How to use aliplayer to achieve continuous video playback?

Abstract : If there are multiple videos in the scene, when the previous video finishes playing, the next video will be played automatically. How to deal with it? Different implementation methods need to be adopted according to the type of player used and the address format to be switched. The live address method is the simplest. The behavior of h5 and flash is the same. You only need to subscribe to 'ended'. In the ended event, call the loadByUrl method, and the parameter is the address of the next video.
If there are multiple videos in the scene
, when the previous video finishes playing, the next video will be played automatically. How to deal with it? Different implementation methods need to be adopted according to the type of player used and the address format to be switched. Live address method
This method is the simplest, the behavior of h5 and flash are the same, only need to subscribe to 'ended', in the ended event, call the loadByUrl method, the parameter is the address of the next video.
function endedHandle()
{
  var newUrl = "";
  player.loadByUrl(newUrl);
}

player.on("ended", endedHandle);

vid+playauth Saas playback mode
vid and playauth Saas playback mode, h5 and flash need different processing methods: h5 calls the replayByVidAndPlayAuth method in the end event, the parameters are vid and the new playauth value. Flash does not provide a method to switch between vid and playauth, it needs to destroy and recreate the player. Note: The validity period of playauth is only 100s. When calling the replayByVidAndPlayAuth method, you need to re-produce the playauth
H5 Player
function endedHandle()
{
  var newPlayAuth = "";
  player.replayByVidAndPlayAuth(vid,newPlayAuth);
}

player.on("ended", endedHandle);

Flash Player

function endedHandle()
{
    var newPlayAuth = "";
    player.dispose(); //destroy
    $('#J_prismPlayer').empty();//id is the container id of the player specified in html
     //rebuild
    player = new Aliplayer({
              id: 'J_prismPlayer',
              autoplay: true,
              playsinline:true,
              vid: vid,
              playauth:newPlayAuth,
              useFlashPrism:true
         });
    }
}
player.on("ended", endedHandle);

The address protocol is handled differently.
If the original playback is the mp4 video, and the new address is the hls video address, in this case, the player can only be recreated.
function endedHandle()
{
    var newUrl = ""; //New playback address
    player.dispose(); //destroy
    $('#J_prismPlayer').empty(); //id is the container id of the player specified in html
     //rebuild
    player = new Aliplayer({
              id: 'J_prismPlayer',
              autoplay: true,
              playsinline:true,
              source:newUrl
         });
    }
}

player.on("ended", endedHandle);

Author: Kagura

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326310654&siteId=291194637