[英]How do I add a replay function to this play / pause button
我希望播放/暫停按鈕在視頻剪輯的末尾顯示“ replay
”。 用我已經擁有的功能做到這一點的最佳方法是什么。
// Event listener for the play/pause button
playButton.addEventListener("click", function() {
if (video.paused == true) {
// Play the video
video.play();
// Update the button text to 'Pause'
playButton.innerHTML = "Pause";
} else {
// Pause the video
video.pause();
// Update the button text to 'Play'
playButton.innerHTML = "Play";
}
});
video.addEventListener("ended", function(){
playButton.textContent = "replay";
});
看來您必須看一下這篇文章
您可以只聽視頻元素上的結束事件:
video.addEventListener('ended', function(e) {
playButton.innerHTML = "<img src='http://www.iconninja.com/files/838/134/365/replay-icon.png'/>";
})
將其添加到您的代碼中,每隔一秒鍾檢查一次,看媒體是否已完成播放
<video id='mediaObj'>.... </video>
<script>
setInterval(function (){
var aud = $('#mediaObj'); //get the html5 media object
curTime = parseInt(aud.currentTime); //get it current time
durTime = parseInt(aud.duration); //check it total play time/duration
if (curTime == durTime) playButton.innerHTML = "<img src='http://www.iconninja.com/files/838/134/365/replay-icon.png'/>"; // code to show replay button goes here
},1000);
</script>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.