IjkPlayer的简单使用

//配置权限

//导入依赖

implementation 'com.dou361.ijkplayer:jjdxm-ijkplayer:1.0.6'

//布局文件引入控件



    

//视频地址

String url = "http://video19.ifeng.com/video09/2014/06/16/1989823-102-086-0009.mp4?vkey=xygcPJfLPKXoQ4%2BnSgUyX8ILwVXSs0jHdgm1g21grcsHU7FLO09PWqed%2FpiFDlOB9Jf3wLfcCNOaVLX0GR5f4JB6m6JictMO5USJ8gK09usIOqpNVFhhtcmXwaKgC9u3mcgkDe72niCBhStktrF18Ty64H9gTAFINUaIYLTrK63ETyLKFlbWOsoKhQ3jnDvlhjYFRE%2BCGPYBBJ9iszNoRg%3D%3D";
//播放控件
private PlayerView player;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    player = new PlayerView(MainActivity.this)
            .setTitle("测试视频")//标题
            .setScaleType(PlayStateParams.fitparent)//缩放类型
            .hideMenu(true)//是否隐藏菜单
            .forbidTouch(false)//是否禁止触摸
            .showThumbnail(new OnShowThumbnailListener() {
                @Override
                public void onShowThumbnail(ImageView ivThumbnail) {
                    Glide.with(MainActivity.this)
                            .load("http://p.qpic.cn/videoyun/0/2449_43b6f696980311e59ed467f22794e792_1/640")
                            .into(ivThumbnail);
                }
            })//设置加载缩略图
            .setPlaySource(url)//设置播放地址
            .pausePlay();//当前暂停播放
}
@Override
public void onBackPressed() {
    super.onBackPressed();
    if(player!=null&&player.onBackPressed()){
        return;
    }
}
@Override
protected void onDestroy() {
    super.onDestroy();
    if(player!=null){
        player.onDestroy();
    }
}

@Override
protected void onPause() {
    super.onPause();
    if(player!=null){
        player.onPause();
    }
}

@Override
public void onConfigurationChanged(Configuration newConfig) {
    super.onConfigurationChanged(newConfig);
    if(player!=null){
        player.onConfigurationChanged(newConfig);
    }
}

@Override
protected void onResume() {
    super.onResume();
    if(player!=null){
        player.onResume();
    }
}
}

你可能感兴趣的:(IjkPlayer的简单使用)