Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Javascript stop and return to poster HTML 5 video

This is my javascript which pause and play the HTML 5 video when a button is pressed but I want to stop the video instead of pausing and returning to the video poster how can I achieve that?

function vidplay() {
    var video = document.getElementById("bg-vid");
    var button = document.getElementById("play");
    if (video.paused) {
        video.play();
    } else {
        video.pause();
    }
}
like image 281
Hannes Brolin Lagerstedt Avatar asked May 10 '26 23:05

Hannes Brolin Lagerstedt


1 Answers

Use load() method (although I believe changing the src attribute implicitly calls it):

...
if (video.paused) {
  video.play()
} else {
  load();
}
...

Note: this method re-loads the resource, thus depending on caching settings it may be re-downloaded causing unnecessary bandwidth and CPU usage.

like image 159
Igor Gilyazov Avatar answered May 12 '26 14:05

Igor Gilyazov



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!