簡體   English   中英

在特定點播放和暫停 html5 視頻

[英]Play and pause html5 video at certain point

我想在mySlides類被替換后開始播放視頻,它實際上是顯示的視頻元素。 視頻完成后,我想暫停,但聲音仍然沒有播放。 基本上它現在所做的是顯示第一個div但是,從它后面的視頻中添加聲音。 任何幫助或指導將不勝感激。

 var slideIndex = 0; showSlides(); function showSlides() { var i; var slides = document.getElementsByClassName("mySlides"); var dots = document.getElementsByClassName("dot"); var vid = document.getElementById("vid"); for (i = 0; i < slides.length; i++) { slides[i].style.display = "none"; } slideIndex++; if (slideIndex > slides.length) { slideIndex = 1 } for (i = 0; i < dots.length; i++) { dots[i].className = dots[i].className.replace(" active", ""); } slides[slideIndex - 1].style.display = "block"; dots[slideIndex - 1].className += " active"; vid.pause(); vid.currentTime = 0; vid.play(); setTimeout(showSlides, 36000); // Change image every minute }
 * { box-sizing: border-box } body { font-family: Verdana, sans-serif; margin: 0; } .mySlides { display: none } /* Slideshow container */ .slideshow-container { position: relative; margin: 0; width: 100%; height: 100%; } /* Caption text */ .text { color: #f2f2f2; font-size: 15px; padding: 8px 12px; position: absolute; bottom: 8px; width: 100%; text-align: center; } /* Number text (1/3 etc) */ .numbertext { color: #f2f2f2; font-size: 12px; padding: 8px 12px; position: absolute; top: 0; } /* The dots/bullets/indicators */ .dot { height: 15px; width: 15px; margin: 0 2px; background-color: #ffffff; border-radius: 50%; display: inline-block; transition: background-color 0.6s ease; } .active { background-color: #ffffff; } /* Fading animation */ .fade { -webkit-animation-name: fade; -webkit-animation-duration: 1.5s; animation-name: fade; animation-duration: 1.5s; } @-webkit-keyframes fade { from { opacity: .4 } to { opacity: 1 } } @keyframes fade { from { opacity: .4 } to { opacity: 1 } } /* On smaller screens, decrease text size */ @media only screen and (max-width: 300px) { .text { font-size: 11px } }
 <meta http-equiv="refresh" content="8000"> <div class="slideshow-container"> <div class="mySlides fade"> <iframe src="http://192.168.4.68" style="position:fixed; top:0px; left:0px; bottom:0px; right:0px; width:100%; height:100%; border:none; margin:0; padding:0; overflow:hidden; z-index:999999;"></iframe> </div> <div class="mySlides fade"> <video id="vid" src="/static/PUT_MEETING_08-20_WSUBS.webm"></video> </div> </div> <br> <div style="text-align:center"> <span class="dot"></span> <span class="dot"></span> </div>

所以我添加了這個,它就像一個魅力! 可能會很亂,但是,它可以完成工作。 感謝大家的幫助!

if(String(slides[slideIndex-1].children.item(0).outerHTML).includes("video")) {

  var vid = document.getElementById("vid");
  vid.play();
} 
else 
{
  var vid = document.getElementById("vid");

  vid.pause();
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM