饺子视频、腾讯视频的简单使用

导入依赖包:

// 饺子视频
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.JzvdStd
        android: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 {

    @Override
    protected void onDestroy() {
        super.onDestroy();
        // 释放所有资源
        JzvdStd.releaseAllVideos();
    }

    @Override
    protected 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.TXCloudVideoView
        android: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;

    @Override
    protected 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");
    }
}

@Override
    public void onDestroy() {
        super.onDestroy();
        JzvdStd.releaseAllVideos();
    }

    @Override
    public void onResume() {
        super.onResume();
        if (JzvdStd!= null) {
            JzvdStd.startVideo();
        }
        if (vodPlayer!=null){
            vodPlayer.resume();
        }
    }

    @Override
    public void onPause() {
        super.onPause();
        if (JzvdStd != null) {
            JzvdStd.goOnPlayOnPause();
        }
        if (vodPlayer!=null){
            vodPlayer.pause();
        }
    }

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值