The superplayer SDK for Android is a player component used to play back videos in VOD. It can implement powerful playback functionality similar to Tencent Video with just a few lines of code.
The superplayer SDK supports more formats and has better compatibility and functionality than system-default players. In addition, it features instant playback on splash screen and low latency.
The VOD superplayer SDK for Android can be downloaded here.
It takes just a few simple steps to integrate with the VOD superplayer SDK for video playback.
SDK/LiteAVSDK_XXX.aar
and Demo/superplayerkit
into the project.app/build.gradle
:compile(name: 'LiteAVSDK_Player_7.4.9211', ext: 'aar')
compile project(':superplayerkit')
// Third-party library for integration of the on-screen commenting feature of superplayer
compile 'com.github.ctiao:DanmakuFlameMaster:0.5.3'
build.gradle
:...
allprojects {
repositories {
flatDir {
dirs 'libs'
}
...
}
}
...
<!--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" />
Log in to the VOD Console, click Media Assets on the left sidebar, and you will see the uploaded video and its corresponding ID (i.e., FileId
) in the video list in the Uploaded column. If you don't have a video, please click Upload Video to upload one.
You can initiate an adaptive bitrate streaming task for the uploaded video through ProcessMedia:
You are recommended to enter 10 for MediaProcessTask.AdaptiveDynamicStreamingTaskSet.Definition
in the API parameter, indicating transcoding to adaptive bitstream in HLS format.
The main class of the player is SuperPlayerView
, and videos can be played back after it is created.
mSuperPlayerView = findViewById(R.id.main_super_player_view);
// Configure video information through `fileid`
SuperPlayerModel model = new SuperPlayerModel();
model.appid = 1256993030; // AppId
model.fileid = "7447398157015849771"; // Video `FileId`
model.videoId.playDefinition = "10"; // Playback template
model.videoId.version = SuperPlayerVideoId.FILE_ID_V3;
// Start playback
mSuperPlayerView.playWithMode(model);
In the code, appid
is your AppId, fileid
is the ID of the video you want to play back, playDefinition
is the ID of the playback template used for playback, and version
is fixed to SuperPlayerVideoId.FILE_ID_V3
.
Run the code and you can see that the video is played back on the phone and most of the features in the UI are available.
When videos are played back, the "thumbnails" and "timestamps" on the progress bar can help viewers find the points of interest easily. Thumbnails are implemented through image sprites, while timestamps by modifying timestamp information in media assets.
After image sprites are generated and timestamps are added, new elements will be displayed in the player UI.
First, the application needs to get the token from your business backend. Then, play back the video through FileId
and Token
with the following playback code:
SuperPlayerModel model = new SuperPlayerModel();
String fileId = "7447398157015849771";
model.appId = 1256993030;
model.videoId = new SuperPlayerVideoId();
model.videoId.fileId = fileId;
model.videoId.playDefinition = "20"; // Playback template
model.videoId.version = SuperPlayerVideoId.FILE_ID_V3; // The V3 protocol needs to be used for DRM
try {
// The token needs to be URL-encoded
String encodedToken = URLEncoder.encode("Token issued by the business", "UTF-8");
model.token = encodedToken;
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
mSuperPlayerView.playWithModel(model);
Small window playback can float on top of all Activities
. It is very simple. You just need to call the following code before playback starts:
// Player configuration
SuperPlayerGlobalConfig prefs = SuperPlayerGlobalConfig.getInstance();
// Enable floating window playback
prefs.enableFloatWindow = true;
// Set the initial position, width, and height of the floating window
SuperPlayerGlobalConfig.TXRect rect = new SuperPlayerGlobalConfig.TXRect();
rect.x = 0;
rect.y = 0;
rect.width = 810;
rect.height = 540;
// Other configurations
If the player is no longer needed, please call resetPlayer
to clear the internal state of the player and free up the memory.
mSuperPlayerView.resetPlayer();
To try out the complete features, scan the QR code below to download the Tencent Video Cloud toolkit or run the project demo directly.
Was this page helpful?