-
Notifications
You must be signed in to change notification settings - Fork 5
/
jquery.videosequence.min.js
1 lines (1 loc) · 1.88 KB
/
jquery.videosequence.min.js
1
!function(e){var n=function(e,n){var t=new XMLHttpRequest;t.open("GET",e,!0),t.responseType="arraybuffer",t.send(),t.onload=function(){var e=new Uint8Array(t.response),r=new Blob([e],{type:"video/webm"});n(r)}},t=function(e,n,t,r){var o=new FileReader;o.onload=function(n){e.timestampOffset=t,e.appendBuffer(new Uint8Array(n.target.result)),r&&r()},o.readAsArrayBuffer(n)},r=function(e,r,o,i){n(r,function(n){t(e,n,o,i)})},o=function(e,n,t){e.addEventListener("sourceopen",function(){var o=e.addSourceBuffer(t),i=n.shift();c(i);var a=i.source,u=i.timestampOffset;r(o,a,u,function(){o.addEventListener("updateend",function(){if(n.length>0){var t=n.shift();c(t);var i=t.source,a=t.timestampOffset;r(o,i,a)}else e.endOfStream()})})})},i=function(e,n,t){if(0===n.length)return console.warn("Trying to create mediasequence with empty specs.");var r=new window.MediaSource;e.src=window.URL.createObjectURL(r),o(r,n,t)},a=function(n,t,r){n.prop("tagName")!==r&&e.error("Called $."+t+" on a non "+r+" tag.")},u=function(n,t){n||e.error("Called $."+t+" with no specs given.")},c=function(n){n.source||e.error('Tried to create a mediasequence with a spec missing "source" key.')},s=function(e,n,t){return JSON.parse(e.attr(n+t))},f=function(n,t){var r="data-"+n+"sequence-",o=s(t,r,"sources"),i=s(t,r,"offsets"),a=[];return e.each(o,function(e,n){var t=i[e];a.push({source:n,timestampOffset:t})}),a},d=function(e,n,t,r){var o=e+"sequence";return a(n,o,e.toUpperCase()),u(t,o),i(n[0],t,r),n};e.fn.videosequence=function(e){return d("video",this,e,'video/webm; codecs="vorbis,vp8"')},e.fn.audiosequence=function(e){return d("audio",this,e,'audio/webm; codecs="vorbis"')};var v=function(n){var t=n+"sequence";e.each(e('[data-rel="'+n+'sequence"]'),function(r,o){var i=e(o),a=f(n,i);i[t].call(i,a)})},p=function(){v("video"),v("audio")};e(p),e(document).on("videosequence:initialize",p),e(document).on("audiosequence:initialize",p)}(jQuery);