jiecaovideoplayer视频播放开源框架的使用步骤

1、使用

1.1 在project的build.gradle添加如下代码和引入lib库

allprojects {
    repositories {
        maven { url "https://jitpack.io" }
    }
}
implementation fm.jiecao:jiecaovideoplayer:5.8.1

1.2 运行所需权限

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

1.3 布局文件

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
              android:layout_width="match_parent"
              android:layout_height="match_parent"
              android:orientation="vertical"
              android:gravity="center_vertical">

    <fm.jiecao.jcvideoplayer_lib.JCVideoPlayerStandard
        android:id="@+id/videoplayer"
        android:layout_width="match_parent"
        android:layout_height="200dp"/>
</LinearLayout>

1.4 配置清单文件

<activity android:name=".JiaoZiVideoPlayerActivity"
                  android:configChanges="screenSize|orientation|keyboard">
            <intent-filter>
                <action android:name="android.intent.action.MAIN"/>
                <category android:name="android.intent.category.LAUNCHER"/>
            </intent-filter>
            <intent-filter>
                <action android:name="android.intent.action.VIEW"/>
                <category android:name="android.intent.category.DEFAULT"/>
                <category android:name="android.intent.category.BROWSABLE"/>
                <data android:scheme="rtsp"/>
            </intent-filter>
            <intent-filter tools:ignore="AppLinkUrlError">
                <action android:name="android.intent.action.VIEW"/>
                <category android:name="android.intent.category.DEFAULT"/>

                <data android:mimeType="video/*"/>
                <data android:mimeType="application/sdp"/>
            </intent-filter>
            <intent-filter>
                <action android:name="android.intent.action.VIEW"/>

                <category android:name="android.intent.category.DEFAULT"/>
                <category android:name="android.intent.category.BROWSABLE"/>

                <data android:scheme="http"/>
                <data android:mimeType="video/mp4"/>
                <data android:mimeType="video/3gp"/>
                <data android:mimeType="video/3gpp"/>
                <data android:mimeType="video/3gpp2"/>
            </intent-filter>
        </activity>

1.5 activity 中调运

class JiaoZiVideoPlayerActivity: BaseActivity() {
    override fun getLayoutId(): Int {
        return R.layout.activity_video_player_jiecao
    }

    override fun initData() {
        val data = intent.data;
        if (data == null){
            //从应用内响应http://hc.yinyuetai.com/uploads/videos/common/0FBB016ADECDDFF86FF7D6E8CE792DCC.mp4?sc=c19481d47147e188&br=785&rd=Android
            //获取传递的数据
            var videoUrl = intent.getStringExtra("videoUrl")
            var videoTitle = intent.getStringExtra("videoTitle")
            if(StringHelper.isEmptyString(videoUrl)){
                videoUrl = "http://hc.yinyuetai.com/uploads/videos/common/0FBB016ADECDDFF86FF7D6E8CE792DCC.mp4?sc=c19481d47147e188&br=785&rd=Android"
            }

            videoplayer.setUp(videoUrl, JCVideoPlayerStandard.SCREEN_LAYOUT_NORMAL,videoTitle)
            videoplayer.thumbImageView.setThumbInCustomProject("http://p.qpic.cn/videoyun/0/2449_43b6f696980311e59ed467f22794e792_1/640");
        }else{
            if (data.toString().startsWith("http:")){
                //外部网络视频
                videoplayer.setUp(data.toString(),
                    JCVideoPlayerStandard.SCREEN_LAYOUT_NORMAL,data.toString())
            }else{
                //从应用外响应
                videoplayer.setUp(data.path,
                    JCVideoPlayerStandard.SCREEN_LAYOUT_NORMAL,data.toString())
            }
        }
    }
    override fun onBackPressed() {
        if (JCVideoPlayer.backPress()) {
            return
        }
        super.onBackPressed()
    }

    override fun onPause() {
        super.onPause()
        JCVideoPlayer.releaseAllVideos()
    }
}

版权声明:本文为qq_30192407原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。