I have a list of video URLs. My goal is to play each item one by one until all items inside the array are played. What I tried below kinda works but it's a really bad approach. What's a better way to play each source inside the array turn by turn? Thanks in advance.
myArr = ["http://commondatastorage.googleapis.com/gtv-videos-bucket/sample/ForBiggerJoyrides.mp4", "http://commondatastorage.googleapis.com/gtv-videos-bucket/sample/ForBiggerMeltdowns.mp4", "http://commondatastorage.googleapis.com/gtv-videos-bucket/sample/ForBiggerFun.mp4"]
const sleep = ms => new Promise(resolve => setTimeout(resolve, ms));
(async() => {
  for (let i = 0; i < myArr.length; i++) {
    $('#video').attr('src', myArr[i])
    //wait until metadata is loaded
    await sleep(600)
    const duration = $('#video')[0].duration
    console.log(duration)
    $('#video').play()
    //wait until video finishes playing
    await sleep(duration);
  }
  console.log("done");
})();video {
  width: 100%;
  height: 40vh;
}<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<video id="video" src="" controls/> 
    