user967451
user967451

Reputation:

How to detect when a HTML5 <video> is played for the first time?

This will fire the alert each time the play button is clicked. So it will be fired the first time the video is played but also on subsequent plays and if the user pauses then then plays again:

$('video').bind('play', function() {
   alert('I have been played!');
});

I need to fire an event only once when the video is played for the first time. How can this be done?

Perhaps the jquery one function can be combined with this to make it happen?

Upvotes: 5

Views: 3951

Answers (2)

Thiyagu
Thiyagu

Reputation: 31

$(document).ready(function(){
   $('#video_id').one('play', function () {
       //code here
    });
});

Upvotes: 0

Explosion Pills
Explosion Pills

Reputation: 191749

$('video').one('play', function () {
   //whatever you want to do
});

Upvotes: 14

Related Questions