Embed: - fixed timer issue causing player to reload after an unload

- added version numbering
This commit is contained in:
Cat 2017-03-13 13:32:00 +01:00 committed by Thulinma
parent 27b85e76d3
commit b6486878ca
13 changed files with 38 additions and 11 deletions

View file

@ -42,7 +42,7 @@ MistPlayer.prototype.build = function () {
} }
MistPlayer.prototype.timer = { MistPlayer.prototype.timer = {
timers: {}, timers: {},
add: function(callback,delay){ add: function(callback,delay,isInterval){
var me = this; var me = this;
var i = setTimeout(function(){ var i = setTimeout(function(){
delete me.timers[i]; delete me.timers[i];
@ -50,19 +50,24 @@ MistPlayer.prototype.timer = {
},delay); },delay);
this.timers[i] = { this.timers[i] = {
delay: delay, delay: delay,
callback: callback callback: callback,
interval: isInterval || false
}; };
return i; return i;
}, },
remove: function(i){ remove: function(i){
clearTimeout(i); if (this.timers[i].interval) {
clearInterval(i);
}
else {
clearTimeout(i);
}
delete this.timers[i]; delete this.timers[i];
}, },
clear: function(){ clear: function(){
for (var i in this.timers) { for (var i in this.timers) {
clearTimeout(i); this.remove(i);
} }
this.timers = {};
} }
}; };
@ -688,6 +693,7 @@ MistPlayer.prototype.askNextCombo = function(msg){
button.appendChild(t); button.appendChild(t);
err.appendChild(button); err.appendChild(button);
button.onclick = function(){ button.onclick = function(){
me.addlog('Reloading player because the reload button was triggered');
me.reload(); me.reload();
} }
@ -697,6 +703,7 @@ MistPlayer.prototype.askNextCombo = function(msg){
type: 'playback', type: 'playback',
warn: 'Automatically reloaded the current player after playback error' warn: 'Automatically reloaded the current player after playback error'
}); });
me.addlog('Triggering reload button because of timeout');
button.click(); button.click();
},20e3); },20e3);
@ -785,6 +792,7 @@ MistPlayer.prototype.unload = function(){
} }
this.timer.clear(); this.timer.clear();
this.target.innerHTML = ''; this.target.innerHTML = '';
this.element.innerHTML = '';
}; };
function mistCheck(streaminfo,options,embedLog) { function mistCheck(streaminfo,options,embedLog) {
@ -1244,7 +1252,7 @@ function mistPlay(streamName,options) {
if ((!element.checkProgressTimeout) && (player.element) && ('currentTime' in player.element)) { if ((!element.checkProgressTimeout) && (player.element) && ('currentTime' in player.element)) {
//check if the progress made is equal to the time spent //check if the progress made is equal to the time spent
var lasttime = player.element.currentTime; var lasttime = player.element.currentTime;
element.checkProgressTimeout = setInterval(function(){ element.checkProgressTimeout = player.timer.add(function(){
var newtime = player.element.currentTime; var newtime = player.element.currentTime;
var progress = newtime - lasttime; var progress = newtime - lasttime;
lasttime = newtime; lasttime = newtime;
@ -1279,13 +1287,13 @@ function mistPlay(streamName,options) {
}); });
return; return;
} }
},30e3); },30e3,true);
} }
},true); },true);
element.addEventListener('pause',function(){ element.addEventListener('pause',function(){
player.paused = true; player.paused = true;
if (element.checkProgressTimeout) { if (element.checkProgressTimeout) {
clearInterval(element.checkProgressTimeout); player.timer.remove(element.checkProgressTimeout);
element.checkProgressTimeout = false; element.checkProgressTimeout = false;
} }
},true); },true);

View file

