Embed: videojs: fixes to get a consistent timestamp with other players

This commit is contained in:
Cat 2022-01-26 14:21:58 +01:00 committed by Thulinma
parent 48260e6bc5
commit 31c5b81f4d
2 changed files with 44 additions and 43 deletions

File diff suppressed because one or more lines are too long

View file

@ -193,26 +193,23 @@ p.prototype.build = function (MistVideo,callback) {
//MistVideo.video.currentTime = value; //MistVideo.video.currentTime = value;
}; };
if (MistVideo.info.type == "live") { //get first and lastms
var lastms = 0;
function getLastBuffer(video) { var firstms = Infinity;
var buffer_end = 0; for (var i in MistVideo.info.meta.tracks) {
if (video.buffered.length) { lastms = Math.max(lastms,MistVideo.info.meta.tracks[i].lastms);
buffer_end = video.buffered.end(video.buffered.length-1) firstms = Math.min(firstms,MistVideo.info.meta.tracks[i].firstms);
} }
return buffer_end; //correct the currentTime timestamp
} var correction = firstms*1e-3;
var HLSlatency = 0; //best guess..
overrides.get.duration = function(){ overrides.get.duration = function(){
if (MistVideo.info) { if (MistVideo.info) {
var duration = ele.duration; var duration = ele.duration;
return duration; return duration + correction;
} }
return 0; return 0;
}; };
MistVideo.player.api.lastProgress = new Date();
MistVideo.player.api.liveOffset = 0;
MistUtil.event.addListener(ele,"progress",function(){ MistUtil.event.addListener(ele,"progress",function(){
MistVideo.player.api.lastProgress = new Date(); MistVideo.player.api.lastProgress = new Date();
@ -224,21 +221,25 @@ p.prototype.build = function (MistVideo,callback) {
MistVideo.log("Seeking to "+MistUtil.format.time(value)+" ("+Math.round(offset*-10)/10+"s from live)"); MistVideo.log("Seeking to "+MistUtil.format.time(value)+" ("+Math.round(offset*-10)/10+"s from live)");
MistVideo.player.videojs.currentTime(MistVideo.video.currentTime - diff); MistVideo.player.videojs.currentTime(MistVideo.video.currentTime - diff);
} }
var lastms = 0;
overrides.get.currentTime = function(){ overrides.get.currentTime = function(){
if (MistVideo.info) { lastms = MistVideo.info.lastms*1e-3; }
var time = MistVideo.player.videojs ? MistVideo.player.videojs.currentTime() : ele.currentTime; var time = MistVideo.player.videojs ? MistVideo.player.videojs.currentTime() : ele.currentTime;
if (isNaN(time)) { return 0; } if (isNaN(time)) { return 0; }
return time; return time + correction;
} }
overrides.get.buffered = function(){ overrides.get.buffered = function(){
var buffered = MistVideo.player.videojs ? MistVideo.player.videojs.buffered() : ele.buffered; var buffered = MistVideo.player.videojs ? MistVideo.player.videojs.buffered() : ele.buffered;
return { return {
length: buffered.length, length: buffered.length,
start: function(i) { return buffered.start(i); }, start: function(i) { return buffered.start(i) + correction; },
end: function(i) { return buffered.end(i); i} end: function(i) { return buffered.end(i) + correction; }
} }
}; };
if (MistVideo.info.type == "live") {
MistVideo.player.api.lastProgress = new Date();
MistVideo.player.api.liveOffset = 0;
} }
} }
else { else {