Embed: mews: remove pause when tabbing out as doing so no longer seems to crash the browser

This commit is contained in:
Cat 2021-05-31 10:33:26 +02:00 committed by Thulinma
parent 8cd51e5e7d
commit 3cf0070121
2 changed files with 16 additions and 31 deletions

File diff suppressed because one or more lines are too long

View file

@ -768,7 +768,7 @@ p.prototype.build = function (MistVideo,callback) {
}, },
pause: function(){ pause: function(){
video.pause(); video.pause();
send({type: "hold",}); send({type: "hold"});
if (player.sb) { player.sb.paused = true; } if (player.sb) { player.sb.paused = true; }
}, },
setTracks: function(obj){ setTracks: function(obj){
@ -792,8 +792,6 @@ p.prototype.build = function (MistVideo,callback) {
} catch (e) { } } catch (e) { }
}); });
player.ws.close(); player.ws.close();
delete window.mistMewsOnVisibilityChange;
document.removeEventListener("visibilitychange",onVisibilityChange);
} }
}; };
@ -881,32 +879,6 @@ p.prototype.build = function (MistVideo,callback) {
}); });
} }
}); });
//pause if tab is hidden to prevent buildup of frames
var autopaused = false;
//only add this once!
function onVisibilityChange() {
if (document.hidden) {
//check if we are playing (not video.paused! that already returns true)
if (!player.sb.paused) {
player.api.pause();
autopaused = true;
if (MistVideo.info.type == "live") {
autopaused = "live"; //go to live point
//NB: even if the player wasn't near the live point when it was paused, we've likely exited the buffer while we were paused, so the current position probably won't exist anymore. Just skip to live.
}
MistVideo.log("Pausing the player as the tab is inactive.");
}
}
else if (autopaused) {
player.api.play(autopaused == "live");
autopaused = false;
MistVideo.log("Restarting the player as the tab is now active again.");
}
}
if (!window.mistMewsOnVisibilityChange) {
window.mistMewsOnVisibilityChange = true;
document.addEventListener("visibilitychange",onVisibilityChange);
}
var seeking = false; var seeking = false;
MistUtil.event.addListener(video,"seeking",function(){ MistUtil.event.addListener(video,"seeking",function(){
@ -927,6 +899,19 @@ p.prototype.build = function (MistVideo,callback) {
} }
} }
}); });
MistUtil.event.addListener(video,"pause",function(){
if (player.sb && !player.sb.paused) {
MistVideo.log("The browser paused the vid - probably because it has no audio and the tab is no longer visible. Pausing download.");
send({type:"hold"});
player.sb.paused = true;
var p = MistUtil.event.addListener(video,"play",function(){
if (player.sb && player.sb.paused) {
send({type:"play"});
}
MistUtil.event.removeListener(p);
});
}
});
if (player.debugging) { if (player.debugging) {
MistUtil.event.addListener(video,"waiting",function(){ MistUtil.event.addListener(video,"waiting",function(){