The Tencent Cloud RT-Cube Player for Android is an open-source player component of Tencent Cloud. It integrates quality monitoring, video encryption, Top Speed Codec, definition selection, and small window playback and is suitable for all VOD and live playback scenarios. It encapsulates complete features and provides upper-layer UIs to help you quickly create a playback program comparable to mainstream video applications.
If the Player component cannot meet your custom requirements and you have development experience, you can integrate the RT-Cube Player SDK as instructed in Integration Guide to customize the player UI and playback features.
GitHub page: LiteAVSDK/Player_Android
You can download the Player for Android by downloading the Player component ZIP package or running the Git clone command.
Go to the Player GitHub page and click Code > Download ZIP.
This step describes how to integrate the player. You can integrate the project by using Gradle for automatic loading, manually downloading the AAR and importing it into your current project, or importing the JAR and SO libraries.
Download the SDK + demo package for Android here.
Copy the Demo/superplayerkit
module to your project and then configure as follows:
superplayerkit
into setting.gradle
in your project directory.include ':superplayerkit'
build.gradle
file of the superplayerkit
project and modify the constant values of compileSdkVersion
, buildToolsVersion
, minSdkVersion
, targetSdkVersion
, and rootProject.ext.liteavSdk
.compileSdkVersion 26
buildToolsVersion "26.0.2"
defaultConfig {
targetSdkVersion 23
minSdkVersion 19
}
dependencies {
// To integrate an older version, change `latest.release` to the corresponding version number, such as `8.5.290009`
implementation 'com.tencent.liteav:LiteAVSDK_Player:latest.release'
}
common
module into your project as instructed above and configure it.Configure the mavenCentral
repository in Gradle, and LiteAVSDK will be automatically downloaded and updated. Open app/build.gradle
and configure as follows:
LiteAVSDK_Player
dependencies to dependencies
.dependencies {
implementation 'com.tencent.liteav:LiteAVSDK_Player:latest.release'
implementation project(':superplayerkit')
// Third-party library for integration of the on-screen commenting feature of the Player component
implementation 'com.github.ctiao:DanmakuFlameMaster:0.5.3'
}
dependencies {
// Integrate the LiteAVSDK_Player SDK v8.5.10033
implementation 'com.tencent.liteav:LiteAVSDK_Player:8.5.10033'
}
defaultConfig
of app/build.gradle
, specify the CPU architecture to be used by the application (currently, LiteAVSDK supports armeabi, armeabi-v7a, and arm64-v8a, which you can configure as needed).ndk {
abiFilters "armeabi", "armeabi-v7a", "arm64-v8a"
}
setDownloadPath
and startDownloadUrl
functions of the TXVodDownloadManager
class in the SDK v9.4 or earlier, and the getPlayPath
path called back by TXVodDownloadManager
is stored in the application for subsequent playback, you will need libijkhlscache-master.so
to play back the file at the getPlayPath
path; otherwise, you won't need it. You can add the following to app/build.gradle
:packagingOptions{
exclude "lib/armeabi/libijkhlscache-master.so"
exclude "lib/armeabi-v7a/libijkhlscache-master.so"
exclude "lib/arm64-v8a/libijkhlscache-master.so"
}
mavenCentral
repository to the build.gradle
in your project directory.repositories {
mavenCentral()
}
Click Sync Now to sync the SDK. If mavenCentral
can be connected to, the SDK will be automatically downloaded and integrated into the project very soon.
Configure permissions for your application in AndroidManifest.xml
. LiteAVSDK needs the following permissions:
<!--network permission-->
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<!--VOD player floating window permission -->
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW" />
<!--storage-->
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
In the proguard-rules.pro
file, add the classes related to the TRTC SDK to the "do not obfuscate" list:
-keep class com.tencent.** { *;}
At this point, you have completed configuring permissions for the RT-Cube Player application for Android.
This step describes how to create a player and use it for video playback.
Player creation
The main class of the player is SuperPlayerView
, and videos can be played back after it is created. FileId
or URL can be integrated for playback. Create SuperPlayerView
in the layout file:
<!-- Player component -->
<com.tencent.liteav.demo.superplayer.SuperPlayerView
android:id="@+id/superVodPlayerView"
android:layout_width="match_parent"
android:layout_height="200dp" />
License configuration
If you have the required license, get the license URL and key in the RT-Cube console.
If you don't have the required license, contact us to get it.
After obtaining the license information, before calling relevant APIs of the SDK, initialize the license through the following API. We recommend you set the following in the Application
class:
public class MApplication extends Application {
@Override
public void onCreate() {
super.onCreate();
String licenceURL = ""; // The license URL obtained
String licenceKey = ""; // The license key obtained
TXLiveBase.getInstance().setLicence(this, licenceURL, licenceKey);
TXLiveBase.setListener(new TXLiveBaseListener() {
@Override
public void onLicenceLoaded(int result, String reason) {
Log.i(TAG, "onLicenceLoaded: result:" + result + ", reason:" + reason);
}
});
}
}
FileID
or URL.A URL can be the playback address of a VOD file or the pull address of a live stream. A video file can be played back simply by passing in its URL.
SuperPlayerModel model = new SuperPlayerModel();
model.appId = 1400329073; // Configure `AppId`
model.url = "http://your_video_url.mp4"; // Configure a URL for your video for playback
mSuperPlayerView.playWithModelNeedLicence(model);
resetPlayer
to reset the player and free up memory.mSuperPlayerView.resetPlayer();
At this point, you have learned how to create a player, use it to play videos, and stop playback.
This section describes several common player features. For more features, see Demo. For features supported by the Player component, see Feature Description.
The Player component supports full screen playback. In full screen mode, users can lock the screen, control volume and brightness with gestures, send on-screen comments, take screenshots, and switch the video definition. You can try out this feature in TCToolkit App > Player > Player Component, and you can enter the full screen playback mode by clicking the full screen icon in the bottom-right corner.
You can call the API below to enter full screen from the windowed playback mode:
mControllerCallback.onSwitchPlayMode(SuperPlayerDef.PlayerMode.FULLSCREEN);
Tap Back to return to the window playback mode.
// API triggered after tapping
mControllerCallback.onBackPressed(SuperPlayerDef.PlayerMode.FULLSCREEN);
onSwitchPlayMode(SuperPlayerDef.PlayerMode.WINDOW);
The Player component supports playback in a small floating window, which allows users to switch to another application without interrupting the video playback. You can try out this feature in TCToolkit App > Player > Player Component by clicking Back in the top-left corner.
Floating window playback relies on the following permission in AndroidManifest
:
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW" />
// The API triggered by switching to the floating window
mSuperPlayerView.switchPlayMode(SuperPlayerDef.PlayerMode.FLOAT);
// The API triggered by tapping the floating window to return to the main window
mControllerCallback.onSwitchPlayMode(SuperPlayerDef.PlayerMode.WINDOW);
The Player component supports customizing a video thumbnail, which is displayed before the callback is received for playing back the first video frame. You can try out this feature in TCToolkit App > Player > Player Component > Thumbnail Customization Demo.
PLAY_ACTION_AUTO_PLAY
, the video will be played back automatically, and the thumbnail will be displayed before the first video frame is loaded.PLAY_ACTION_MANUAL_PLAY
, the video will be played back only after the user clicks Play. The thumbnail will be displayed until the first video frame is loaded.You can set the thumbnail by specifying the URL of a local or online file. For detailed directions, see the code below. If you play by VOD file ID, you can also set the thumbnail in the VOD console.
SuperPlayerModel model = new SuperPlayerModel();
model.appId = "Your `appid`";
model.videoId = new SuperPlayerVideoId();
model.videoId.fileId = "Your `fileId`";
// Playback mode, which can be set to automatic (`PLAY_ACTION_AUTO_PLAY`) or manual (`PLAY_ACTION_MANUAL_PLAY`)
model.playAction = PLAY_ACTION_MANUAL_PLAY;
// Specify the URL of an online file to use as the thumbnail. If `coverPictureUrl` is not set, the thumbnail configured in the VOD console will be used.
model.coverPictureUrl = "http://1500005830.vod2.myqcloud.com/6c9a5118vodcq1500005830/cc1e28208602268011087336518/MXUW1a5I9TsA.png"
mSuperPlayerView.playWithModelNeedLicence(model);
The Player component supports looping a video playlist:
This feature can be tried out in TCToolkit App > Player > Player Component > Video List Loop Demo.
// Step 1. Create a loop list<SuperPlayerModel>
ArrayList<SuperPlayerModel> list = new ArrayList<>();
SuperPlayerModel model = new VideoModel();
model = new SuperPlayerModel();
model.videoId = new SuperPlayerVideoId();
model.appid = 1252463788;
model.videoId.fileId = "4564972819219071568";
list.add(model);
model = new SuperPlayerModel();
model.videoId = new SuperPlayerVideoId();
model.appid = 1252463788;
model.videoId.fileId = "4564972819219071679";
list.add(model);
// Step 2. Call the loop API
mSuperPlayerView.playWithModelListNeedLicence(list, true, 0);
public void playWithModelListNeedLicence(List<SuperPlayerModel> models, boolean isLoopPlayList, int index);
API parameters:
Parameter | Type | Description |
---|---|---|
models | List |
Loop data list |
isLoopPlayList | boolean | Whether to loop video playback |
index | int | Index of SuperPlayerModel from which to start the playback |
The Player component supports the video preview feature, which allows non-member viewers to view a preview of the video. You can pass in different parameters to control the video preview duration, prompt message, and preview end screen. You can try out this feature in Tencent Cloud Toolkit App > Player > Player Component > Preview Feature Demo.
Method 1:
// Step 1. Create a video model
SuperPlayerModel mode = new SuperPlayerModel();
//... Add the video source information
// Step 2. Create a preview information model
VipWatchModel vipWatchModel = new VipWatchModel("You can preview %ss and activate the VIP membership to watch the full video",15);
mode.vipWatchMode = vipWatchModel;
// Step 3. Call the method for playing back videos
mSuperPlayerView.playWithModelNeedLicence(mode);
Method 2:
// Step 1. Create a preview information model
VipWatchModel vipWatchModel = new VipWatchModel("You can preview %ss and activate the VIP membership to watch the full video",15);
// Step 2. Call the method for setting the preview feature
mSuperPlayerView.setVipWatchModel(vipWatchModel);
public VipWatchModel(String tipStr, long canWatchTime)
VipWatchModel
API parameter description:
Parameter | Type | Description |
---|---|---|
tipStr | String | Preview prompt message |
canWatchTime | Long | Preview duration in seconds |
The Player component allows you to add a randomly moving text watermark to protect your content against piracy. Watermarks are visible in both the full screen mode and windowed mode. The text, font size, and color of a watermark are customizable. You can find a demo for this feature in the TCToolkit app: Player > Player Component > Dynamic Watermark Demo.
Method 1:
// Step 1. Create a video model
SuperPlayerModel mode = new SuperPlayerModel();
//... Add the video source information
// Step 2. Create a watermark information model
DynamicWaterConfig dynamicWaterConfig = new DynamicWaterConfig("shipinyun", 30, Color.parseColor("#80FFFFFF"));
mode.dynamicWaterConfig = dynamicWaterConfig;
// Step 3. Call the method for playing back videos
mSuperPlayerView.playWithModelNeedLicence(mode);
Method 2:
// Step 1. Create a watermark information model
DynamicWaterConfig dynamicWaterConfig = new DynamicWaterConfig("shipinyun", 30, Color.parseColor("#80FFFFFF"));
// Step 2. Call the method for setting the dynamic watermark feature
mSuperPlayerView.setDynamicWatermarkConfig(dynamicWaterConfig);
public DynamicWaterConfig(String dynamicWatermarkTip, int tipTextSize, int tipTextColor)
API parameters:
Parameter | Type | Description |
---|---|---|
dynamicWatermarkTip | String | Watermark text information |
tipTextSize | int | Text size |
tipTextColor | int | Text color |
To try out more features, you can directly run the project demo or scan the QR code to download the TCToolkit App demo.
$SuperPlayer_Android/Demo
directory of the demo project. After the demo project is imported successfully, click Run app to run the demo.You can try out more features of the Player component in TCToolkit App > Player.
Was this page helpful?