Embed: videojs live fixes

This commit is contained in:
Cat 2019-04-19 10:37:12 +02:00 committed by Thulinma
parent 2fa6565f7b
commit dfb308aac7
8 changed files with 51 additions and 14 deletions

File diff suppressed because one or more lines are too long

View file

@ -1 +1 @@
mistplayers.videojs={name:"VideoJS player",mimes:["html5/application/vnd.apple.mpegurl","html5/application/vnd.apple.mpegurl;version=7"],priority:MistUtil.object.keys(mistplayers).length+1,isMimeSupported:function(e){return this.mimes.indexOf(e)==-1?false:true},isBrowserSupported:function(e,t,i){if(location.protocol!=MistUtil.http.url.split(t.url).protocol){i.log("HTTP/HTTPS mismatch for this source");return false}if(location.protocol=="file:"&&e=="html5/application/vnd.apple"){i.log("This source ("+e+") won't load if the page is run via file://");return false}return"MediaSource"in window},player:function(){},scriptsrc:function(e){return e+"/videojs.js"}};var p=mistplayers.videojs.player;p.prototype=new MistPlayer;p.prototype.build=function(e,t){var i=this;function r(){if(e.destroyed){return}e.log("Building VideoJS player..");var r=document.createElement("video");if(e.source.type!="html5/video/ogg"){r.crossOrigin="anonymous"}var o=e.source.type.split("/");if(o[0]=="html5"){o.shift()}var n=document.createElement("source");n.setAttribute("src",e.source.url);i.source=n;r.appendChild(n);n.type=o.join("/");e.log("Adding "+n.type+" source @ "+e.source.url);if(n.type.indexOf("application/vnd.apple.mpegurl")>=0){n.type="application/x-mpegURL"}MistUtil.class.add(r,"video-js");var s={};if(e.options.autoplay){s.autoplay=true}if(e.options.loop&&e.info.type!="live"){s.loop=true;r.loop=true}if(e.options.muted){s.muted=true;r.muted=true}if(e.options.poster){s.poster=e.options.poster}if(e.options.controls=="stock"){r.setAttribute("controls","");if(!document.getElementById("videojs-css")){var l=document.createElement("link");l.rel="stylesheet";l.href=e.options.host+"/skins/videojs.css";l.id="videojs-css";document.head.appendChild(l)}}i.onready(function(){i.videojs=videojs(r,s,function(){e.log("Videojs initialized")});i.api.unload=function(){if(i.videojs){videojs(r).dispose();i.videojs=false}};MistUtil.event.addListener(e.options.target,"error",function(e){if(e.message=="Stream is offline"){i.api.unload()}})});e.log("Built html");if("Proxy"in window&&"Reflect"in window){var a={get:{},set:{}};e.player.api=new Proxy(r,{get:function(e,t,i){if(t in a.get){return a.get[t].apply(e,arguments)}var r=e[t];if(typeof r==="function"){return function(){return r.apply(e,arguments)}}return r},set:function(e,t,i){if(t in a.set){return a.set[t].call(e,i)}return e[t]=i}});if(e.info.type=="live"){function p(e){var t=0;if(e.buffered.length){t=e.buffered.end(e.buffered.length-1)}return t}var u=90;a.get.duration=function(){if(e.info){return(e.info.lastms+(new Date).getTime()-e.info.updated.getTime())*.001}return false};e.player.api.lastProgress=new Date;e.player.api.liveOffset=0;MistUtil.event.addListener(r,"progress",function(){e.player.api.lastProgress=new Date});a.set.currentTime=function(t){var i=e.player.api.currentTime-t;var r=t-e.player.api.duration;e.log("Seeking to "+MistUtil.format.time(t)+" ("+Math.round(r*-10)/10+"s from live)");e.video.currentTime-=i};a.get.currentTime=function(){return this.currentTime+e.info.lastms*.001-e.player.api.liveOffset-u}}}else{i.api=r}e.player.setSize=function(t){if("videojs"in e.player){e.player.videojs.dimensions(t.width,t.height);r.parentNode.style.width=t.width+"px";r.parentNode.style.height=t.height+"px"}this.api.style.width=t.width+"px";this.api.style.height=t.height+"px"};e.player.api.setSource=function(t){if(!e.player.videojs){return}if(e.player.videojs.src()!=t){e.player.videojs.src({type:e.player.videojs.currentSource().type,src:t})}};e.player.api.setSubtitle=function(e){var t=r.getElementsByTagName("track");for(var i=t.length-1;i>=0;i--){r.removeChild(t[i])}if(e){var o=document.createElement("track");r.appendChild(o);o.kind="subtitles";o.label=e.label;o.srclang=e.lang;o.src=e.src;o.setAttribute("default","")}};t(r)}if("videojs"in window){r()}else{var o=MistUtil.scripts.insert(e.urlappend(mistplayers.videojs.scriptsrc(e.options.host)),{onerror:function(t){var i="Failed to load videojs.js";if(t.message){i+=": "+t.message}e.showError(i)},onload:r},e)}};
mistplayers.videojs={name:"VideoJS player",mimes:["html5/application/vnd.apple.mpegurl","html5/application/vnd.apple.mpegurl;version=7"],priority:MistUtil.object.keys(mistplayers).length+1,isMimeSupported:function(e){return this.mimes.indexOf(e)==-1?false:true},isBrowserSupported:function(e,t,i){if(location.protocol!=MistUtil.http.url.split(t.url).protocol){i.log("HTTP/HTTPS mismatch for this source");return false}if(location.protocol=="file:"&&e=="html5/application/vnd.apple"){i.log("This source ("+e+") won't load if the page is run via file://");return false}return"MediaSource"in window},player:function(){},scriptsrc:function(e){return e+"/videojs.js"}};var p=mistplayers.videojs.player;p.prototype=new MistPlayer;p.prototype.build=function(e,t){var i=this;function r(){if(e.destroyed){return}e.log("Building VideoJS player..");var r=document.createElement("video");if(e.source.type!="html5/video/ogg"){r.crossOrigin="anonymous"}var o=e.source.type.split("/");if(o[0]=="html5"){o.shift()}var s=document.createElement("source");s.setAttribute("src",e.source.url);i.source=s;r.appendChild(s);s.type=o.join("/");e.log("Adding "+s.type+" source @ "+e.source.url);MistUtil.class.add(r,"video-js");var n={};if(e.options.autoplay){n.autoplay=true}if(e.options.loop&&e.info.type!="live"){n.loop=true;r.loop=true}if(e.options.muted){n.muted=true;r.muted=true}if(e.options.poster){n.poster=e.options.poster}if(e.options.controls=="stock"){r.setAttribute("controls","");if(!document.getElementById("videojs-css")){var a=document.createElement("link");a.rel="stylesheet";a.href=e.options.host+"/skins/videojs.css";a.id="videojs-css";document.head.appendChild(a)}}i.onready(function(){i.videojs=videojs(r,n,function(){e.log("Videojs initialized")});i.api.unload=function(){if(i.videojs){videojs(r).dispose();i.videojs=false}};MistUtil.event.addListener(e.options.target,"error",function(t){var r=false;switch(t.message){case"Stream is shutting down":{t.preventDefault();break}case"Stream is offline":{e.clearError();t.preventDefault();r=MistUtil.event.addListener(e.video,"waiting",function(){i.api.pause();e.showError("Stream is offline ",{polling:true});if(r){MistUtil.event.removeListener(r)}});break}case"Stream is waiting for data":{if(r){MistUtil.event.removeListener(r)}i.api.pause();e.reload();break}}})});e.log("Built html");if("Proxy"in window&&"Reflect"in window){var l={get:{},set:{}};e.player.api=new Proxy(r,{get:function(e,t,i){if(t in l.get){return l.get[t].apply(e,arguments)}var r=e[t];if(typeof r==="function"){return function(){return r.apply(e,arguments)}}return r},set:function(e,t,i){if(t in l.set){return l.set[t].call(e,i)}return e[t]=i}});if(e.info.type=="live"){function p(e){var t=0;if(e.buffered.length){t=e.buffered.end(e.buffered.length-1)}return t}var u=90;l.get.duration=function(){if(e.info){return(e.info.lastms+(new Date).getTime()-e.info.updated.getTime())*.001}return false};e.player.api.lastProgress=new Date;e.player.api.liveOffset=0;MistUtil.event.addListener(r,"progress",function(){e.player.api.lastProgress=new Date});l.set.currentTime=function(t){var i=e.player.api.currentTime-t;var r=t-e.player.api.duration;e.log("Seeking to "+MistUtil.format.time(t)+" ("+Math.round(r*-10)/10+"s from live)");e.video.currentTime-=i};l.get.currentTime=function(){return this.currentTime+e.info.lastms*.001-e.player.api.liveOffset-u}}}else{i.api=r}e.player.setSize=function(t){if("videojs"in e.player){e.player.videojs.dimensions(t.width,t.height);r.parentNode.style.width=t.width+"px";r.parentNode.style.height=t.height+"px"}this.api.style.width=t.width+"px";this.api.style.height=t.height+"px"};e.player.api.setSource=function(t){if(!e.player.videojs){return}if(e.player.videojs.src()!=t){e.player.videojs.src({type:e.player.videojs.currentSource().type,src:t})}};e.player.api.setSubtitle=function(e){var t=r.getElementsByTagName("track");for(var i=t.length-1;i>=0;i--){r.removeChild(t[i])}if(e){var o=document.createElement("track");r.appendChild(o);o.kind="subtitles";o.label=e.label;o.srclang=e.lang;o.src=e.src;o.setAttribute("default","")}};t(r)}if("videojs"in window){r()}else{var o=MistUtil.scripts.insert(e.urlappend(mistplayers.videojs.scriptsrc(e.options.host)),{onerror:function(t){var i="Failed to load videojs.js";if(t.message){i+=": "+t.message}e.showError(i)},onload:r},e)}};

