1. 程式人生 > >Android視訊播放之JiaoZiVideoPlayer框架的使用

Android視訊播放之JiaoZiVideoPlayer框架的使用

1,新增依賴

compile 'cn.jzvd:jiaozivideoplayer:6.2.12'
// glide 4.7
compile 'com.github.bumptech.glide:glide:4.7.1'
annotationProcessor 'com.github.bumptech.glide:compiler:4.7.1'

新增許可權:

<uses-permission android:name="android.permission.INTERNET" />

2,佈局檔案中引入:

<cn.jzvd.JZVideoPlayerStandard
        android:
id="@+id/videoplayer" android:layout_width="match_parent" android:layout_height="200dp"/>

3,設定視訊地址、縮圖地址、標題

JZVideoPlayerStandard jzvdStd = (JZVideoPlayerStandard) findViewById(R.id.videoplayer);

        // 設定這兩句切換時會直接進入橫屏全屏模式
        JZVideoPlayer.FULLSCREEN_ORIENTATION = ActivityInfo.
SCREEN_ORIENTATION_LANDSCAPE; //橫向 JZVideoPlayer.NORMAL_ORIENTATION = ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT; //縱向 // 設定播放器播放地址,標題 jzvdStd.setUp("http://jzvd.nathen.cn/342a5f7ef6124a4a8faf00e738b8bee4/cf6d9db0bd4d41f59d09ea0a81e918fd-5287d2089db37e62345123a1be272f8b.mp4" ,
JZVideoPlayerStandard.SCREEN_WINDOW_NORMAL, "好孩子" ); //設定播放器封面 Glide.with(this) .load("http://jzvd-pic.nathen.cn/jzvd-pic/1bb2ebbe-140d-4e2e-abd2-9e7e564f71ac.png") .into(jzvdStd.thumbImageView);

4,在Activity中:

@Override
    public void onBackPressed() {
        if (JZVideoPlayerStandard.backPress()) {
            return;
        }
        super.onBackPressed();
    }
    @Override
    protected void onPause() {
        super.onPause();
        JZVideoPlayerStandard.releaseAllVideos();
    }

5,在AndroidManifest.xml中:

<activity
    android:name=".MainActivity"
    android:configChanges="orientation|screenSize|keyboardHidden"
    android:screenOrientation="portrait" />