Some videojs API functions seem to fail
Adriaan-E opened this issue · comments
By using the videojs-youtube plugin, it seems that some videojs api functions are not working anymore as expected or i should say are not returning the expected values.
For example, player.duration() always returns 0 (zero), setinterval, updateontime and loadedmetadata are also not triggering anymore. Can be understandable as youtube is not native but hope anyone can tell me a workaround to get this working again?
Cheers!
@Adriaan-E ... this is a terrible workaround and I don't recommend it to anyone, but we implemented it... as it was the only way. What's really interesting is that even when you force the video to play(), and timeupdate is listening, it will still return 0 duration for a second or so. After that it's picked up successfully.
Pending your use case context this may be acceptable.
if(data.video.duration == 0 || data.video.duration == null){
videoPlayer.on('loadedmetadata', function () {
data.video.duration = Math.floor(videoPlayer.duration());
console.log('getDuration loadedmetadata -- ' + data.video.duration);
if(data.video.duration == 0) {
videoPlayer.on('timeupdate', function () {
console.log('getDuration timeupdate -- ' + data.video.duration);
if (data.video.duration > 0 ) {
videoPlayer.off('timeupdate');
videoPlayer.currentTime(0);
videoPlayer.pause();
data.updateVideo(data.video, User);
}
$scope.$apply(function () {
data.video.duration = Math.floor(videoPlayer.duration());
});
});
videoPlayer.play();
}
});
}
What version of videojs and videojs-youtube are you using? It seems to be working for me just fine. At least with #411 applied which fixes issues with videojs-youtube and videojs 5.12.
I believe it's fixed now in 2.2.0.
It's still 0 (or NaN) with video.js 6.2.7 and videojs-youtube 2.4.0
https://codepen.io/bencergazda/pen/VzqxVX
I mean, is/should it be possible to get the video duration before the video gets started?