I've been trying to figure out a simple way to use pseudo-streaming, and have javascript tell the video to start playing at a certain offset (in seconds). Unfortunately, the Player.seek() call only seems to work when the player is paused or playing...
So for the moment, I've come up with this horrendously ugly hack:
Basically if the video is not yet loaded, I have to tell it to load, catch when the metadata is loaded with onStart(), and then tell it to pause so I can seek. However, then I have to poll for when the pause actually happens/finishes, so I can do the seek... And finally I can tell it to play.
Is there something I've missed in the API that would make this simpler? If not, maybe a Player.playAt(seconds) call could be added, or something?
So for the moment, I've come up with this horrendously ugly hack:
function seekVideo(seconds) {
var p = $f();
if (p.isLoaded()) {
p.seek(seconds);
if (!p.isPlaying()) p.play();
} else {
var c = p.getClip(0);
var initialLoad = true;
var seekInterval = null;
if (c) c.update({ autoPlay: false, autoBuffering: true });
p.onStart(function () {
if (initialLoad) {
initialLoad = false;
p.pause();
seekInterval = window.setInterval(function() {
if (p.isPaused()) {
window.clearInterval(seekInterval);
p.seek(seconds);
p.play();
}
}, 10)
}
});
p.load();
}
}
Basically if the video is not yet loaded, I have to tell it to load, catch when the metadata is loaded with onStart(), and then tell it to pause so I can seek. However, then I have to poll for when the pause actually happens/finishes, so I can do the seek... And finally I can tell it to play.
Is there something I've missed in the API that would make this simpler? If not, maybe a Player.playAt(seconds) call could be added, or something?