Skip to content

常见问题

dueeeke edited this page Nov 27, 2019 · 13 revisions

VideoView定制和MediaPlayer定制

参考demo中ijkVideoView和ExoVideoView实现

控制器定制

继承GestureVideoController,需完全自定义ui,需要手势操作的情形; 继承StandardVideoController,部分自定义的情形,重写相关方法; 使用ControlComponent,参考demo和dkplayer-ui这个库的实现方式。

添加自定义渲染层

VideoView内部有一个mPlayerContainer的FrameLayout,将你的渲染层添加到里面即可,具体可参考弹幕demo

监听播放状态

通过OnVideoViewStateChangeListener接口, 示例如下:

VideoView.addOnVideoViewStateChangeListener(new OnVideoViewStateChangeListener() {
    @Override
    public void onPlayerStateChanged(int playerState) {
        switch (playerState) {
            case VideoView.PLAYER_NORMAL://小屏
                break;
            case VideoView.PLAYER_FULL_SCREEN://全屏
                break;
        }
    }
    @Override
    public void onPlayStateChanged(int playState) {
        switch (playState) {
            case VideoView.STATE_IDLE:
                break;
            case VideoView.STATE_PREPARING:
                break;
            case VideoView.STATE_PREPARED:
                break;
            case VideoView.STATE_PLAYING:
                break;
            case VideoView.STATE_PAUSED:
                break;
            case VideoView.STATE_BUFFERING:
                break;
            case VideoView.STATE_BUFFERED:
                break;
            case VideoView.STATE_PLAYBACK_COMPLETED:
                break;
            case VideoView.STATE_ERROR:
                break;
        }
    }
});

本地视频播放

前提:拥有存储权限,示例如下:

String path = Environment.getExternalStorageDirectory().getAbsolutePath();
String url = "file://" + path + File.separator + "test.mp4";
videoView.setUrl(url);

给IjkPlayer设置option

参考demo中IjkVideoView的实现

IjkPlayer自编译so

https://www.jianshu.com/p/e1596d201ea4

IjkPlayer常见问题汇总

https://www.jianshu.com/p/496257563f69