diff --git a/README.md b/README.md index c443cc0f2667e6c320ca3ae35985a14873720d69..c5161092f2ebebf4874ee5994f347e17378a3df3 100644 --- a/README.md +++ b/README.md @@ -127,20 +127,43 @@ compile 'com.shuyu:gsyVideoPlayer-ex_so:5.0.2' ## 五、近期版本 +### 6.0.0-beta (2018-xx-xx) +* 升级 ExoPlayer 到 2.8.4。 +* 修复代理缓存时头部信息不存在问题。 +* 调整代码结构,移除 GSYVideoType 中的内核切换,直接通过 PlayerFactory 装载。 +* 调整代码结构,ExoPlayer可单独依赖,通过 PlayerFactory 装载,更方便自定义PlayerManager。 + +``` +//PlayerFactory.setPlayManager(new Exo2PlayerManager());//EXO模式 +//PlayerFactory.setPlayManager(new SystemPlayerManager());//系统模式 +//PlayerFactory.setPlayManager(new IjkPlayerManager());//ijk模式 +``` -### 5.0.2(2018-08-01) -* Fix跟随屏幕旋转存在的问题。 -* 修改对于Audio冲突时候的处理,子类可以复写方法自行另外处理. -* fix #1300 -* 默认暂停图片修改为false - +* 调整代码结构,CacheFactory 更方便自定义,默认 ProxyCacheManager。 -### 5.0.1(2018-07-01) -* Update ListGSYVideoPlayer -* ijkPlayer的ex_so增加avi支持 -* update ExoPlayer to 2.8.2 -* ExoPlayer模式的问题修复 +``` +//CacheFactory.setCacheManager(new ExoPlayerCacheManager());//exo缓存模式,支持m3u8,只支持exo +//CacheFactory.setCacheManager(new ProxyCacheManager());//代理缓存模式,支持所有模式,不支持m3u8等 +``` +* 增加 ExoMediaSourceInterceptListener,方便 Exo 模式下使用自定义的 MediaSource。 + +``` +ExoSourceManager.setExoMediaSourceInterceptListener(new ExoMediaSourceInterceptListener() { + /** + * @param dataSource 链接 + * @param preview 是否带上header,默认有header自动设置为true + * @param cacheEnable 是否需要缓存 + * @param isLooping 是否循环 + * @param cacheDir 自定义缓存目录 + * @return 返回不为空时,使用返回的自定义mediaSource + */ + @Override + public MediaSource getMediaSource(String dataSource, boolean preview, boolean cacheEnable, boolean isLooping, File cacheDir) { + return null; + } +}); +``` ### 更多版本请查阅:[版本更新说明](https://github.com/CarGuo/GSYVideoPlayer/blob/master/doc/UPDATE_VERSION.md) diff --git a/app/src/main/java/com/example/gsyvideoplayer/GSYApplication.java b/app/src/main/java/com/example/gsyvideoplayer/GSYApplication.java index 3f5b39963e6c5be8451e82e4ea18a2fce5cf6cbe..1bbcc1bf99178b9532dfc2e675f276fe47d60f60 100644 --- a/app/src/main/java/com/example/gsyvideoplayer/GSYApplication.java +++ b/app/src/main/java/com/example/gsyvideoplayer/GSYApplication.java @@ -2,6 +2,7 @@ package com.example.gsyvideoplayer; import android.support.multidex.MultiDexApplication; +import com.google.android.exoplayer2.source.MediaSource; import com.shuyu.gsyvideoplayer.GSYVideoManager; import com.shuyu.gsyvideoplayer.cache.CacheFactory; import com.shuyu.gsyvideoplayer.cache.ProxyCacheManager; @@ -11,10 +12,14 @@ import com.shuyu.gsyvideoplayer.player.SystemPlayerManager; import com.shuyu.gsyvideoplayer.utils.GSYVideoType; import tv.danmaku.ijk.media.exo2.Exo2PlayerManager; +import tv.danmaku.ijk.media.exo2.ExoMediaSourceInterceptListener; import tv.danmaku.ijk.media.exo2.ExoPlayerCacheManager; +import tv.danmaku.ijk.media.exo2.ExoSourceManager; import com.squareup.leakcanary.LeakCanary; +import java.io.File; + /** * Created by shuyu on 2016/11/11. */ @@ -50,5 +55,13 @@ public class GSYApplication extends MultiDexApplication { //IjkPlayerManager.setLogLevel(IjkMediaPlayer.IJK_LOG_SILENT); + + /*ExoSourceManager.setExoMediaSourceInterceptListener(new ExoMediaSourceInterceptListener() { + @Override + public MediaSource getMediaSource(String dataSource, boolean preview, boolean cacheEnable, boolean isLooping, File cacheDir) { + return null; + } + });*/ + } } diff --git a/gsyVideoPlayer-exo_player2/src/main/java/tv/danmaku/ijk/media/exo2/ExoMediaSourceInterceptListener.java b/gsyVideoPlayer-exo_player2/src/main/java/tv/danmaku/ijk/media/exo2/ExoMediaSourceInterceptListener.java new file mode 100644 index 0000000000000000000000000000000000000000..b9c9e366e81107c130c6ac7afe042f3b2560d27c --- /dev/null +++ b/gsyVideoPlayer-exo_player2/src/main/java/tv/danmaku/ijk/media/exo2/ExoMediaSourceInterceptListener.java @@ -0,0 +1,22 @@ +package tv.danmaku.ijk.media.exo2; + +import com.google.android.exoplayer2.source.MediaSource; + +import java.io.File; + +/** + * 设置 ExoPlayer 的 MediaSource 创建拦截 + * Created by guoshuyu + * Date: 2018-08-22 + */ +public interface ExoMediaSourceInterceptListener { + /** + * @param dataSource 链接 + * @param preview 是否带上header,默认有header自动设置为true + * @param cacheEnable 是否需要缓存 + * @param isLooping 是否循环 + * @param cacheDir 自定义缓存目录 + * @return 返回不为空时,使用返回的自定义mediaSource + */ + MediaSource getMediaSource(String dataSource, boolean preview, boolean cacheEnable, boolean isLooping, File cacheDir); +} diff --git a/gsyVideoPlayer-exo_player2/src/main/java/tv/danmaku/ijk/media/exo2/ExoSourceManager.java b/gsyVideoPlayer-exo_player2/src/main/java/tv/danmaku/ijk/media/exo2/ExoSourceManager.java index c015b86c384c10924a6edd774bcce81e556b7b26..434d2588f5fe4de03c4408c5a31724c3817c924b 100644 --- a/gsyVideoPlayer-exo_player2/src/main/java/tv/danmaku/ijk/media/exo2/ExoSourceManager.java +++ b/gsyVideoPlayer-exo_player2/src/main/java/tv/danmaku/ijk/media/exo2/ExoSourceManager.java @@ -45,13 +45,16 @@ public class ExoSourceManager { public static final int TYPE_RTMP = 4; - protected static Cache mCache; - protected Context mAppContext; + private static Cache mCache; - protected Map mMapHeadData; + private Context mAppContext; - protected String mDataSource; + private Map mMapHeadData; + + private String mDataSource; + + private static ExoMediaSourceInterceptListener sExoMediaSourceInterceptListener; private boolean isCached = false; @@ -64,11 +67,24 @@ public class ExoSourceManager { mMapHeadData = mapHeadData; } + /** + * @param dataSource 链接 + * @param preview 是否带上header,默认有header自动设置为true + * @param cacheEnable 是否需要缓存 + * @param isLooping 是否循环 + * @param cacheDir 自定义缓存目录 + */ public MediaSource getMediaSource(String dataSource, boolean preview, boolean cacheEnable, boolean isLooping, File cacheDir) { + MediaSource mediaSource = null; + if (sExoMediaSourceInterceptListener != null) { + mediaSource = sExoMediaSourceInterceptListener.getMediaSource(dataSource, preview, cacheEnable, isLooping, cacheDir); + } + if (mediaSource != null) { + return mediaSource; + } mDataSource = dataSource; Uri contentUri = Uri.parse(dataSource); int contentType = inferContentType(dataSource); - MediaSource mediaSource; switch (contentType) { case C.TYPE_SS: mediaSource = new SsMediaSource.Factory( @@ -103,6 +119,23 @@ public class ExoSourceManager { return mediaSource; } + + /** + * 设置ExoPlayer 的 MediaSource 创建拦截 + */ + public static void setExoMediaSourceInterceptListener(ExoMediaSourceInterceptListener exoMediaSourceInterceptListener) { + sExoMediaSourceInterceptListener = exoMediaSourceInterceptListener; + } + + public static void resetExoMediaSourceInterceptListener() { + sExoMediaSourceInterceptListener = null; + } + + public static ExoMediaSourceInterceptListener getExoMediaSourceInterceptListener() { + return sExoMediaSourceInterceptListener; + } + + @C.ContentType public static int inferContentType(String fileName) { fileName = Util.toLowerInvariant(fileName); @@ -184,7 +217,6 @@ public class ExoSourceManager { return isCached; } - /** * 获取SourceFactory,是否带Cache */