//multi video player
let videoSource = new Array();
videoSource[0] = 'https://hw16.cdn.asset.aparat.com/aparat-video/8eab4cb75a416c654aa5ec617cc6743425163389-144p.mp4';
videoSource[1] = 'https://hw7.cdn.asset.aparat.com/aparat-video/e10169d6a4a91704c3a852e52a8b0a0925026838-144p.mp4';
videoSource[2] = 'https://hw20.cdn.asset.aparat.com/aparat-video/483492fb32b922f9ab0da3a41f8cfd9d24767112-144p.mp4';
var i = 0; // global
const videoCount = videoSource.length;
const element = document.getElementById("videoPlayer");
 
function videoPlay(videoNum) {
    element.setAttribute("src", videoSource[videoNum]);
    element.autoplay = true;
    element.load();
    element.play();
}
document.getElementById('videoPlayer').addEventListener('ended', myHandler, false);
 
videoPlay(0); // play the video
 
function myHandler() {
    i++;
    if (i == videoCount) {
        i = 0;
        videoPlay(i);
    } else {
        videoPlay(i);
    }
}