-
Notifications
You must be signed in to change notification settings - Fork 1k
常见问题
dueeeke edited this page Mar 19, 2019
·
13 revisions
方法一:修改源码
方法二:内部大部分方法和变量都是public和protected,只需继承它重写相关方法逻辑(推荐)
方法一:修改源码
方法二:继承BaseVideoController,需完全自定义ui的情形,且不需要手势操作; 继承GestureVideoController,需完全自定义ui的情形,需要手势操作; 继承StandardVideoController,部分自定义的情形,重写相关方法
IjkVideoView内部有一个mPlayerContainer的FrameLayout,将你的渲染层添加到里面即可,具体可参考弹幕demo
通过OnVideoViewStateChangeListener接口, 示例如下:
ijkVideoView.addOnVideoViewStateChangeListener(new OnVideoViewStateChangeListener() {
@Override
public void onPlayerStateChanged(int playerState) {
switch (playerState) {
case IjkVideoView.PLAYER_NORMAL://小屏
break;
case IjkVideoView.PLAYER_FULL_SCREEN://全屏
break;
}
}
@Override
public void onPlayStateChanged(int playState) {
switch (playState) {
case IjkVideoView.STATE_IDLE:
break;
case IjkVideoView.STATE_PREPARING:
break;
case IjkVideoView.STATE_PREPARED:
break;
case IjkVideoView.STATE_PLAYING:
break;
case IjkVideoView.STATE_PAUSED:
break;
case IjkVideoView.STATE_BUFFERING:
break;
case IjkVideoView.STATE_BUFFERED:
break;
case IjkVideoView.STATE_PLAYBACK_COMPLETED:
break;
case IjkVideoView.STATE_ERROR:
break;
}
}
});
前提:拥有存储权限,示例如下:
String path = Environment.getExternalStorageDirectory().getAbsolutePath();
String url = "file://" + path + File.separator + "test.mp4";
ijkVideoView.setUrl(url);
使用setCustomMediaPlayer方法,示例如下
ijkVideoView.setCustomMediaPlayer(new IjkPlayer(this) {
@Override
public void setOptions() {
super.setOptions();
//支持concat
mMediaPlayer.setOption(IjkMediaPlayer.OPT_CATEGORY_FORMAT, "safe", 0);
mMediaPlayer.setOption(IjkMediaPlayer.OPT_CATEGORY_FORMAT, "protocol_whitelist",
"rtmp,concat,ffconcat,file,subfile,http,https,tls,rtp,tcp,udp,crypto,rtsp");
//使用tcp方式拉取rtsp流,默认是通过udp方式
mMediaPlayer.setOption(IjkMediaPlayer.OPT_CATEGORY_FORMAT, "rtsp_transport", "tcp");
}
});