Abstract:

scenario

If have many video, when the last video plays end, play next video automatically, how should handle? Different implementations are required depending on the type of player used and the address format to switch.

Live address mode

H5 and Flash behave the same. Just subscribe to ‘ended’. In the ended event, call the loadByUrl method with the parameter as the address of the next video.

function endedHandle()
{
  var newUrl = "";
  player.loadByUrl(newUrl);
}

player.on("ended", endedHandle);Copy the code

Vid + Playauth Saas playback mode

Vid and Playauth Saas play modes, H5 and Flash require different handling modes:

  • H5 calls the replayByVidAndPlayAuth method in a Ended event. The parameters are VID and the new playauth value.
  • Flash does not provide a way to switch between VID and Playauth. You need to destroy and recreate the player.

Note: Playauth is only valid for 100s. When replayByVidAndPlayAuth is called, the playAuth needs to be reproduced to get the playauth

H5 Player

function endedHandle()
{
  var newPlayAuth = ""; 
  player.replayByVidAndPlayAuth(vid,newPlayAuth);
}

player.on("ended", endedHandle);Copy the code

Flash Player

function endedHandle()
{
    var newPlayAuth = ""; player.dispose(); / / destruction of $('#J_prismPlayer').empty(); // create player = new Aliplayer({id:'J_prismPlayer',
              autoplay: true,
              playsinline:true,
              vid: vid,
              playauth:newPlayAuth,
              useFlashPrism:true
         });
    }
}

player.on("ended", endedHandle);Copy the code

Address protocol is handled differently

If the original video was played by MP4 and now the new address is the video address of HLS, you can only recreate the player.

function endedHandle()
{
    var newUrl = ""; // New player.dispose(); / / destruction of $('#J_prismPlayer').empty(); // create player = new Aliplayer({id:'J_prismPlayer',
              autoplay: true,
              playsinline:true.source:newUrl
         });
    }
}

player.on("ended", endedHandle);Copy the code

Author: 樰 Hedge