Skip to content

Commit

Permalink
Merge pull request CarGuo#133 from PureDark/master
Browse files Browse the repository at this point in the history
* 支持设置自定义IjkLibLoader以支持动态加载so包
  • Loading branch information
CarGuo authored Apr 1, 2017
2 parents a556f1f + ddcf051 commit 0806239
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import tv.danmaku.ijk.media.exo.IjkExoMediaPlayer;
import tv.danmaku.ijk.media.player.AbstractMediaPlayer;
import tv.danmaku.ijk.media.player.IMediaPlayer;
import tv.danmaku.ijk.media.player.IjkLibLoader;
import tv.danmaku.ijk.media.player.IjkMediaPlayer;

/**
Expand Down Expand Up @@ -63,6 +64,9 @@ public class GSYVideoManager implements IMediaPlayer.OnPreparedListener, IMediaP
private WeakReference<GSYMediaPlayerListener> listener;
private WeakReference<GSYMediaPlayerListener> lastListener;

// 单例模式实在不好给instance()加参数,还是直接设为静态变量吧
private static IjkLibLoader ijkLibLoader; //自定义so包加载类

private List<VideoOptionModel> optionModelList;//配置ijk option

private HttpProxyCacheServer proxy; //视频代理
Expand Down Expand Up @@ -94,11 +98,18 @@ public class GSYVideoManager implements IMediaPlayer.OnPreparedListener, IMediaP

public static synchronized GSYVideoManager instance() {
if (videoManager == null) {
videoManager = new GSYVideoManager();
videoManager = new GSYVideoManager(ijkLibLoader);
}
return videoManager;
}

/**
* 设置自定义so包加载类
*/
public static void setIjkLibLoader(IjkLibLoader libLoader) {
ijkLibLoader = libLoader;
}

/**
* 获取缓存代理服务
*/
Expand Down Expand Up @@ -214,7 +225,12 @@ public void setLastListener(GSYMediaPlayerListener lastListener) {
}

public GSYVideoManager() {
mediaPlayer = new IjkMediaPlayer();
this(null);
}

public GSYVideoManager(IjkLibLoader libLoader) {
mediaPlayer = (libLoader == null) ? new IjkMediaPlayer() : new IjkMediaPlayer(libLoader);
ijkLibLoader = libLoader;
mMediaHandlerThread = new HandlerThread(TAG);
mMediaHandlerThread.start();
mMediaHandler = new MediaHandler((mMediaHandlerThread.getLooper()));
Expand Down Expand Up @@ -280,7 +296,7 @@ private void initVideo(Message msg) {
}

private void initIJKPlayer(Message msg) {
mediaPlayer = new IjkMediaPlayer();
mediaPlayer = (ijkLibLoader == null) ? new IjkMediaPlayer() : new IjkMediaPlayer(ijkLibLoader);
mediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
try {
if (GSYVideoType.isMediaCodec()) {
Expand Down Expand Up @@ -382,7 +398,7 @@ public void prepare(final String url, final Map<String, String> mapHeadData, boo
GSYModel fb = new GSYModel(url, mapHeadData, loop, speed);
msg.obj = fb;
mMediaHandler.sendMessage(msg);
if(needTimeOutOther) {
if (needTimeOutOther) {
startTimeOutBuffer();
}
}
Expand Down Expand Up @@ -627,17 +643,17 @@ public boolean isNeedTimeOutOther() {

/**
* 是否需要在buffer缓冲时,增加外部超时判断
*
* <p>
* 超时后会走onError接口,播放器通过onPlayError回调出
*
* <p>
* 错误码为 : BUFFER_TIME_OUT_ERROR = -192
*
* <p>
* 由于onError之后执行GSYVideoPlayer的OnError,如果不想触发错误,
* 可以重载onError,在super之前拦截处理。
*
* <p>
* public void onError(int what, int extra){
* do you want before super and return;
* super.onError(what, extra)
* do you want before super and return;
* super.onError(what, extra)
* }
*
* @param timeOut 超时时间,毫秒 默认8000
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import java.util.TimerTask;

import tv.danmaku.ijk.media.player.IMediaPlayer;
import tv.danmaku.ijk.media.player.IjkLibLoader;
import tv.danmaku.ijk.media.player.IjkMediaPlayer;

import static com.shuyu.gsyvideoplayer.utils.CommonUtil.getTextSpeed;
Expand Down Expand Up @@ -144,6 +145,15 @@ public GSYVideoPlayer(Context context, Boolean fullFlag) {
init(context);
}

/**
* 模仿IjkMediaPlayer的构造函数,提供自定义IjkLibLoader的入口
*/
public GSYVideoPlayer(Context context, IjkLibLoader ijkLibLoader) {
super(context);
GSYVideoManager.setIjkLibLoader(ijkLibLoader);
init(context);
}

public GSYVideoPlayer(Context context) {
super(context);
init(context);
Expand Down Expand Up @@ -186,6 +196,15 @@ protected void init(Context context) {
mSeekEndOffset = CommonUtil.dip2px(getContext(), 50);
}


/**
* 设置自定义so包加载类,必须在setUp之前调用
* 不然setUp时会第一次实例化GSYVideoManager
*/
public void setIjkLibLoader(IjkLibLoader libLoader){
GSYVideoManager.setIjkLibLoader(libLoader);
}

/**
* 设置播放URL
*
Expand Down

0 comments on commit 0806239

Please sign in to comment.