git clone git@github.com:tencentyun/SuperPlayer_Android.git
Cloning to 'SuperPlayer_Android'...remote: Enumerating objects: 2637, done.remote: Counting objects: 100% (644/644), done.remote: Compressing objects: 100% (333/333), done.remote: Total 2637 (delta 227), reused 524 (delta 170), pack-reused 1993Receiving the object: 100% (2637/2637), 571.20 MiB | 3.94 MiB/s, done.Processing delta: 100% (1019/1019), done.
Filename | Description |
LiteAVDemo(Player) | The Player demo project, which can be run directly after being imported into Android Studio. |
app | The entry of the main UI |
superplayerkit | The Player component ( SuperPlayerView ), which provides common features such as playback, pause, and gesture control. |
superplayerdemo | The Player component demo code |
common | Tool module |
SDK | Player SDK, including LiteAVSDK_Player_x.x.x.aar (SDK provided in AAR format) and LiteAVSDK_Player_x.x.x.zip (SDKs provided in lib and JAR formats) |
Player Documentation (Android).pdf | The Player component user guide |
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 26buildToolsVersion "26.0.2"defaultConfig {targetSdkVersion 23minSdkVersion 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.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 componentimplementation 'com.github.ctiao:DanmakuFlameMaster:0.5.3'}
dependencies {// Integrate the LiteAVSDK_Player SDK v8.5.10033implementation '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()}
mavenCentral
can be connected to, the SDK will be automatically downloaded and integrated into the project very soon.SDK/LiteAVSDK_Player_XXX.aar
(XXX
is the version number) into the libs
folder under app
and copy the Demo/superplayerkit
module to the project.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 26buildToolsVersion "26.0.2"defaultConfig {targetSdkVersion 23minSdkVersion 19}dependencies {implementation(name:'LiteAVSDK_Player_8.9.10349', ext:'aar')}
common
module into your project as instructed above and configure it.repositories
repositories {flatDir {dirs '../app/libs'}}
app/build.gradle
:compile(name:'LiteAVSDK_Player_8.9.10349', ext:'aar')implementation project(':superplayerkit')// Third-party library for integration of the on-screen commenting feature of the Player componentimplementation 'com.github.ctiao:DanmakuFlameMaster:0.5.3'
build.gradle
:allprojects {repositories {flatDir {dirs 'libs'}}}
defaultConfig
of app/build.gradle
, specify the CPU architecture to be used by the application (currently, LiteAVSDK supports armeabi, armeabi-v7a, and arm64-v8a).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"}
SDK/LiteAVSDK_Player_XXX.zip
(XXX
is the version number) in the SDK directory. After decompression, you can get the libs
directory, which contains the JAR file and folders of SO files as listed below:Demo/superplayerkit
module to your project and import superplayerkit
into setting.gradle
in your project directory.include ':superplayerkit'
libs
folder obtained by decompression in step 1 to the superplayerkit
project root directory.superplayerkit/build.gradle
file:compileSdkVersion 26buildToolsVersion "26.0.2"defaultConfig {targetSdkVersion 23minSdkVersion 19}
common
module into your project as instructed above and configure it.sourceSets
and add the SO library import code.sourceSets{main{jniLibs.srcDirs = ['libs']}}
repositories
, add flatDir
, and specify the path of the local repository.repositories {flatDir {dirs 'libs'}}
defaultConfig
of app/build.gradle
, specify the CPU architecture to be used by the application (currently, LiteAVSDK supports armeabi, armeabi-v7a, and arm64-v8a).ndk {abiFilters "armeabi", "armeabi-v7a", "arm64-v8a"}
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" />
proguard-rules.pro
file, add the classes related to the TRTC SDK to the "do not obfuscate" list:-keep class com.tencent.** { *;}
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.SuperPlayerViewandroid:id="@+id/superVodPlayerView"android:layout_width="match_parent"android:layout_height="200dp" />
Application
class:public class MApplication extends Application {@Overridepublic void onCreate() {super.onCreate();String licenceURL = ""; // The license URL obtainedString licenceKey = ""; // The license key obtainedTXLiveBase.getInstance().setLicence(this, licenceURL, licenceKey);TXLiveBase.setListener(new TXLiveBaseListener() {@Overridepublic void onLicenceLoaded(int result, String reason) {Log.i(TAG, "onLicenceLoaded: result:" + result + ", reason:" + reason);}});}}
FileID
or URL.SuperPlayerModel model = new SuperPlayerModel();model.appId = 1400329073; // Configure `AppId`model.url = "http://your_video_url.mp4"; // Configure a URL for your video for playbackmSuperPlayerView.playWithModelNeedLicence(model);
psign
to specify the video to play; otherwise, the playback may fail. For more information on how to transcode a video and generate psign
, see Play back a video with the Player component and Player Signature.FileId
, the above problem may exist. In this case, we recommend you make adjustments as instructed above. You can also directly get the playback link of the source video for playback through URL.// If you haven't enabled hotlink protection and a "no v4 play info" error occurs, we recommend you transcode your video using the Adaptive-HLS template (ID: 10) or get the playback URL of the video and play it by URL.SuperPlayerModel *model = [[SuperPlayerModel alloc] init];model.appId = 1400329071;// Configure AppIdmodel.videoId = [[SuperPlayerVideoId alloc] init];model.videoId.fileId = @"5285890799710173650"; // Configure `FileId`// If you enable hotlink protection, you need to enter a `psign` (player signature) for playback. For more information on the signature and how to generate it, see [Player Signature](https://www.tencentcloud.com/document/product/266/38099).//model.videoId.pSign = @"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJhcHBJZCI6MTQwMDMyOTA3MSwiZmlsZUlkIjoiNTI4NTg5MDc5OTcxMDE3MzY1MCIsImN1cnJlbnRUaW1lU3RhbXAiOjEsImV4cGlyZVRpbWVTdGFtcCI6MjE0NzQ4MzY0NywidXJsQWNjZXNzSW5mbyI6eyJ0IjoiN2ZmZmZmZmYifSwiZHJtTGljZW5zZUluZm8iOnsiZXhwaXJlVGltZVN0YW1wIjoyMTQ3NDgzNjQ3fX0.yJxpnQ2Evp5KZQFfuBBK05BoPpQAzYAWo6liXws-LzU";[_playerView playWithModelNeedLicence:model];
resetPlayer
to reset the player and free up memory.mSuperPlayerView.resetPlayer();
mControllerCallback.onSwitchPlayMode(SuperPlayerDef.PlayerMode.FULLSCREEN);
// API triggered after tappingmControllerCallback.onBackPressed(SuperPlayerDef.PlayerMode.FULLSCREEN);onSwitchPlayMode(SuperPlayerDef.PlayerMode.WINDOW);
// API triggered after tappingtoggleLockState();
// Step 1. Add an on-screen comment to the on-screen comment viewaddDanmaku(String content, boolean withBorder);// Step 2. Enable or disable on-screen commentingtoggleBarrage();
mSuperPlayer.snapshot
API.mSuperPlayer.snapshot(new TXLivePlayer.ITXSnapshotListener() {@Overridepublic void onSnapshot(Bitmap bitmap) {// The captured screenshot can be saved here}});
// The API for displaying the definition selection view triggered after the button is tappedshowQualityView();// The callback API for tapping the definition option is as followsmListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {@Overridepublic void onItemClick(AdapterView<?> parent, View view, int position, long id) {// The event of tapping the definition list viewVideoQuality quality = mList.get(position);mCallback.onQualitySelect(quality);}});// Callback for the selected definition@Overridepublic void onQualityChange(VideoQuality quality) {mFullScreenPlayer.updateVideoQuality(quality);mSuperPlayer.switchStream(quality);}
AndroidManifest
:<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW" />
// The API triggered by switching to the floating windowmSuperPlayerView.switchPlayMode(SuperPlayerDef.PlayerMode.FLOAT);// The API triggered by tapping the floating window to return to the main windowmControllerCallback.onSwitchPlayMode(SuperPlayerDef.PlayerMode.WINDOW);
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.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);
// 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 APImSuperPlayerView.playWithModelListNeedLicence(list, true, 0);
public void playWithModelListNeedLicence(List<SuperPlayerModel> models, boolean isLoopPlayList, int index);
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 |
Method 1:// Step 1. Create a video modelSuperPlayerModel mode = new SuperPlayerModel();//... Add the video source information// Step 2. Create a preview information modelVipWatchModel 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 videosmSuperPlayerView.playWithModelNeedLicence(mode);Method 2:// Step 1. Create a preview information modelVipWatchModel 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 featuremSuperPlayerView.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 |
Method 1:// Step 1. Create a video modelSuperPlayerModel mode = new SuperPlayerModel();//... Add the video source information// Step 2. Create a watermark information modelDynamicWaterConfig dynamicWaterConfig = new DynamicWaterConfig("shipinyun", 30, Color.parseColor("#80FFFFFF"));mode.dynamicWaterConfig = dynamicWaterConfig;// Step 3. Call the method for playing back videosmSuperPlayerView.playWithModelNeedLicence(mode);Method 2:// Step 1. Create a watermark information modelDynamicWaterConfig dynamicWaterConfig = new DynamicWaterConfig("shipinyun", 30, Color.parseColor("#80FFFFFF"));// Step 2. Call the method for setting the dynamic watermark featuremSuperPlayerView.setDynamicWatermarkConfig(dynamicWaterConfig);
public DynamicWaterConfig(String dynamicWatermarkTip, int tipTextSize, int tipTextColor)
Parameter | Type | Description |
dynamicWatermarkTip | String | Watermark text information |
tipTextSize | int | Text size |
tipTextColor | int | Text color |
$SuperPlayer_Android/Demo
directory of the demo project. After the demo project is imported successfully, click Run app to run the demo.
Was this page helpful?