App下載

video循環(huán)播放多個視頻有哪些方法?方法步驟分享!

來源: 流年絮語 2021-08-16 11:52:16 瀏覽數(shù) (17348)
反饋

今天我們來說說好我們?nèi)粘S嘘P(guān)的內(nèi)容,那么:“video循環(huán)播放多個視頻有哪些方法?”這個問題就是今天和大家分享的相關(guān)內(nèi)容,希望對小伙伴們有所幫助! 

設(shè)計流程

1.掃描二維碼時,將其視頻列表存入model中,存入第一條是為了,不在html界面重新獲取第一條視頻:

  model.addAttribute("playUrl", videos.get(0).getVideoUrl());
  model.addAttribute("videoUrls", JsonUtils.toJson(videos));

2.返回其對應(yīng)的html界面:

return "client/coursePlayer.html";

3.使用video 播放視頻第一條視頻:

  <video id="videoID" controls="true"
           style="object-fit:fill"
           src="${playUrl}"
           class="horizontal-img"
           preload="metadata"
           webkit-playsinline="true"
           playsinline="true"
           x-webkit-airplay="allow"
           x5-video-player-type="h5"
           x5-video-player-fullscreen="true"
           x5-video-orientation="landscape"
           autoplay>
      抱歉,您的瀏覽器不支持內(nèi)嵌視頻!
    </video>

4.用ended 監(jiān)控視頻播放進度:

<script type="application/javascript">
  videoDom.addEventListener('ended', function(event) {
    if (index === length-1) {
      videoDom.pause();
    } else {
      index += 1;
      videoDom.src = videos[index].videoUrl;
      videoDom.play();
    }
  })
 </script>

html界面如下:

<!doctype html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport"
        content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>${title}</title>
  <style>
    .video {
      position: fixed;
      top: 0;
      bottom: 0;
      right: 0;
      left: 0;
      z-index: 99;
      transition: all 0.3s;
      background-color: rgba(0, 0, 0, 0.5);
    }

    .video-content {
      height: 100%;
      width: 100%;
    }

    video {
      position: initial;
    }

    video.horizontal-img {
      width: 100%;
      height: auto;
      max-height: 100%;
    }
  </style>
</head>
<body>
<div class="video">
  <div class="video-content">
    <video id="videoID" controls="true"
           style="object-fit:fill"
           src="${playUrl}"
           class="horizontal-img"
           preload="metadata"
           webkit-playsinline="true"
           playsinline="true"
           x-webkit-airplay="allow"
           x5-video-player-type="h5"
           x5-video-player-fullscreen="true"
           x5-video-orientation="landscape"
           autoplay>
      抱歉,您的瀏覽器不支持內(nèi)嵌視頻!
    </video>
  </div>
</div>
<script type="application/javascript">
  var dom = document;
  var index = 0;
  var videos = ${videoUrls};
  var videoDom = dom.getElementById('videoID');
  videoDom.play();
  videoDom.addEventListener('ended', function(event) {
    if (index === length-1) {
      videoDom.pause();
    } else {
      index += 1;
      videoDom.src = videos[index].videoUrl;
      videoDom.play();
    }
  })
</script>
</body>
</html>

那么到此這篇關(guān)于:“video循環(huán)播放多個視頻有哪些方法?”這個問題的解決方法和代碼就分享到這里了,更多有關(guān)于HTML5 video標(biāo)簽這方面的相關(guān)內(nèi)容我們都可以在W3Cschool中進行學(xué)習(xí)和了解!


0 人點贊