Superplayer for Android

Last updated: 2020-04-02 16:31:48

    Overview

    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.

    • Basic features: landscape/portrait mode switch, definition selection, gestures, small window playback, etc.
    • Advanced features: video buffering, software/hardware decoding switch, adjustable-speed playback, video thumbnails, DRM-encrypted playback, etc.

    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.

    SDK Download

    The VOD superplayer SDK for Android can be downloaded here.

    Quick Integration

    It takes just a few simple steps to integrate with the VOD superplayer SDK for video playback.

    aar integration

    1. Download the SDK and Demo development kit for Android here: SuperPlayer_Android.
    2. Import SDK/LiteAVSDK_XXX.aar and Demo/app/libs/lib_tcsuperplayer.aar into the project.
    3. Add dependencies to app/build.gralde:
      compile(name: 'LiteAVSDK_Professional', ext: 'aar')
      compile(name: 'lib_tcsuperplayer', ext: 'aar')
      // Third-party library for integration of the on-screen commenting feature of superplayer
      compile 'com.github.ctiao:DanmakuFlameMaster:0.5.3'
    4. Add the following to the project's build.gradle:
      ...
      allprojects {
       repositories {
           flatDir {
               dirs 'libs'
           }
           ...
       }
      }
      ...
    5. Declare the 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" />

    Note:

    lib_tcsuperplayer.aar is made open source in the form of module. You can find all the source code in Demo/lib_tcsuperplayer.

    Preparing videos

    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.

    Starting playback

    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.

    Thumbnails and Timestamps

    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.

    How to use

    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

    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

    Exiting Playback

    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();

    More Features

    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?

    Was this page helpful?

    • Not at all
    • Not very helpful
    • Somewhat helpful
    • Very helpful
    • Extremely helpful
    Send Feedback
    Help