Android简单的集成腾讯视频播放器

在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);
        }
    }

以上就简单的实现了视频播放

  • 1
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
好的,以下是基于腾讯云实时音视频SDK的Demo,包含UI界面: 1. 首先,你需要在腾讯云官网注册账号,开通实时音视频服务,并创建一个应用,获取到SDKAppID和密钥信息。 2. 在Android Studio中创建一个新的项目,并在app/build.gradle文件中添加依赖: ``` dependencies { implementation 'com.tencent.liteav:liteav:latest_version' } ``` 其中,latest_version为实时音视频SDK的最新版本号。 3. 在MainActivity中添加以下代码,初始化腾讯云实时音视频SDK: ``` public class MainActivity extends AppCompatActivity { private static final String TAG = "MainActivity"; private TXLivePlayer mPlayer; private TXLivePusher mPusher; private TXCloudProxy mCloudProxy; private String mSdkAppId = "YOUR_SDK_APP_ID"; private String mUserId = "YOUR_USER_ID"; private String mUserSig = "YOUR_USER_SIG"; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); // 初始化SDK TXLiveBase.getInstance().setLicence(this, "YOUR_LICENCE_URL", "YOUR_LICENCE_KEY"); TXLiveBase.getInstance().setConsoleEnabled(true); mPlayer = new TXLivePlayer(this); mPusher = new TXLivePusher(this); mCloudProxy = new TXCloudProxy(this, mSdkAppId, mUserId, mUserSig); // 设置播放器和推流器的配置 TXLivePlayConfig playConfig = new TXLivePlayConfig(); playConfig.setAutoAdjustCacheTime(true); playConfig.setMaxAutoAdjustCacheTime(5); mPlayer.setConfig(playConfig); TXLivePushConfig pushConfig = new TXLivePushConfig(); pushConfig.setVideoFPS(15); pushConfig.setVideoBitrate(800); pushConfig.setVideoResolution(TXLiveConstants.VIDEO_RESOLUTION_TYPE_360_640); pushConfig.setAudioSampleRate(TXLiveConstants.AUDIO_SAMPLE_RATE_48000); mPusher.setConfig(pushConfig); // 开始预览 TXCloudView cloudView = findViewById(R.id.cloud_view); mPusher.startCameraPreview(cloudView); } @Override protected void onDestroy() { super.onDestroy(); // 释放资源 mPlayer.stopPlay(true); mPlayer = null; mPusher.stopCameraPreview(true); mPusher.stopPusher(); mPusher = null; mCloudProxy.logout(); mCloudProxy = null; } } ``` 在上面的代码中,我们使用TXLivePlayer和TXLivePusher来进行播放和推流操作,使用TXCloudProxy来进行用户登录和注销操作。你需要将YOUR_SDK_APP_ID、YOUR_USER_ID和YOUR_USER_SIG替换为你自己的SDKAppID和密钥信息。你还需要在腾讯云官网获取到有效的licence_url和licence_key,并将其替换到上面的代码中。 4. 在布局文件中添加一个TXCloudView,用于预览摄像头的画面: ``` <com.tencent.rtmp.TXCloudView android:id="@+id/cloud_view" android:layout_width="match_parent" android:layout_height="match_parent" /> ``` 5. 运行应用,你将看到摄像头的预览画面。你可以使用TXLivePlayer来播放实时音视频流,使用TXLivePusher来进行推流操作。 以上就是一个基于腾讯云实时音视频SDK的Demo,包含UI界面的实现方式。如果你需要更多的功能,可以参考腾讯云官方文档或在官方论坛中寻求帮助。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

时代新人

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值