Skip to content

Commit

Permalink
增加自定义exo source 演示,实现证书问题
Browse files Browse the repository at this point in the history
  • Loading branch information
CarGuo committed Mar 25, 2019
1 parent 217ee3e commit 098cb88
Show file tree
Hide file tree
Showing 4 changed files with 987 additions and 1 deletion.
23 changes: 22 additions & 1 deletion app/src/main/java/com/example/gsyvideoplayer/GSYApplication.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,23 @@
package com.example.gsyvideoplayer;

import android.net.Uri;

import androidx.multidex.MultiDexApplication;
import tv.danmaku.ijk.media.exo2.Exo2PlayerManager;
import tv.danmaku.ijk.media.exo2.ExoMediaSourceInterceptListener;
import tv.danmaku.ijk.media.exo2.ExoSourceManager;

import com.example.gsyvideoplayer.source.CustomSourceTag;
import com.google.android.exoplayer2.C;
import com.google.android.exoplayer2.source.MediaSource;
import com.google.android.exoplayer2.source.hls.HlsMediaSource;
import com.shuyu.gsyvideoplayer.player.PlayerFactory;
import com.squareup.leakcanary.LeakCanary;

import java.io.File;

import static com.google.android.exoplayer2.util.Util.inferContentType;

/**
* Created by shuyu on 2016/11/11.
*/
Expand Down Expand Up @@ -39,13 +53,20 @@ public void onCreate() {

//IjkPlayerManager.setLogLevel(IjkMediaPlayer.IJK_LOG_SILENT);


/*ExoSourceManager.setExoMediaSourceInterceptListener(new ExoMediaSourceInterceptListener() {
@Override
public MediaSource getMediaSource(String dataSource, boolean preview, boolean cacheEnable, boolean isLooping, File cacheDir) {
Uri contentUri = Uri.parse(dataSource);
int contentType = inferContentType(dataSource);
switch (contentType) {
case C.TYPE_HLS:
return new HlsMediaSource.Factory(CustomSourceTag.getDataSourceFactory(GSYApplication.this.getApplicationContext(), preview)).createMediaSource(contentUri);
}
return null;
}
});*/

}


}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package com.example.gsyvideoplayer.source;

import android.content.Context;

import com.google.android.exoplayer2.upstream.DataSource;
import com.google.android.exoplayer2.upstream.DefaultBandwidthMeter;
import com.google.android.exoplayer2.upstream.DefaultDataSourceFactory;
import com.google.android.exoplayer2.util.Util;

public class CustomSourceTag {

/**
* 获取SourceFactory
*/
static public DataSource.Factory getDataSourceFactory(Context context, boolean preview) {
return new DefaultDataSourceFactory(context, preview ? null : new DefaultBandwidthMeter(),
getHttpDataSourceFactory(context, preview));
}

static public DataSource.Factory getHttpDataSourceFactory(Context context, boolean preview) {
DefaultHttpDataSourceFactory dataSourceFactory = new DefaultHttpDataSourceFactory(Util.getUserAgent(context,
"yout tag"), preview ? null : new DefaultBandwidthMeter());
return dataSourceFactory;
}
}
Loading

0 comments on commit 098cb88

Please sign in to comment.