From ff09a7255ac03dfd7d828aaaf872b263c4c9cee4 Mon Sep 17 00:00:00 2001 From: Omar Roth Date: Mon, 28 Jan 2019 22:36:27 -0600 Subject: [PATCH] Add handling to remove invalid sources --- src/invidious/views/components/player.ecr | 39 +++++++++++++++++------ 1 file changed, 30 insertions(+), 9 deletions(-) diff --git a/src/invidious/views/components/player.ecr b/src/invidious/views/components/player.ecr index 66ee358b..80879b67 100644 --- a/src/invidious/views/components/player.ecr +++ b/src/invidious/views/components/player.ecr @@ -115,17 +115,38 @@ var player = videojs("player", options, function() { }); player.on('error', function(event) { - console.log("An error occured in the player, reloading..."); + if (player.error().code === 2) { + console.log("An error occured in the player, reloading..."); - var currentTime = player.currentTime(); - var playbackRate = player.playbackRate() - player.load(); - if (currentTime > 0.5) { - currentTime -= 0.5; + var currentTime = player.currentTime(); + var playbackRate = player.playbackRate(); + player.load(); + if (currentTime > 0.5) { + currentTime -= 0.5; + } + player.currentTime(currentTime); + player.playbackRate(playbackRate); + player.play() + } else if (player.error().code === 4) { + console.log("Detected invalid source, removing..."); + var currentTime = player.currentTime(); + var sources = player.options().sources; + + for (var i = 0; i < sources.length; i++) { + if (sources[i].src === player.currentSource().src) { + sources.splice(i, 1); + break + } + }; + + player.load(); + if (currentTime > 0.5) { + currentTime -= 0.5; + } + player.currentTime(currentTime); + player.src(sources); + player.play(); } - player.currentTime(currentTime); - player.playbackRate(playbackRate); - player.play() }); player.share(shareOptions);