All Products
Search
Document Center

Video playback

Last Updated: Apr 03, 2020

Instant loading solution

SmartVideo uses the full-screen instant loading solution to play videos. For more information, see Video playback.

Quickly integrate the instant loading solution

Step 1. Copy 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 integrating the instance loading solution

Step 2. Reference the preceding folders and configure the build.gradle file

  • Add the dependency configuration to the build.gradle file of your project.
  1. dependencies {
  2. implementation fileTree(dir: 'libs', include: ['*.jar'])
  3. //...
  4. // The dependent libraries of the player.
  5. api externalPlayerPart
  6. }

Step 3. Use the solution

  1. Call the addView method to add an AlivcVideoListView instance to the UI. The sample code is as follows:
  1. /**
  2. * Initialize the video list.
  3. */
  4. private void initPlayListView() {
  5. videoListView = new AlivcVideoListView(context);
  6. // Create an adapter to inherit the BaseVideoListAdapter class.
  7. final LittleVideoListAdapter adapter = new LittleVideoListAdapter(context);
  8. // Add the adapter to the AlivcVideoListView instance.
  9. videoListView.setAdapter(adapter);
  10. videoListView.setVisibility(VISIBLE);
  11. // Set the number of player instances.
  12. videoListView.setPlayerCount(3);
  13. // Configure a listener for a vertical swipe gesture to load data.
  14. videoListView.setOnRefreshDataListener(new AlivcVideoListView.OnRefreshDataListener() {
  15. @Override
  16. public void onRefresh() {
  17. if (onRefreshDataListener != null) {
  18. onRefreshDataListener.onRefresh();
  19. }
  20. }
  21. @Override
  22. public void onLoadMore() {
  23. if (onRefreshDataListener != null) {
  24. onRefreshDataListener.onLoadMore();
  25. }
  26. }
  27. });
  28. // Configure a listener for video loading.
  29. videoListView.setLoadingListener(new IAliyunVodPlayer.OnLoadingListener() {
  30. @Override
  31. public void onLoadStart() {
  32. controlView.updateLoadingView(true);
  33. }
  34. @Override
  35. public void onLoadEnd() {
  36. controlView.updateLoadingView(false);
  37. }
  38. @Override
  39. public void onLoadProgress(int i) {
  40. }
  41. });
  42. // Configure a listener for the expiration of authentication information to update the authentication information.
  43. videoListView.setTimeExpiredErrorListener(new IAliyunVodPlayer.OnTimeExpiredErrorListener() {
  44. @Override
  45. public void onTimeExpiredError() {
  46. if (mTimeExpiredErrorListener!=null){
  47. mTimeExpiredErrorListener.onTimeExpiredError();
  48. }
  49. }
  50. });
  51. // Add the AlivcVideoListView instance to the layout.
  52. addSubView(videoListView);
  53. }
  1. Configure playback data.
  • Refresh playback data. The sample code is as follows:
  1. /**
  2. * Refresh the video list.
  3. *
  4. * @param datas
  5. */
  6. public void refreshVideoList(List<AlivcVideoInfo.Video> datas) {
  7. List<IVideoSourceModel> videoList = new ArrayList<>();
  8. videoList.addAll(datas);
  9. videoListView.refreshData(videoList);
  10. // Cancel loading.
  11. controlView.updateLoadingView(false);
  12. }
  • Add playback data. The sample code is as follows:
  1. /**
  2. * Add more videos.
  3. *
  4. * @param datas
  5. */
  6. public void addMoreData(List<AlivcVideoInfo.Video> datas) {
  7. List<IVideoSourceModel> videoList = new ArrayList<>();
  8. videoList.addAll(datas);
  9. videoListView.addMoreData(videoList);
  10. // Cancel loading.
  11. controlView.updateLoadingView(false);
  12. }