All Products
Search
Document Center

Video playback

Last Updated: Aug 01, 2019

Instant loading solution

SmartVideo uses the full-screen instant loading solution to play videos. For more information, see Use ApsaraVideo Player to quickly implement full-screen instant loading.

Quickly integrate the instant loading solution

Step 1: Import files

  • Copy the code and relevant resource files in the com/aliyun/apsara/alivclittlevideo/view/video/videolist directory of the AlivcLittleVideo module. Copy files for SmartVideo playback

  • Copy the Aliyunplayer module. Image

Step 2: Import packages and build.gradle configuration

  • Add the following reference to the settings.gradle file of your project:
include ':Aliyunplayer:AlivcPlayer'
include ':Aliyunplayer:AlivcReporter'
include ':Aliyunplayer:AlivcVodPlayer'
  • Add the dependency configuration to the build.gradle file of your project.
dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    //...

    // The dependent libraries of the player.
    api project(':Aliyunplayer:AlivcPlayer')
    api project(':Aliyunplayer:AlivcReporter')
    api project(':Aliyunplayer:AlivcVodPlayer')
}

Step 3: Use the solution

  1. Call the addView method to add an AlivcVideoListView instance to the UI. The sample code is as follows:
/**
     * Initializes the video list.
     */
    private void initPlayListView() {
        videoListView = new AlivcVideoListView(context);
        // Creates an adapter to inherit the BaseVideoListAdapter class.
        final LittleVideoListAdapter adapter = new LittleVideoListAdapter(context);
        // Adds the adapter to the AlivcVideoListView instance.
        videoListView.setAdapter(adapter);
        videoListView.setVisibility(VISIBLE);
        // Sets the number of player instances.
        videoListView.setPlayerCount(3);
        // Configures a listener for a vertical swipe gesture to load data.
        videoListView.setOnRefreshDataListener(new AlivcVideoListView.OnRefreshDataListener() {
            @Override
            public void onRefresh() {
                if (onRefreshDataListener ! = null) {
                    onRefreshDataListener.onRefresh();
                }
            }

            @Override
            public void onLoadMore() {
                if (onRefreshDataListener ! = null) {
                    onRefreshDataListener.onLoadMore();
                }
            }
        });
        // Configures a listener for video loading.
        videoListView.setLoadingListener(new IAliyunVodPlayer.OnLoadingListener() {
            @Override
            public void onLoadStart() {
                controlView.updateLoadingView(true);
            }

            @Override
            public void onLoadEnd() {
                controlView.updateLoadingView(false);
            }

            @Override
            public void onLoadProgress(int i) {

            }
        });
        // Configures a listener for the expiration of authentication information to update the authentication information.
        videoListView.setTimeExpiredErrorListener(new IAliyunVodPlayer.OnTimeExpiredErrorListener() {

            @Override
            public void onTimeExpiredError() {
                if (mTimeExpiredErrorListener! =null){
                    mTimeExpiredErrorListener.onTimeExpiredError();
                }
            }
        });
        // Adds the AlivcVideoListView instance to the layout.
        addSubView(videoListView);
    }
  1. Configure playback data.

  2. Refresh playback data. The sample code is as follows:

/**
     * Refreshes the video list.
     *
     * @param datas
     */
    public void refreshVideoList(List<AlivcVideoInfo.Video> datas) {
        List<IVideoSourceModel> videoList = new ArrayList<>();
        videoList.addAll(datas);
        videoListView.refreshData(videoList);
        // Cancels loading.
        controlView.updateLoadingView(false);
    }
  • Add playback data. The sample code is as follows:
/**
     * Adds more videos.
     *
     * @param datas
     */
    public void addMoreData(List<AlivcVideoInfo.Video> datas) {
        List<IVideoSourceModel> videoList = new ArrayList<>();
        videoList.addAll(datas);
        videoListView.addMoreData(videoList);
        // Cancels loading.
        controlView.updateLoadingView(false);

    }