Embed: mews: after a track switch, always do overzealous seeking even if the codecs are the same
This commit is contained in:
parent
22e720c9d1
commit
a1ffc383cb
2 changed files with 42 additions and 42 deletions
File diff suppressed because one or more lines are too long
|
@ -618,67 +618,21 @@ p.prototype.build = function (MistVideo,callback) {
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
function setSeekingPosition(t) {
|
||||||
|
var currPos = video.currentTime.toFixed(3);
|
||||||
if (checkEqual(player.last_codecs ? player.last_codecs : player.sb._codecs,msg.data.codecs)) {
|
|
||||||
MistVideo.log("Player switched tracks, keeping source buffer as codecs are the same as before.");
|
|
||||||
if ((video.currentTime == 0) && (msg.data.current != 0)) {
|
|
||||||
video.currentTime = msg.data.current;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
if (player.debugging) {
|
|
||||||
console.warn("Different codecs!");
|
|
||||||
console.warn("video time",video.currentTime,"switch startpoint",msg.data.current*1e-3);
|
|
||||||
}
|
|
||||||
player.last_codecs = msg.data.codecs;
|
|
||||||
//start gathering messages in a new msg queue. They won't be appended to the current source buffer
|
|
||||||
if (player.msgqueue) {
|
|
||||||
player.msgqueue.push([]);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
player.msgqueue = [[]];
|
|
||||||
}
|
|
||||||
//play out buffer, then when we reach the starting timestamp of the new data, reset the source buffers
|
|
||||||
var clear = function(){
|
|
||||||
//once the source buffer is done updating the current segment, clear the specified interval from the buffer
|
|
||||||
currPos = video.currentTime.toFixed(3);
|
|
||||||
if (player && player.sb) {
|
|
||||||
player.sb._do(function(remaining_do_on_updateend){
|
|
||||||
if (!player.sb.updating) {
|
|
||||||
if (!isNaN(player.ms.duration)) player.sb.remove(0,Infinity);
|
|
||||||
player.sb.queue = [];
|
|
||||||
player.ms.removeSourceBuffer(player.sb);
|
|
||||||
player.sb = null;
|
|
||||||
var t = (msg.data.current*1e-3).toFixed(3); //rounded because of floating point issues
|
|
||||||
video.src = "";
|
|
||||||
player.ms.onsourceclose = null;
|
|
||||||
player.ms.onsourceended = null;
|
|
||||||
//console.log("sb murdered");
|
|
||||||
if (player.debugging && remaining_do_on_updateend && remaining_do_on_updateend.length) {
|
|
||||||
console.warn("There are do_on_updateend functions queued, which I will re-apply after clearing the sb.");
|
|
||||||
}
|
|
||||||
|
|
||||||
player.msinit().then(function(){
|
|
||||||
player.sbinit(msg.data.codecs);
|
|
||||||
player.sb.do_on_updateend = remaining_do_on_updateend;
|
|
||||||
|
|
||||||
var e = MistUtil.event.addListener(video,"loadedmetadata",function(){
|
|
||||||
MistVideo.log("Buffer cleared");
|
|
||||||
|
|
||||||
var f = function() {
|
|
||||||
if (currPos > t) {
|
if (currPos > t) {
|
||||||
|
//don't seek backwards
|
||||||
t = currPos;
|
t = currPos;
|
||||||
}
|
}
|
||||||
if (!video.buffered.length || (video.buffered.end(video.buffered.length-1) < t)) {
|
if (!video.buffered.length || (video.buffered.end(video.buffered.length-1) < t)) {
|
||||||
if (player.debugging) { console.log("Desired seeking position ("+MistUtil.format.time(t,{ms:true})+") not yet in buffer ("+(video.buffered.length ? MistUtil.format.time(video.buffered.end(video.buffered.length-1),{ms:true}) : "null")+")"); }
|
if (player.debugging) { console.log("Desired seeking position ("+MistUtil.format.time(t,{ms:true})+") not yet in buffer ("+(video.buffered.length ? MistUtil.format.time(video.buffered.end(video.buffered.length-1),{ms:true}) : "null")+")"); }
|
||||||
player.sb._doNext(f);
|
player.sb._doNext(function(){ setSeekingPosition(t); });
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
video.currentTime = t;
|
video.currentTime = t;
|
||||||
MistVideo.log("Setting playback position to "+MistUtil.format.time(t,{ms:true}));
|
MistVideo.log("Setting playback position to "+MistUtil.format.time(t,{ms:true}));
|
||||||
if (video.currentTime.toFixed(3) < t) {
|
if (video.currentTime.toFixed(3) < t) {
|
||||||
player.sb._doNext(f);
|
player.sb._doNext(function(){ setSeekingPosition(t); });
|
||||||
if (player.debugging) { console.log("Could not set playback position"); }
|
if (player.debugging) { console.log("Could not set playback position"); }
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
@ -703,7 +657,53 @@ p.prototype.build = function (MistVideo,callback) {
|
||||||
p();
|
p();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
f();
|
|
||||||
|
|
||||||
|
if (checkEqual(player.last_codecs ? player.last_codecs : player.sb._codecs,msg.data.codecs)) {
|
||||||
|
MistVideo.log("Player switched tracks, keeping source buffer as codecs are the same as before.");
|
||||||
|
if ((video.currentTime == 0) && (msg.data.current != 0)) {
|
||||||
|
setSeekingPosition((msg.data.current*1e-3).toFixed(3));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
if (player.debugging) {
|
||||||
|
console.warn("Different codecs!");
|
||||||
|
console.warn("video time",video.currentTime,"switch startpoint",msg.data.current*1e-3);
|
||||||
|
}
|
||||||
|
player.last_codecs = msg.data.codecs;
|
||||||
|
//start gathering messages in a new msg queue. They won't be appended to the current source buffer
|
||||||
|
if (player.msgqueue) {
|
||||||
|
player.msgqueue.push([]);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
player.msgqueue = [[]];
|
||||||
|
}
|
||||||
|
//play out buffer, then when we reach the starting timestamp of the new data, reset the source buffers
|
||||||
|
var clear = function(){
|
||||||
|
//once the source buffer is done updating the current segment, clear the specified interval from the buffer
|
||||||
|
if (player && player.sb) {
|
||||||
|
player.sb._do(function(remaining_do_on_updateend){
|
||||||
|
if (!player.sb.updating) {
|
||||||
|
if (!isNaN(player.ms.duration)) player.sb.remove(0,Infinity);
|
||||||
|
player.sb.queue = [];
|
||||||
|
player.ms.removeSourceBuffer(player.sb);
|
||||||
|
player.sb = null;
|
||||||
|
video.src = "";
|
||||||
|
player.ms.onsourceclose = null;
|
||||||
|
player.ms.onsourceended = null;
|
||||||
|
//console.log("sb murdered");
|
||||||
|
if (player.debugging && remaining_do_on_updateend && remaining_do_on_updateend.length) {
|
||||||
|
console.warn("There are do_on_updateend functions queued, which I will re-apply after clearing the sb.");
|
||||||
|
}
|
||||||
|
|
||||||
|
player.msinit().then(function(){
|
||||||
|
player.sbinit(msg.data.codecs);
|
||||||
|
player.sb.do_on_updateend = remaining_do_on_updateend;
|
||||||
|
|
||||||
|
var e = MistUtil.event.addListener(video,"loadedmetadata",function(){
|
||||||
|
MistVideo.log("Buffer cleared");
|
||||||
|
|
||||||
|
setSeekingPosition((msg.data.current*1e-3).toFixed(3));
|
||||||
|
|
||||||
MistUtil.event.removeListener(e);
|
MistUtil.event.removeListener(e);
|
||||||
});
|
});
|
||||||
|
|
Loading…
Add table
Reference in a new issue