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 | Homepage entry |
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 `10.8.0.29000`implementation 'com.tencent.liteav:LiteAVSDK_Player_Premium:latest.release'// If you want to integrate the basic version of the player// implementation 'com.tencent.liteav:LiteAVSDK_Player:latest.release'}
common
module into your project as instructed above and configure it.mavenCentral
library in Gradle, and LiteAVSDK will be automatically downloaded and updated. Open app/build.gradle
and configure as follows:LiteAVSDK_Player_Premium
dependencies to dependencies
.dependencies {implementation 'com.tencent.liteav:LiteAVSDK_Player_Premium:latest.release'// If you want to integrate the basic version of the player// implementation 'com.tencent.liteav:LiteAVSDK_Player:latest.release'implementation project(':superplayerkit')}
dependencies {// Integrate the LiteAVSDK_Player_Premium SDK v10.8.0.29000implementation 'com.tencent.liteav:LiteAVSDK_Player_Premium:10.8.0.29000'// If you want to integrate the basic version of the player// implementation 'com.tencent.liteav:LiteAVSDK_Player:latest.release'}
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"}
mavenCentral
library to the build.gradle
in your project directory.repositories {mavenCentral()}
SDK/LiteAVSDK_Player_Premium_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_Premium_10.8.0.29000', 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_Premium_10.8.0.29000', 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"}
SDK/LiteAVSDK_Player_Premium_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 paths of the local repositories.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" />
<?xml version="1.0" encoding="utf-8"?><network-security-config><domain-config cleartextTrafficPermitted="true"><domain includeSubdomains="true">127.0.0.1</domain></domain-config></network-security-config>
<?xml version="1.0" encoding="utf-8"?><manifest ... ><application android:networkSecurityConfig="@xml/network_security_config"... >...</application></manifest>
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" />
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);
// If you haven't enabled hotlink protection and a "no v4 play info" error occurs, transcode your video by using the Adaptive-HLS template (ID: 10) or get the playback URL of the video and play it by URL.SuperPlayerModel model = new SuperPlayerModel();model.appId = 1400329071;// Configure AppIdmodel.videoId = new SuperPlayerVideoId();model.videoId.fileId = "5285890799710173650"; // Configure `FileId`// `psign` is a player signature. 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";mSuperPlayerView.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 thumbnail will be displayed before the first video frame is loaded.PLAY_ACTION_MANUAL_PLAY
, videos are played only after users tap the play button, and 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<SuperPlayerModel> | Loop data list |
isLoopPlayList | boolean | Whether to loop video playback |
index | int | Index of SuperPlayerModel from which to start the playback |
<activity>android:name=".demo.SuperPlayerActivity"android:resizeableActivity="true"android:supportsPictureInPicture="true"android:documentLaunchMode="intoExisting"android:excludeFromRecents="true"android:configChanges="orientation|keyboardHidden|screenSize|smallestScreenSize|screenLayout"></activity>
PictureInPictureHelper mPictureInPictureHelper = new PictureInPictureHelper(mContext);mPictureInPictureHelper.setListener(this);mPictureInPictureHelper.enterPictureInPictureMode(getPlayerState(),mTXCloudVideoView);
mPictureInPictureHelper.release();
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 |
DownloadMenuListView
(cache selection list view) is used to select and download videos at different definitions. After selecting the definition in the top-left corner, click the option of the video to be downloaded. When a check mark appears, the download has started. After clicking the video download list button below, you will be redirected to the Activity where VideoDownloadListView
is located.// Step 1. Initialize the download data with the following parametersDownloadMenuListView mDownloadMenuView = findViewById(R.id.superplayer_cml_cache_menu);mDownloadMenuView.initDownloadData(superPlayerModelList, mVideoQualityList, mDefaultVideoQuality, "default");// Step 2. Set the options of the video being played backmDownloadMenuView.setCurrentPlayVideo(mSuperplayerModel);// Step 3. Set the click event of the **video download list** buttonmDownloadMenuView.setOnCacheListClick(new OnClickListener() {@Overridepublic void onClick(View v) {// Redirect to the Activity where `VideoDownloadListView` is locatedstartActivity(DownloadMeduListActivity.this,VideoDownloadListActivity.class);}});// Step 4. Display the view with animationmDownloadMenuView.show();
public void initDownloadData(List<SuperPlayerModel> superPlayerModelList,List<VideoQuality> qualityList,VideoQuality currentQuality,String userName)
Parameter | Type | Description |
superPlayerModelList | List<SuperPlayerModel> | The downloaded video data |
qualityList | List<VideoQuality> | The video definition data |
currentQuality | VideoQuality | The current video definition |
userName | String | The username |
VideoDownloadListView
(video download list) displays the list of views of all the videos that are being downloaded and have been downloaded. When this button is clicked, if the download is in progress, it will be paused; if it is paused, it will be resumed; if it has completed, the video will be played back.// Step 1. Bind the controlVideoDownloadListView mVideoDownloadListView = findViewById(R.id.video_download_list_view);//Step 2. Add datamVideoDownloadListView.addCacheVideo(mDataList, true);
public void addCacheVideo(List<TXVodDownloadMediaInfo> mediaInfoList, boolean isNeedClean);
Parameter | Type | Description |
mediaInfoList | List<TXVodDownloadMediaInfo> | The type of the added video data |
isNeedClean | boolean | Whether to clear the previous data |
// Step 1. Get the image sprite and timestamp information in the `onPlayEvent` callback (this works only if the video is played back through `PlayWithField`, with the `url` variable of `superplayerModel` being empty and `videoId` not being empty).mSuperplayerView.play(superplayerModel);// Step 2. Get timestamp and image sprite information in the `VOD_PLAY_EVT_GET_PLAYINFO_SUCC` callback event during playback through `PlayWithFileId`.public void onPlayEvent(TXVodPlayer player, int event, Bundle param) {switch (event) {case TXVodConstants.VOD_PLAY_EVT_GET_PLAYINFO_SUCC:// Get the list of image URLs of the image spriteplayImageSpriteInfo.imageUrls = param.getStringArrayList(TXVodConstants.EVT_IMAGESPRIT_IMAGEURL_LIST);// Get the download URL of the image sprite WebVTT fileplayImageSpriteInfo.webVttUrl = param.getString(TXVodConstants.EVT_IMAGESPRIT_WEBVTTURL);// Get the timestamp informationArrayList<String> keyFrameContentList =param.getStringArrayList(TXVodConstants.EVT_KEY_FRAME_CONTENT_LIST);// Get the time information of the timestamp informationfloat[] keyFrameTimeArray = param.getFloatArray(TXVodConstants.EVT_KEY_FRAME_TIME_LIST);// Construct the list of timestamp informationif (keyFrameContentList != null && keyFrameTimeArray != null&& keyFrameContentList.size() == keyFrameTimeArray.length) {for (int i = 0; i < keyFrameContentList.size(); i++) {PlayKeyFrameDescInfo frameDescInfo = new PlayKeyFrameDescInfo();frameDescInfo.content = keyFrameContentList.get(i);frameDescInfo.time = keyFrameTimeArray[i];mKeyFrameDescInfoList.add(frameDescInfo);}}break;default:break;}}// Step 3. Assign the obtained timestamp information and image sprite to the corresponding view through the `updateVideoImageSpriteAndKeyFrame` method.// The view of the image sprite corresponds to `mIvThumbnail` in the `VideoProgressLayout` component.// The view of the timestamp information corresponds to `TCPointView` in the `PointSeekBar` component.updateVideoImageSpriteAndKeyFrame(playImageSpriteInfo,keyFrameDescInfoList);
SuperPlayerModel#subtitleSourceModelList
.// Pass in subtitle url, subtitle name, and subtitle typeSubtitleSourceModel subtitleSourceModel = new SubtitleSourceModel();subtitleSourceModel.name = "ex-cn-srt";subtitleSourceModel.url = "https://mediacloud-76607.gzc.vod.tencent-cloud.com/DemoResource/TED-CN.srt";subtitleSourceModel.mimeType = TXVodConstants.VOD_PLAY_MIMETYPE_TEXT_SRT;model.subtitleSourceModelList.add(subtitleSourceModel);// PlaymSuperPlayerView.playWithModelNeedLicence(model);
// After the video starts playing, select the added external subtitles.public void onClickSubTitleItem(TXTrackInfo clickInfo) {List<TXTrackInfo> subtitleTrackInfoList = mVodPlayer.getSubtitleTrackInfo();for (TXTrackInfo trackInfo : subtitleTrackInfoList) {if (trackInfo.trackIndex == clickInfo.trackIndex) {// Select the subtitlemVodPlayer.selectTrack(trackInfo.trackIndex);mSelectedSubtitleTrackInfo = trackInfo;} else {// Deselect other subtitles if they are not needed.mVodPlayer.deselectTrack(trackInfo.trackIndex);}}}
TXSubtitleRenderModel model = new TXSubtitleRenderModel();model.canvasWidth = 1920; // Subtitle render canvas widthmodel.canvasHeight = 1080; // Subtitle render canvas heightmodel.fontColor = 0xFFFFFFFF; // Set the subtitle font color, default white and opaquemodel.isBondFontStyle = false; // Set whether the subtitle font is boldmVodPlayer.setSubtitleStyle(model);
// Step 1: Configure FileId that supports ghost watermark to play videoSuperPlayerModel model = new SuperPlayerModel(); model.appId = 1500006438; model.videoId.fileId = "387702307847129127"; model.videoId.pSign = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJhcHBJZCI6MTUwMDA" + "wNjQzOCwiZmlsZUlkIjoiMzg3NzAyMzA3ODQ3MTI5MTI3IiwiY29udG" + "VudEluZm8iOnsiYXVkaW9WaWRlb1R5cGUiOiJSYXdBZGFwdGl2ZSIsIn" + "Jhd0FkYXB0aXZlRGVmaW5pdGlvbiI6MTB9LCJjdXJyZW50VGltZVN0YW1w" + "IjoxNjg2ODgzMzYwLCJnaG9zdFdhdGVybWFya0luZm8iOnsidGV4dCI6I" + "mdob3N0IGlzIHdhdGNoaW5nIn19.0G2o4P5xVZ7zF" + "lFUgBLntfX03iGxK9ntD_AONClUUno"; mSuperPlayerView.playWithModelNeedLicence(model);// Step 2: After receiving the ghost watermark content callback in SuperPlayerView#onRcvWaterMark, display the ghost watermarkpublic void onRcvWaterMark(String text, long duration) { if (!TextUtils.isEmpty(text)) { DynamicWaterConfig dynamicWaterConfig = new DynamicWaterConfig(text, 30, Color.parseColor("#30FFFFFF")); dynamicWaterConfig.durationInSecond = duration; dynamicWaterConfig.setShowType(DynamicWaterConfig.GHOST_RUNNING); setDynamicWatermarkConfig(dynamicWaterConfig); } }
$SuperPlayer_Android/Demo
directory of the demo project. After the demo project is imported successfully, click Run app to run the demo.
この記事はお役に立ちましたか?