3

我有一个视频需要在网站上展示。我不能让用户快进,但他们需要能够倒带。我在这里修改了示例:https ://www.w3schools.com/tags/tryit.asp?filename=tryhtml5_av_prop_controller

到以下:

<!DOCTYPE html> 
<html> 
<body> 

<video id="myVideo" width="320" height="176" onclick="playOrPause();" oncontextmenu="return false;" controls >
  <source src="https://www.w3schools.com/tags/mov_bbb.mp4" type="video/mp4">
  <source src="https://www.w3schools.com/tags/mov_bbb.ogg" type="video/ogg">
  Your browser does not support HTML5 video.
</video>
<div>
    
<input type="button" id="btnRewind" name="btnRewind" value="Rewind" onclick="rewindVideo();" />
<input type="button" id="btnPlay" name="btnPlay" value="Play" onclick="playVideo();" />
<input type="button" id="btnPause" name="btnPause" value="Pause" onclick="pauseVideo();" />
</div>

<script>
    var video = document.getElementById("myVideo");
    
    function playOrPause() {
        if (video.paused) {
            playVideo();
        } else {
            pauseVideo();
        }
    }
    
    function playVideo() {
        video.play();        
    }
    
    function pauseVideo() {
        video.pause();
    }
    
    function rewindVideo() {
        //video.currentTime -= 0.5;
        video.playBackRate = -2;
        video.play();
    }    

</script> 

<p>Video courtesy of <a href="https://www.bigbuckbunny.org/" target="_blank">Big Buck Bunny</a>.</p>

</body> 
</html>

有没有一种简单的方法可以从当前位置倒带视频?我想避免将整个库用于倒带功能。不过jQuery会很好。

4

1 回答 1

1

如何使用 JS 将“视频”元素倒带 2 秒

function Rewind() { 
var myVideo = document.getElementById("myVideo");
myVideo.currentTime = myVideo.currentTime -2; }

如何使用 JS 将“视频”元素快进 2 秒

function FastForward() { 
var myVideo = document.getElementById("myVideo");
myVideo.currentTime = myVideo.currentTime +2; }
于 2020-10-29T15:26:27.980 回答