@ -1,5 +1,6 @@
mistplayers.dashjs = { mistplayers.dashjs = {
name: 'Dash.js Player', name: 'Dash.js Player',
version: '1.1',
mimes: ['dash/video/mp4'], mimes: ['dash/video/mp4'],
priority: Object.keys(mistplayers).length + 1, priority: Object.keys(mistplayers).length + 1,
isMimeSupported: function (mimetype) { isMimeSupported: function (mimetype) {
@ -131,3 +132,11 @@ p.prototype.resize = function(size){
this.element.width = size.width; this.element.width = size.width;
this.element.height = size.height; this.element.height = size.height;
}; };
p.prototype.updateSrc = function(src){
if (src == '') {
this.dash.reset();
return;
}
this.dash.attachSource(src);
return true;
};

View file

@ -1,5 +1,6 @@
mistplayers.flash_strobe = { mistplayers.flash_strobe = {
name: 'Strobe Flash Media Playback', name: 'Strobe Flash Media Playback',
version: '1.0',
mimes: ['flash/10','flash/11','flash/7'], mimes: ['flash/10','flash/11','flash/7'],
priority: Object.keys(mistplayers).length + 1, priority: Object.keys(mistplayers).length + 1,
isMimeSupported: function (mimetype) { isMimeSupported: function (mimetype) {

View file

@ -1,5 +1,6 @@
mistplayers.html5 = { mistplayers.html5 = {
name: 'HTML5 video player', name: 'HTML5 video player',
version: '1.0',
mimes: ['html5/application/vnd.apple.mpegurl','html5/video/mp4','html5/video/ogg','html5/video/webm','html5/audio/mp3','html5/audio/webm','html5/audio/ogg','html5/audio/wav'], mimes: ['html5/application/vnd.apple.mpegurl','html5/video/mp4','html5/video/ogg','html5/video/webm','html5/audio/mp3','html5/audio/webm','html5/audio/ogg','html5/audio/wav'],
priority: Object.keys(mistplayers).length + 1, priority: Object.keys(mistplayers).length + 1,
isMimeSupported: function (mimetype) { isMimeSupported: function (mimetype) {

View file

@ -1,5 +1,6 @@
mistplayers.img = { mistplayers.img = {
name: 'HTML img tag', name: 'HTML img tag',
version: '1.0',
mimes: ['html5/image/jpeg'], mimes: ['html5/image/jpeg'],
priority: Object.keys(mistplayers).length + 1, priority: Object.keys(mistplayers).length + 1,
isMimeSupported: function (mimetype) { isMimeSupported: function (mimetype) {

View file

@ -1,5 +1,6 @@
mistplayers.jwplayer = { mistplayers.jwplayer = {
name: 'JWPlayer', name: 'JWPlayer',
version: '0.1',
mimes: ['html5/video/mp4','html5/video/webm','dash/video/mp4','flash/10','flash/7','html5/application/vnd.apple.mpegurl','html5/audio/mp3','html5/audio/aac'], mimes: ['html5/video/mp4','html5/video/webm','dash/video/mp4','flash/10','flash/7','html5/application/vnd.apple.mpegurl','html5/audio/mp3','html5/audio/aac'],
priority: Object.keys(mistplayers).length + 1, priority: Object.keys(mistplayers).length + 1,
isMimeSupported: function (mimetype) { isMimeSupported: function (mimetype) {

View file

@ -1,5 +1,6 @@
mistplayers.polytrope = { mistplayers.polytrope = {
name: 'Polytrope Flash Player', name: 'Polytrope Flash Player',
version: '0.1',
mimes: ['flash/11','flash/10','flash/7'], mimes: ['flash/11','flash/10','flash/7'],
priority: Object.keys(mistplayers).length + 1, priority: Object.keys(mistplayers).length + 1,
isMimeSupported: function (mimetype) { isMimeSupported: function (mimetype) {

View file

@ -1,5 +1,6 @@
mistplayers.silverlight = { mistplayers.silverlight = {
name: 'Silverlight', name: 'Silverlight',
version: '1.0',
mimes: ['silverlight'], mimes: ['silverlight'],
priority: Object.keys(mistplayers).length + 1, priority: Object.keys(mistplayers).length + 1,
isMimeSupported: function (mimetype) { isMimeSupported: function (mimetype) {

View file

@ -1,5 +1,6 @@
mistplayers.myplayer = { mistplayers.myplayer = {
name: 'My video player', name: 'My video player',
version: '0.1',
mimes: ['my/mime/types'], mimes: ['my/mime/types'],
priority: Object.keys(mistplayers).length + 1, priority: Object.keys(mistplayers).length + 1,
isMimeSupported: function (mimetype) { isMimeSupported: function (mimetype) {

View file

@ -1,5 +1,6 @@
mistplayers.theoplayer = { mistplayers.theoplayer = {
name: 'TheoPlayer', name: 'TheoPlayer',
version: '0.1',
mimes: ['html5/application/vnd.apple.mpegurl','dash/video/mp4'], mimes: ['html5/application/vnd.apple.mpegurl','dash/video/mp4'],
priority: Object.keys(mistplayers).length + 1, priority: Object.keys(mistplayers).length + 1,
isMimeSupported: function (mimetype) { isMimeSupported: function (mimetype) {

View file

@ -1,5 +1,6 @@
mistplayers.videojs = { mistplayers.videojs = {
name: 'VideoJS player', name: 'VideoJS player',
version: '1.0',
mimes: ['html5/video/mp4','html5/application/vnd.apple.mpegurl','html5/video/ogg','html5/video/webm'], mimes: ['html5/video/mp4','html5/application/vnd.apple.mpegurl','html5/video/ogg','html5/video/webm'],
priority: Object.keys(mistplayers).length + 1, priority: Object.keys(mistplayers).length + 1,
isMimeSupported: function (mimetype) { isMimeSupported: function (mimetype) {

View file

@ -67,9 +67,9 @@ top:a,left:d,right:"auto",bottom:"auto"})});a.parent().on("dragleave",function()
"days, ")).append(UI.format.addUnit(d.hr,"hrs"));break;default:b.append([("0"+d.hr).slice(-2),("0"+d.min).slice(-2),("0"+d.sec).slice(-2)+(d.ms?"."+d.ms:"")].join(":"))}return b[0].innerHTML},number:function(a){if(isNaN(Number(a))||0==a)return a;var b=Math.pow(10,3-Math.floor(Math.log(a)/Math.LN10)-1),a=Math.round(a*b)/b;if(1E4<a){number=a.toString().split(".");for(a=/(\d+)(\d{3})/;a.test(number[0]);)number[0]=number[0].replace(a,"$1 $2");a=number.join(".")}return a},status:function(a){var b=$("<span>"); "days, ")).append(UI.format.addUnit(d.hr,"hrs"));break;default:b.append([("0"+d.hr).slice(-2),("0"+d.min).slice(-2),("0"+d.sec).slice(-2)+(d.ms?"."+d.ms:"")].join(":"))}return b[0].innerHTML},number:function(a){if(isNaN(Number(a))||0==a)return a;var b=Math.pow(10,3-Math.floor(Math.log(a)/Math.LN10)-1),a=Math.round(a*b)/b;if(1E4<a){number=a.toString().split(".");for(a=/(\d+)(\d{3})/;a.test(number[0]);)number[0]=number[0].replace(a,"$1 $2");a=number.join(".")}return a},status:function(a){var b=$("<span>");
if("undefined"==typeof a.online)return b.text("Unknown, checking.."),"undefined"!=typeof a.error&&b.text(a.error),b;switch(a.online){case -1:b.text("Enabling");break;case 0:b.text("Unavailable").addClass("red");break;case 1:b.text("Active").addClass("green");break;case 2:b.text("Standby").addClass("orange");break;default:b.text(a.online)}"error"in a&&b.text(a.error);return b},capital:function(a){return a.charAt(0).toUpperCase()+a.substring(1)},addUnit:function(a,b){var c=$("<span>").html(a);c.append($("<span>").addClass("unit").html(b)); if("undefined"==typeof a.online)return b.text("Unknown, checking.."),"undefined"!=typeof a.error&&b.text(a.error),b;switch(a.online){case -1:b.text("Enabling");break;case 0:b.text("Unavailable").addClass("red");break;case 1:b.text("Active").addClass("green");break;case 2:b.text("Standby").addClass("orange");break;default:b.text(a.online)}"error"in a&&b.text(a.error);return b},capital:function(a){return a.charAt(0).toUpperCase()+a.substring(1)},addUnit:function(a,b){var c=$("<span>").html(a);c.append($("<span>").addClass("unit").html(b));
return c[0].innerHTML},bytes:function(a,b){var c="bytes KiB MiB GiB TiB PiB".split(" ");if(0==a)unit=c[0];else{var d=Math.floor(Math.log(Math.abs(a))/Math.log(1024));0>d?unit=c[0]:(a/=Math.pow(1024,d),unit=c[d])}return UI.format.addUnit(UI.format.number(a),unit+(b?"/s":""))}},navto:function(a,b){var c=location.hash,d=c.split("@");d[0]=[mist.user.name,mist.user.host].join("&");d[1]=[a,b].join("&");"undefined"!=typeof screenlog&&screenlog.navto(d[1]);location.hash=d.join("@");location.hash==c&&$(window).trigger("hashchange")}, return c[0].innerHTML},bytes:function(a,b){var c="bytes KiB MiB GiB TiB PiB".split(" ");if(0==a)unit=c[0];else{var d=Math.floor(Math.log(Math.abs(a))/Math.log(1024));0>d?unit=c[0]:(a/=Math.pow(1024,d),unit=c[d])}return UI.format.addUnit(UI.format.number(a),unit+(b?"/s":""))}},navto:function(a,b){var c=location.hash,d=c.split("@");d[0]=[mist.user.name,mist.user.host].join("&");d[1]=[a,b].join("&");"undefined"!=typeof screenlog&&screenlog.navto(d[1]);location.hash=d.join("@");location.hash==c&&$(window).trigger("hashchange")},
showTab:function(a,b){var c=UI.elements.main;if(mist.user.loggedin&&!("ui_settings"in mist.data))c.html("Loading.."),mist.send(function(){UI.showTab(a,b)},{ui_settings:!0});else{var d=UI.elements.menu.removeClass("hide").find('.plain:contains("'+a+'")').closest(".button");0<d.length&&(UI.elements.menu.find(".button.active").removeClass("active"),d.addClass("active"));if("undefined"!=typeof mistvideo)for(var e in mistvideo)if("embedded"in mistvideo[e])for(var g in mistvideo[e].embedded)try{mistvideo[e].embedded[g].player.unload()}catch(m){}UI.interval.clear(); showTab:function(a,b){var c=UI.elements.main;if(mist.user.loggedin&&!("ui_settings"in mist.data))c.html("Loading.."),mist.send(function(){UI.showTab(a,b)},{ui_settings:!0});else{var d=UI.elements.menu.removeClass("hide").find('.plain:contains("'+a+'")').closest(".button");0<d.length&&(UI.elements.menu.find(".button.active").removeClass("active"),d.addClass("active"));if("undefined"!=typeof mistvideo)for(var e in mistvideo)if("embedded"in mistvideo[e])for(var g in mistvideo[e].embedded)try{mistvideo[e].embedded[g].player.unload(),
c.html($("<h2>").text(a));switch(a){case "Login":if(mist.user.loggedin){UI.navto("Overview");return}UI.elements.menu.addClass("hide");UI.elements.connection.status.text("Disconnected").removeClass("green").addClass("red");c.append(UI.buildUI([{type:"help",help:"Please provide your account details.<br>You were asked to set these when MistController was started for the first time. If you did not yet set any account details, log in with your desired credentials to create a new account."},{label:"Host", delete mistvideo[e].embedded[g]}catch(m){}UI.interval.clear();c.html($("<h2>").text(a));switch(a){case "Login":if(mist.user.loggedin){UI.navto("Overview");return}UI.elements.menu.addClass("hide");UI.elements.connection.status.text("Disconnected").removeClass("green").addClass("red");c.append(UI.buildUI([{type:"help",help:"Please provide your account details.<br>You were asked to set these when MistController was started for the first time. If you did not yet set any account details, log in with your desired credentials to create a new account."},
help:"Url location of the MistServer API. Generally located at http://MistServerIP:4242/api","default":"http://localhost:4242/api",pointer:{main:mist.user,index:"host"}},{label:"Username",help:"Please enter your username here.",validate:["required"],pointer:{main:mist.user,index:"name"}},{label:"Password",type:"password",help:"Please enter your password here.",validate:["required"],pointer:{main:mist.user,index:"rawpassword"}},{type:"buttons",buttons:[{label:"Login",type:"save","function":function(){mist.user.password= {label:"Host",help:"Url location of the MistServer API. Generally located at http://MistServerIP:4242/api","default":"http://localhost:4242/api",pointer:{main:mist.user,index:"host"}},{label:"Username",help:"Please enter your username here.",validate:["required"],pointer:{main:mist.user,index:"name"}},{label:"Password",type:"password",help:"Please enter your password here.",validate:["required"],pointer:{main:mist.user,index:"rawpassword"}},{type:"buttons",buttons:[{label:"Login",type:"save","function":function(){mist.user.password=
MD5(mist.user.rawpassword);delete mist.user.rawpassword;mist.send(function(){UI.navto("Overview")})}}]}]));break;case "Create a new account":UI.elements.menu.addClass("hide");c.append($("<p>").text("No account has been created yet in the MistServer at ").append($("<i>").text(mist.user.host)).append("."));c.append(UI.buildUI([{type:"buttons",buttons:[{label:"Select other host",type:"cancel",css:{"float":"left"},"function":function(){UI.navto("Login")}}]},{type:"custom",custom:$("<br>")},{label:"Desired username", MD5(mist.user.rawpassword);delete mist.user.rawpassword;mist.send(function(){UI.navto("Overview")})}}]}]));break;case "Create a new account":UI.elements.menu.addClass("hide");c.append($("<p>").text("No account has been created yet in the MistServer at ").append($("<i>").text(mist.user.host)).append("."));c.append(UI.buildUI([{type:"buttons",buttons:[{label:"Select other host",type:"cancel",css:{"float":"left"},"function":function(){UI.navto("Login")}}]},{type:"custom",custom:$("<br>")},{label:"Desired username",
type:"str",validate:["required"],help:"Enter your desired username. In the future, you will need this to access the Management Interface.",pointer:{main:mist.user,index:"name"}},{label:"Desired password",type:"password",validate:["required",function(a,b){$(".match_password").not($(b)).trigger("change");return false}],help:"Enter your desired password. In the future, you will need this to access the Management Interface.",pointer:{main:mist.user,index:"rawpassword"},classes:["match_password"]},{label:"Repeat password", type:"str",validate:["required"],help:"Enter your desired username. In the future, you will need this to access the Management Interface.",pointer:{main:mist.user,index:"name"}},{label:"Desired password",type:"password",validate:["required",function(a,b){$(".match_password").not($(b)).trigger("change");return false}],help:"Enter your desired password. In the future, you will need this to access the Management Interface.",pointer:{main:mist.user,index:"rawpassword"},classes:["match_password"]},{label:"Repeat password",
type:"password",validate:["required",function(a,b){return a!=$(".match_password").not($(b)).val()?{msg:'The fields "Desired password" and "Repeat password" do not match.',classes:["red"]}:false}],help:"Repeat your desired password.",classes:["match_password"]},{type:"buttons",buttons:[{type:"save",label:"Create new account","function":function(){mist.send(function(){UI.navto("Account created")},{authorize:{new_username:mist.user.name,new_password:mist.user.rawpassword}});mist.user.password=MD5(mist.user.rawpassword); type:"password",validate:["required",function(a,b){return a!=$(".match_password").not($(b)).val()?{msg:'The fields "Desired password" and "Repeat password" do not match.',classes:["red"]}:false}],help:"Repeat your desired password.",classes:["match_password"]},{type:"buttons",buttons:[{type:"save",label:"Create new account","function":function(){mist.send(function(){UI.navto("Account created")},{authorize:{new_username:mist.user.name,new_password:mist.user.rawpassword}});mist.user.password=MD5(mist.user.rawpassword);

View file

@ -1839,6 +1839,7 @@ var UI = {
for (var i in mistvideo[s].embedded) { for (var i in mistvideo[s].embedded) {
try { try {
mistvideo[s].embedded[i].player.unload(); mistvideo[s].embedded[i].player.unload();
delete mistvideo[s].embedded[i];
} }
catch (e) {} catch (e) {}
} }