View file

@ -43,7 +43,7 @@ function MistVideo(streamName,options) {
this.logs = [];
this.log = function(message,type){
if (!type) { type = "log"; }
MistUtil.event.send(type,message,options.target);
var event = MistUtil.event.send(type,message,options.target);
var data = {
type: type
};
@ -59,6 +59,7 @@ function MistVideo(streamName,options) {
else { console.log(msg); }
} catch(e){}
}
return event;
};
this.log("Initializing..");
@ -301,7 +302,7 @@ function MistVideo(streamName,options) {
var fw = size.width || ('width' in options && options.width ? options.width : false ); //force this width
var fh = size.height || ('height' in options && options.height ? options.height : false ); //force this height
if (!("source" in this.info)) {
if ((!this.info) || !("source" in this.info)) {
fw = 640;
fh = 480;
}

View file

@ -5,4 +5,4 @@ wget https://cdn.dashjs.org/latest/dash.all.min.js -O dash.all.min.js
echo "Videojs"
echo "You'll want to check for the latest version at https://videojs.com/getting-started/#download-cdn"
wget https://vjs.zencdn.net/7.3.0/video.min.js -O video.min.js
wget https://vjs.zencdn.net/7.4.1/video.min.js -O video.min.js

File diff suppressed because one or more lines are too long

View file

@ -1702,7 +1702,7 @@ MistSkins["default"] = {
d.appendChild(document.createTextNode(details));
}
else if ("decodingIssues" in MistVideo.skin.blueprints) { //dev mode
if (("player" in MistVideo) && ("api" in MistVideo.player)) {
if (("player" in MistVideo) && ("api" in MistVideo.player) && (MistVideo.video)) {
details = [];
if (typeof MistVideo.player.api.currentTime != "undefined") {
details.push(["Current video time:",MistUtil.format.time(MistVideo.player.api.currentTime)]);
@ -1810,7 +1810,7 @@ MistSkins["default"] = {
since = (new Date()).getTime();
this.log(message,"error");
var event = this.log(message,"error");
var message_container = container.message(message,false,options);
message_global = message_container;
@ -1873,6 +1873,10 @@ MistSkins["default"] = {
if ("container" in MistVideo) {
MistVideo.container.removeAttribute("data-loading");
}
if (event.defaultPrevented) {
container.clear();
}
};
container.clear = function(message){
var countdowns = container.querySelectorAll("svg.icon.timeout");

View file

@ -587,6 +587,7 @@ var MistUtil = {
});
event.message = message;
target.dispatchEvent(event);
return event;
}
catch (e) {
try {
@ -594,6 +595,7 @@ var MistUtil = {
event.initEvent(type,true,true);
event.message = message;
target.dispatchEvent(event);
return event;
}
catch (e) { return false; }
}
@ -947,6 +949,8 @@ var MistUtil = {
line.addData = function(newData) {
if (isNaN(newData.y)) { return; }
if (options.differentiate) {
var diff = newData.y - lasty;
lasty = newData.y;

View file

@ -50,7 +50,8 @@ p.prototype.build = function (MistVideo,callback) {
ele.appendChild(source);
source.type = shortmime.join("/");
MistVideo.log("Adding "+source.type+" source @ "+MistVideo.source.url);
if (source.type.indexOf("application/vnd.apple.mpegurl") >= 0) { source.type = "application/x-mpegURL"; }
//if (source.type.indexOf("application/vnd.apple.mpegurl") >= 0) { source.type = "application/x-mpegURL"; }
//source.type = "application/vnd.apple.mpegurl";
MistUtil.class.add(ele,"video-js");
@ -89,10 +90,37 @@ p.prototype.build = function (MistVideo,callback) {
}
};
//because video reloads the m3u8 when the stream stops, creating all sorts of problems
//special HLS live when-stream-ends code because holy crap latency
MistUtil.event.addListener(MistVideo.options.target,"error",function(e){
if (e.message == "Stream is offline") {
me.api.unload();
var eventdata = false;
switch (e.message) {
case "Stream is shutting down": {
//MistVideo.clearError(); //we've probably got loads of buffer left to play
e.preventDefault();
break;
}
case "Stream is offline": {
MistVideo.clearError(); //we've probably got loads of buffer left to play
e.preventDefault();
eventdata = MistUtil.event.addListener(MistVideo.video,"waiting",function(){
//stream has ended
me.api.pause();
//show stream offline error
MistVideo.showError("Stream is offline ",{polling:true});
if (eventdata) { MistUtil.event.removeListener(eventdata); }
});
break;
}
case "Stream is waiting for data": {
if (eventdata) { MistUtil.event.removeListener(eventdata); }
me.api.pause();
MistVideo.reload();
break;
}
}
});
});