LonnyGomes / vjs-video

An angular js directive for video.js
http://lonnygomes.github.io/vjs-video/
MIT License
75 stars 33 forks source link

How to check the play status? #41

Open plutarcociceron opened 8 years ago

plutarcociceron commented 8 years ago

Hi, is there a way how check if the player is paused or not? Something like this? $scope.$watch('vjsVideoIsPlaying', function(oldVal, newVal) { if (oldVal) { console.log('old: ', oldVal); } });

ghost commented 8 years ago

@plutarcociceron currently the way to do what you're looking for is to get a reference to the player once it is ready. In a future update the plan is to have an angular service handle this type of logic but you to check play status for videos something like the following could work:

var videos = {};
$scope.$on('vjsVideoReady', function (e, data) {
    videos[data.id] = data.player;

    videos[data.id].on('play', function (e) {
        console.log('video is playing:' + this.id());
    });
});

This stores all videos on a page in an object and adds a listener for play.

If at some later time you wanted to see if the a video with an id of example_vid was paused you could do the following:

if (videos['example_vid'].paused()) {
    console.log('video is paused');
}

Let me know if that makes sense or if you have suggestions on making this easier to deal with.