C'è un modo semplice per riavvolgere un elemento video HTML con javascript / jquery? [duplicare]
Oct 29 2020
Ho un video che devo mostrare su un sito web. Non posso consentire all'utente di farlo avanzare rapidamente, ma deve essere in grado di riavvolgerlo. Ho modificato l'esempio qui:https://www.w3schools.com/tags/tryit.asp?filename=tryhtml5_av_prop_controller
a quanto segue:
<!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>
C'è un modo semplice per riavvolgere il video dalla posizione corrente? Vorrei evitare di utilizzare un'intera libreria per una funzione di riavvolgimento. jQuery andrebbe bene però.
Risposte
חִידָה Oct 29 2020 at 15:26
Come riavvolgere un elemento "video" di 2 secondi con JS :
function Rewind() {
var myVideo = document.getElementById("myVideo");
myVideo.currentTime = myVideo.currentTime -2; }
Come far avanzare rapidamente un elemento "video" di 2 secondi con JS :
function FastForward() {
var myVideo = document.getElementById("myVideo");
myVideo.currentTime = myVideo.currentTime +2; }