Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

HTML5 Video / End of a Video Poster

Tags:

html

video

<video controls="controls" poster="http://gifs.gifbin.com/1233925271_8be9acc.gif" style="width:800px;">

With the above; within the HTML5 <video> tag, I can add a poster; of an image or animated .gif just fine and plays / runs before the actual video is 'played'.

NOW, how can I add an image; specifically a .gif (animated .gif works with poster) that will run AFTER the video has played through?

like image 257
fred randall Avatar asked Jan 09 '13 20:01

fred randall


People also ask

How do I show a video poster in HTML?

The HTML <video> poster Attribute is used to display the image while video downloading or when user click the play button. If this image not set then it will take the first frame of video as a poster image. Attribute Values: It contains a single value URL which specifies the link of source image.

How do you add a thumbnail to a video in HTML?

Approach: Sometimes the user wants to display a specific image of his choice as the thumbnail of the video. This can be simply done by using the poster attribute. All you have to do is create a poster attribute in the video tag and place the URL of the thumbnail image in it.

How do I put a video into a poster?

The poster attribute specifies an image to be shown while the video is downloading, or until the user hits the play button. If this is not included, the first frame of the video will be used instead.


2 Answers

A straightforward way of doing this:

<script>
var video = document.querySelector('video');       
video.addEventListener('ended', function() {
  video.load();     
});
</script>

Indeed when changing the src of a video tag you implicitly call a load() on it.

This method has the caveat to request the media URL again and depending on caching settings it may re-download the full-length media resource causing unnecessary network/CPU usage for the client.

A more appropriate way to solve this issue is to use an overlay image/div on top the video tag and to hide it when video starts. When the ended event fires just show the overlay image again.

like image 165
Arnaud Leyder Avatar answered Oct 21 '22 12:10

Arnaud Leyder


This is what I ended up doing to see a poster after the video finished playing:

# Show poster at the end of the video
$('video').on('ended',->
  $('video')[0].autoplay=false
  $('video')[0].load()
)
like image 12
Hackeron Avatar answered Oct 21 '22 13:10

Hackeron