How to stop (not pause) html5 video with jQuery
You can stop it with pause and currentTime.
var media = $("#video-id").get(0);
media.pause();
media.currentTime = 0;
Check this out: https://developer.mozilla.org/en-US/docs/Learn/JavaScript/Client-side_web_APIs/Video_and_audio_APIs
There is no .stop()
. You just can pause it...
But you also can set the currentTime
back to zero (begining of the file)...
That will be nice to have it ready to play again on subsequent #playButton
click.
That would be:
$('#playButton').click(function(event){
$('#theVideo').get(0).play();
setTimeout(function(){
$('#theVideo').get(0).pause();
$('#theVideo').get(0).currentTime = 0;
}, 7000);
});
Now, «If a user visits the page and navigates back»... Holà!! Using the browser's back button? Nothing you can do here. The JavaScript is not ran like a normal page load here. Nothing can happen "on back".