在build.gradle里加入
api 'com.tencent.tbs.tbssdk:sdk:43939'//腾讯视频播放
AndroidManifest.xml里加入
<activity
android:name="com.tencent.smtt.sdk.VideoActivity"
android:alwaysRetainTaskState="true"
android:configChanges="orientation|screenSize|keyboardHidden"
android:exported="false"
android:launchMode="singleTask">
<intent-filter>
<action android:name="com.tencent.smtt.tbs.video.PLAY" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
加入权限
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
使用
/**
* 直接调用播放视频
* @param videoUrl 视频地址
*/
private void startPlay(String videoUrl){
//判断当前是否可用
if(TbsVideo.canUseTbsPlayer(getApplicationContext())){
Bundle bundle = new Bundle();
bundle.putInt("screenMode",102);//102 来实现默认全屏+控制栏等UI
bundle.putString("title","测试");
bundle.putBoolean("standardFullScreen",true);// true表示标准全屏,false表示X5全屏;不设置默认false,
bundle.putBoolean("supportLiteWnd",true);// false:关闭小窗;true:开启小窗;不设置默认true,
bundle.putInt("DefaultVideoScreen",1);// 1:以页面内开始播放,2:以全屏开始播放;不设置默认:1
//播放视频
TbsVideo.openVideo(getApplicationContext(), videoUrl,bundle);
// TbsVideo.openVideo(getApplicationContext(), videoUrl);
}
}
以上就简单的实现了视频播放