本文主要是介绍饺子视频、腾讯视频的简单使用,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
导入依赖包:
// 饺子视频
implementation 'cn.jzvd:jiaozivideoplayer:7.7.0'
//腾讯短视屏
implementation 'com.tencent.liteav:LiteAVSDK_Professional:latest.release'
添加网络权限:
<uses-permission android:name="android.permission.INTERNET" />
首先,饺子视频:
mainActivity.xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"xmlns:app="http://schemas.android.com/apk/res-auto"xmlns:tools="http://schemas.android.com/tools"android:layout_width="match_parent"android:layout_height="match_parent"android:orientation="vertical"tools:context=".MainActivity"><cn.jzvd.JzvdStdandroid:layout_width="match_parent"android:layout_height="500dp"android:id="@+id/jzvd" /></LinearLayout>
MainActivity.java:
package com.example.myapplication;import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.ImageView;
import com.bumptech.glide.Glide;import cn.jzvd.JzvdStd;public class MainActivity extends AppCompatActivity {@Overrideprotected void onDestroy() {super.onDestroy();// 释放所有资源JzvdStd.releaseAllVideos();}@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);// 获取播放器JzvdStd jzvdStd = findViewById(R.id.jzvd);// 设置播放器的视频url,视频标题,有播放按钮的模式jzvdStd.setUp("https://zkw.oss-cn-beijing.aliyuncs.com/video/4329fee0bb96438bb9914a753f8154da.mp4", "啊啊啊", JzvdStd.SCREEN_NORMAL);// 设置视频封面的图片填充方式为填满整个容器jzvdStd.posterImageView.setScaleType(ImageView.ScaleType.FIT_XY);// 设置视频封面图片Glide.with(this).load("https://zkw.oss-cn-beijing.aliyuncs.com/video/4329fee0bb96438bb9914a753f8154da.mp4?x-oss-process=video/snapshot,t_7000,f_jpg").into(jzvdStd.posterImageView);// 开始播放视频jzvdStd.startVideo();}
}
效果图如下:
应用打开后,就开始播放了。不过需要注意的是,当退出应用的时候,要释放视频资源,不然应用退出后,视频依然在播放......还有声音......
然后,腾讯视频:
activity_test.xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"xmlns:app="http://schemas.android.com/apk/res-auto"xmlns:tools="http://schemas.android.com/tools"android:layout_width="match_parent"android:layout_height="match_parent"tools:context=".activity.TestActivity"><com.tencent.rtmp.ui.TXCloudVideoViewandroid:id="@+id/tXCloudVideoView"android:layout_width="match_parent"android:layout_height="match_parent"android:background="@color/black" />
</LinearLayout>
TestActivity.java:
package com.example.supermarket.activity;import androidx.appcompat.app.AppCompatActivity;import android.annotation.SuppressLint;
import android.os.Bundle;
import android.view.View;import com.example.supermarket.R;
import com.tencent.rtmp.TXLiveConstants;
import com.tencent.rtmp.TXVodPlayer;
import com.tencent.rtmp.ui.TXCloudVideoView;public class TestActivity extends AppCompatActivity {private TXVodPlayer vodPlayer;@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_test);vodPlayer = new TXVodPlayer(this);vodPlayer.setRenderRotation(TXLiveConstants.RENDER_ROTATION_PORTRAIT);TXCloudVideoView txCloudVideoView = findViewById(R.id.tXCloudVideoView);vodPlayer.setPlayerView(txCloudVideoView);vodPlayer.setMute(false);// 开启声音vodPlayer.setLoop(true);vodPlayer.startVodPlay("https://zkw.oss-cn-beijing.aliyuncs.com/video/4329fee0bb96438bb9914a753f8154da.mp4");}
}
@Overridepublic void onDestroy() {super.onDestroy();JzvdStd.releaseAllVideos();}@Overridepublic void onResume() {super.onResume();if (JzvdStd!= null) {JzvdStd.startVideo();}if (vodPlayer!=null){vodPlayer.resume();}}@Overridepublic void onPause() {super.onPause();if (JzvdStd != null) {JzvdStd.goOnPlayOnPause();}if (vodPlayer!=null){vodPlayer.pause();}}
这篇关于饺子视频、腾讯视频的简单使用的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!