Setting currentTime on 'loadedmetadata' event doesn't work properly on flash
Description
I want to start video from some position. For this purpose I'm using player.currentTime(myTime) on 'loadedmetadata' event. But after that on 'timeupdate' event player.currentTime() === 'myTime' and video plays from the 0. Video should play from my time position and on 'timeupdate' event player.currentTime() should be equal correct time position.
Steps to reproduce
- use flash player
- add listener to 'loadedmetadata' with player.currentTime(yourTime)
- add listener to 'timeupdate' and log player.currentTime() ... PROFIT!!!
versions
videojs
videojs swf 5.1.0 video.js 5.11.0
browsers
chrome
OSes
ubuntu
Does it work better if you use canplay event instead?
Yes, canplay event works. Thank you.
I think, it would be good to document it.
I was having issues with this also. I am using the HTML5 version though. I was using video.js 5.11.0 and I could not get loadedmetadata or canplay working. I was using preload="none", so I had to hit play before the loadedmetadata event fired.
I tried updating to 5.12.1 to see if anything was different and it was not. I was able to get loadmetadata to work by adding a setTimeout. When I hit play, with the code below the loadedmetadata fires, and you cannot notice any play or pauses in the playback when i hit play, just looks like it meant to start playing at the 90 second mark.
I commented on what worked and what did not work in the code below. Thought on how to improve this code. I dont think timeouts is the right way to go.
player.on('loadedmetadata', function(){
console.log('inside example_video_1 is loadedmetadata');
//works
setTimeout(function() { player.play(); }, 100);
setTimeout(function() { player.pause(); }, 200);
setTimeout(function() { player.currentTime(90); }, 300);
setTimeout(function() { player.play(); }, 400);
//does not work
//player.play();
//player.pause();
//player.currentTime(90);
//player.play();
//does not work
//setTimeout(function() { player.pause(); }, 100);
//setTimeout(function() { player.currentTime(90); }, 200);
//setTimeout(function() { player.play(); }, 300);
});
Looks like this issue might be similar to #3099 and #3622.
Try this:
player.on("ready", function () {
this.on('loadedmetadata', function () {
// it all should work here
});
});
Given that Adobe Flash is being end-of-lifed this month we will no longer be working on flash related features.