html5media-1.2.js 38 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656
  1. /****************************************************************
  2. * *
  3. * 代码库 *
  4. * www.dmaku.com *
  5. * 努力创建完善、持续更新插件以及模板 *
  6. * *
  7. ****************************************************************/
  8. /*
  9. * flowplayer.js 3.2.6. The Flowplayer API
  10. *
  11. * Copyright 2009-2011 Flowplayer Oy
  12. *
  13. * This file is part of Flowplayer.
  14. *
  15. * Flowplayer is free software: you can redistribute it and/or modify
  16. * it under the terms of the GNU General Public License as published by
  17. * the Free Software Foundation, either version 3 of the License, or
  18. * (at your option) any later version.
  19. *
  20. * Flowplayer is distributed in the hope that it will be useful,
  21. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  22. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  23. * GNU General Public License for more details.
  24. *
  25. * You should have received a copy of the GNU General Public License
  26. * along with Flowplayer. If not, see <http://www.gnu.org/licenses/>.
  27. *
  28. * Date: 2011-02-04 05:45:28 -0500 (Fri, 04 Feb 2011)
  29. * Revision: 614
  30. */
  31. (function(){function g(o){console.log("$f.fireEvent",[].slice.call(o))}function k(q){if(!q||typeof q!="object"){return q}var o=new q.constructor();for(var p in q){if(q.hasOwnProperty(p)){o[p]=k(q[p])}}return o}function m(t,q){if(!t){return}var o,p=0,r=t.length;if(r===undefined){for(o in t){if(q.call(t[o],o,t[o])===false){break}}}else{for(var s=t[0];p<r&&q.call(s,p,s)!==false;s=t[++p]){}}return t}function c(o){return document.getElementById(o)}function i(q,p,o){if(typeof p!="object"){return q}if(q&&p){m(p,function(r,s){if(!o||typeof s!="function"){q[r]=s}})}return q}function n(s){var q=s.indexOf(".");if(q!=-1){var p=s.slice(0,q)||"*";var o=s.slice(q+1,s.length);var r=[];m(document.getElementsByTagName(p),function(){if(this.className&&this.className.indexOf(o)!=-1){r.push(this)}});return r}}function f(o){o=o||window.event;if(o.preventDefault){o.stopPropagation();o.preventDefault()}else{o.returnValue=false;o.cancelBubble=true}return false}function j(q,o,p){q[o]=q[o]||[];q[o].push(p)}function e(){return"_"+(""+Math.random()).slice(2,10)}var h=function(t,r,s){var q=this,p={},u={};q.index=r;if(typeof t=="string"){t={url:t}}i(this,t,true);m(("Begin*,Start,Pause*,Resume*,Seek*,Stop*,Finish*,LastSecond,Update,BufferFull,BufferEmpty,BufferStop").split(","),function(){var v="on"+this;if(v.indexOf("*")!=-1){v=v.slice(0,v.length-1);var w="onBefore"+v.slice(2);q[w]=function(x){j(u,w,x);return q}}q[v]=function(x){j(u,v,x);return q};if(r==-1){if(q[w]){s[w]=q[w]}if(q[v]){s[v]=q[v]}}});i(this,{onCuepoint:function(x,w){if(arguments.length==1){p.embedded=[null,x];return q}if(typeof x=="number"){x=[x]}var v=e();p[v]=[x,w];if(s.isLoaded()){s._api().fp_addCuepoints(x,r,v)}return q},update:function(w){i(q,w);if(s.isLoaded()){s._api().fp_updateClip(w,r)}var v=s.getConfig();var x=(r==-1)?v.clip:v.playlist[r];i(x,w,true)},_fireEvent:function(v,y,w,A){if(v=="onLoad"){m(p,function(B,C){if(C[0]){s._api().fp_addCuepoints(C[0],r,B)}});return false}A=A||q;if(v=="onCuepoint"){var z=p[y];if(z){return z[1].call(s,A,w)}}if(y&&"onBeforeBegin,onMetaData,onStart,onUpdate,onResume".indexOf(v)!=-1){i(A,y);if(y.metaData){if(!A.duration){A.duration=y.metaData.duration}else{A.fullDuration=y.metaData.duration}}}var x=true;m(u[v],function(){x=this.call(s,A,y,w)});return x}});if(t.onCuepoint){var o=t.onCuepoint;q.onCuepoint.apply(q,typeof o=="function"?[o]:o);delete t.onCuepoint}m(t,function(v,w){if(typeof w=="function"){j(u,v,w);delete t[v]}});if(r==-1){s.onCuepoint=this.onCuepoint}};var l=function(p,r,q,t){var o=this,s={},u=false;if(t){i(s,t)}m(r,function(v,w){if(typeof w=="function"){s[v]=w;delete r[v]}});i(this,{animate:function(y,z,x){if(!y){return o}if(typeof z=="function"){x=z;z=500}if(typeof y=="string"){var w=y;y={};y[w]=z;z=500}if(x){var v=e();s[v]=x}if(z===undefined){z=500}r=q._api().fp_animate(p,y,z,v);return o},css:function(w,x){if(x!==undefined){var v={};v[w]=x;w=v}r=q._api().fp_css(p,w);i(o,r);return o},show:function(){this.display="block";q._api().fp_showPlugin(p);return o},hide:function(){this.display="none";q._api().fp_hidePlugin(p);return o},toggle:function(){this.display=q._api().fp_togglePlugin(p);return o},fadeTo:function(y,x,w){if(typeof x=="function"){w=x;x=500}if(w){var v=e();s[v]=w}this.display=q._api().fp_fadeTo(p,y,x,v);this.opacity=y;return o},fadeIn:function(w,v){return o.fadeTo(1,w,v)},fadeOut:function(w,v){return o.fadeTo(0,w,v)},getName:function(){return p},getPlayer:function(){return q},_fireEvent:function(w,v,x){if(w=="onUpdate"){var z=q._api().fp_getPlugin(p);if(!z){return}i(o,z);delete o.methods;if(!u){m(z.methods,function(){var B=""+this;o[B]=function(){var C=[].slice.call(arguments);var D=q._api().fp_invoke(p,B,C);return D==="undefined"||D===undefined?o:D}});u=true}}var A=s[w];if(A){var y=A.apply(o,v);if(w.slice(0,1)=="_"){delete s[w]}return y}return o}})};function b(q,G,t){var w=this,v=null,D=false,u,s,F=[],y={},x={},E,r,p,C,o,A;i(w,{id:function(){return E},isLoaded:function(){return(v!==null&&v.fp_play!==undefined&&!D)},getParent:function(){return q},hide:function(H){if(H){q.style.height="0px"}if(w.isLoaded()){v.style.height="0px"}return w},show:function(){q.style.height=A+"px";if(w.isLoaded()){v.style.height=o+"px"}return w},isHidden:function(){return w.isLoaded()&&parseInt(v.style.height,10)===0},load:function(J){if(!w.isLoaded()&&w._fireEvent("onBeforeLoad")!==false){var H=function(){u=q.innerHTML;if(u&&!flashembed.isSupported(G.version)){q.innerHTML=""}if(J){J.cached=true;j(x,"onLoad",J)}flashembed(q,G,{config:t})};var I=0;m(a,function(){this.unload(function(K){if(++I==a.length){H()}})})}return w},unload:function(J){if(this.isFullscreen()&&/WebKit/i.test(navigator.userAgent)){if(J){J(false)}return w}if(u.replace(/\s/g,"")!==""){if(w._fireEvent("onBeforeUnload")===false){if(J){J(false)}return w}D=true;try{if(v){v.fp_close();w._fireEvent("onUnload")}}catch(H){}var I=function(){v=null;q.innerHTML=u;D=false;if(J){J(true)}};setTimeout(I,50)}else{if(J){J(false)}}return w},getClip:function(H){if(H===undefined){H=C}return F[H]},getCommonClip:function(){return s},getPlaylist:function(){return F},getPlugin:function(H){var J=y[H];if(!J&&w.isLoaded()){var I=w._api().fp_getPlugin(H);if(I){J=new l(H,I,w);y[H]=J}}return J},getScreen:function(){return w.getPlugin("screen")},getControls:function(){return w.getPlugin("controls")._fireEvent("onUpdate")},getLogo:function(){try{return w.getPlugin("logo")._fireEvent("onUpdate")}catch(H){}},getPlay:function(){return w.getPlugin("play")._fireEvent("onUpdate")},getConfig:function(H){return H?k(t):t},getFlashParams:function(){return G},loadPlugin:function(K,J,M,L){if(typeof M=="function"){L=M;M={}}var I=L?e():"_";w._api().fp_loadPlugin(K,J,M,I);var H={};H[I]=L;var N=new l(K,null,w,H);y[K]=N;return N},getState:function(){return w.isLoaded()?v.fp_getState():-1},play:function(I,H){var J=function(){if(I!==undefined){w._api().fp_play(I,H)}else{w._api().fp_play()}};if(w.isLoaded()){J()}else{if(D){setTimeout(function(){w.play(I,H)},50)}else{w.load(function(){J()})}}return w},getVersion:function(){var I="flowplayer.js 3.2.6";if(w.isLoaded()){var H=v.fp_getVersion();H.push(I);return H}return I},_api:function(){if(!w.isLoaded()){throw"Flowplayer "+w.id()+" not loaded when calling an API method"}return v},setClip:function(H){w.setPlaylist([H]);return w},getIndex:function(){return p},_swfHeight:function(){return v.clientHeight}});m(("Click*,Load*,Unload*,Keypress*,Volume*,Mute*,Unmute*,PlaylistReplace,ClipAdd,Fullscreen*,FullscreenExit,Error,MouseOver,MouseOut").split(","),function(){var H="on"+this;if(H.indexOf("*")!=-1){H=H.slice(0,H.length-1);var I="onBefore"+H.slice(2);w[I]=function(J){j(x,I,J);return w}}w[H]=function(J){j(x,H,J);return w}});m(("pause,resume,mute,unmute,stop,toggle,seek,getStatus,getVolume,setVolume,getTime,isPaused,isPlaying,startBuffering,stopBuffering,isFullscreen,toggleFullscreen,reset,close,setPlaylist,addClip,playFeed,setKeyboardShortcutsEnabled,isKeyboardShortcutsEnabled").split(","),function(){var H=this;w[H]=function(J,I){if(!w.isLoaded()){return w}var K=null;if(J!==undefined&&I!==undefined){K=v["fp_"+H](J,I)}else{K=(J===undefined)?v["fp_"+H]():v["fp_"+H](J)}return K==="undefined"||K===undefined?w:K}});w._fireEvent=function(Q){if(typeof Q=="string"){Q=[Q]}var R=Q[0],O=Q[1],M=Q[2],L=Q[3],K=0;if(t.debug){g(Q)}if(!w.isLoaded()&&R=="onLoad"&&O=="player"){v=v||c(r);o=w._swfHeight();m(F,function(){this._fireEvent("onLoad")});m(y,function(S,T){T._fireEvent("onUpdate")});s._fireEvent("onLoad")}if(R=="onLoad"&&O!="player"){return}if(R=="onError"){if(typeof O=="string"||(typeof O=="number"&&typeof M=="number")){O=M;M=L}}if(R=="onContextMenu"){m(t.contextMenu[O],function(S,T){T.call(w)});return}if(R=="onPluginEvent"||R=="onBeforePluginEvent"){var H=O.name||O;var I=y[H];if(I){I._fireEvent("onUpdate",O);return I._fireEvent(M,Q.slice(3))}return}if(R=="onPlaylistReplace"){F=[];var N=0;m(O,function(){F.push(new h(this,N++,w))})}if(R=="onClipAdd"){if(O.isInStream){return}O=new h(O,M,w);F.splice(M,0,O);for(K=M+1;K<F.length;K++){F[K].index++}}var P=true;if(typeof O=="number"&&O<F.length){C=O;var J=F[O];if(J){P=J._fireEvent(R,M,L)}if(!J||P!==false){P=s._fireEvent(R,M,L,J)}}m(x[R],function(){P=this.call(w,O,M);if(this.cached){x[R].splice(K,1)}if(P===false){return false}K++});return P};function B(){if($f(q)){$f(q).getParent().innerHTML="";p=$f(q).getIndex();a[p]=w}else{a.push(w);p=a.length-1}A=parseInt(q.style.height,10)||q.clientHeight;E=q.id||"fp"+e();r=G.id||E+"_api";G.id=r;t.playerId=E;if(typeof t=="string"){t={clip:{url:t}}}if(typeof t.clip=="string"){t.clip={url:t.clip}}t.clip=t.clip||{};if(q.getAttribute("href",2)&&!t.clip.url){t.clip.url=q.getAttribute("href",2)}s=new h(t.clip,-1,w);t.playlist=t.playlist||[t.clip];var I=0;m(t.playlist,function(){var K=this;if(typeof K=="object"&&K.length){K={url:""+K}}m(t.clip,function(L,M){if(M!==undefined&&K[L]===undefined&&typeof M!="function"){K[L]=M}});t.playlist[I]=K;K=new h(K,I,w);F.push(K);I++});m(t,function(K,L){if(typeof L=="function"){if(s[K]){s[K](L)}else{j(x,K,L)}delete t[K]}});m(t.plugins,function(K,L){if(L){y[K]=new l(K,L,w)}});if(!t.plugins||t.plugins.controls===undefined){y.controls=new l("controls",null,w)}y.canvas=new l("canvas",null,w);u=q.innerHTML;function J(L){var K=w.hasiPadSupport&&w.hasiPadSupport();if(/iPad|iPhone|iPod/i.test(navigator.userAgent)&&!/.flv$/i.test(F[0].url)&&!K){return true}if(!w.isLoaded()&&w._fireEvent("onBeforeClick")!==false){w.load()}return f(L)}function H(){if(u.replace(/\s/g,"")!==""){if(q.addEventListener){q.addEventListener("click",J,false)}else{if(q.attachEvent){q.attachEvent("onclick",J)}}}else{if(q.addEventListener){q.addEventListener("click",f,false)}w.load()}}setTimeout(H,0)}if(typeof q=="string"){var z=c(q);if(!z){throw"Flowplayer cannot access element: "+q}q=z;B()}else{B()}}var a=[];function d(o){this.length=o.length;this.each=function(p){m(o,p)};this.size=function(){return o.length}}window.flowplayer=window.$f=function(){var p=null;var o=arguments[0];if(!arguments.length){m(a,function(){if(this.isLoaded()){p=this;return false}});return p||a[0]}if(arguments.length==1){if(typeof o=="number"){return a[o]}else{if(o=="*"){return new d(a)}m(a,function(){if(this.id()==o.id||this.id()==o||this.getParent()==o){p=this;return false}});return p}}if(arguments.length>1){var t=arguments[1],q=(arguments.length==3)?arguments[2]:{};if(typeof t=="string"){t={src:t}}t=i({bgcolor:"#000000",version:[9,0],expressInstall:"http://static.flowplayer.org/swf/expressinstall.swf",cachebusting:false},t);if(typeof o=="string"){if(o.indexOf(".")!=-1){var s=[];m(n(o),function(){s.push(new b(this,k(t),k(q)))});return new d(s)}else{var r=c(o);return new b(r!==null?r:o,t,q)}}else{if(o){return new b(o,t,q)}}}return null};i(window.$f,{fireEvent:function(){var o=[].slice.call(arguments);var q=$f(o[0]);return q?q._fireEvent(o.slice(1)):null},addPlugin:function(o,p){b.prototype[o]=p;return $f},each:m,extend:i});if(typeof jQuery=="function"){jQuery.fn.flowplayer=function(q,p){if(!arguments.length||typeof arguments[0]=="number"){var o=[];this.each(function(){var r=$f(this);if(r){o.push(r)}});return arguments.length?o[arguments[0]]:new d(o)}return this.each(function(){$f(this,k(q),p?k(p):{})})}}})();(function(){var e=typeof jQuery=="function";var i={width:"100%",height:"100%",allowfullscreen:true,allowscriptaccess:"always",quality:"high",version:null,onFail:null,expressInstall:null,w3c:false,cachebusting:false};if(e){jQuery.tools=jQuery.tools||{};jQuery.tools.flashembed={version:"1.0.4",conf:i}}function j(){if(c.done){return false}var l=document;if(l&&l.getElementsByTagName&&l.getElementById&&l.body){clearInterval(c.timer);c.timer=null;for(var k=0;k<c.ready.length;k++){c.ready[k].call()}c.ready=null;c.done=true}}var c=e?jQuery:function(k){if(c.done){return k()}if(c.timer){c.ready.push(k)}else{c.ready=[k];c.timer=setInterval(j,13)}};function f(l,k){if(k){for(key in k){if(k.hasOwnProperty(key)){l[key]=k[key]}}}return l}function g(k){switch(h(k)){case"string":k=k.replace(new RegExp('(["\\\\])',"g"),"\\$1");k=k.replace(/^\s?(\d+)%/,"$1pct");return'"'+k+'"';case"array":return"["+b(k,function(n){return g(n)}).join(",")+"]";case"function":return'"function()"';case"object":var l=[];for(var m in k){if(k.hasOwnProperty(m)){l.push('"'+m+'":'+g(k[m]))}}return"{"+l.join(",")+"}"}return String(k).replace(/\s/g," ").replace(/\'/g,'"')}function h(l){if(l===null||l===undefined){return false}var k=typeof l;return(k=="object"&&l.push)?"array":k}if(window.attachEvent){window.attachEvent("onbeforeunload",function(){__flash_unloadHandler=function(){};__flash_savedUnloadHandler=function(){}})}function b(k,n){var m=[];for(var l in k){if(k.hasOwnProperty(l)){m[l]=n(k[l])}}return m}function a(r,t){var q=f({},r);var s=document.all;var n='<object width="'+q.width+'" height="'+q.height+'"';if(s&&!q.id){q.id="_"+(""+Math.random()).substring(9)}if(q.id){n+=' id="'+q.id+'"'}if(q.cachebusting){q.src+=((q.src.indexOf("?")!=-1?"&":"?")+Math.random())}if(q.w3c||!s){n+=' data="'+q.src+'" type="application/x-shockwave-flash"'}else{n+=' classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"'}n+=">";if(q.w3c||s){n+='<param name="movie" value="'+q.src+'" />'}q.width=q.height=q.id=q.w3c=q.src=null;for(var l in q){if(q[l]!==null){n+='<param name="'+l+'" value="'+q[l]+'" />'}}var o="";if(t){for(var m in t){if(t[m]!==null){o+=m+"="+(typeof t[m]=="object"?g(t[m]):t[m])+"&"}}o=o.substring(0,o.length-1);n+='<param name="flashvars" value=\''+o+"' />"}n+="</object>";return n}function d(m,p,l){var k=flashembed.getVersion();f(this,{getContainer:function(){return m},getConf:function(){return p},getVersion:function(){return k},getFlashvars:function(){return l},getApi:function(){return m.firstChild},getHTML:function(){return a(p,l)}});var q=p.version;var r=p.expressInstall;var o=!q||flashembed.isSupported(q);if(o){p.onFail=p.version=p.expressInstall=null;m.innerHTML=a(p,l)}else{if(q&&r&&flashembed.isSupported([6,65])){f(p,{src:r});l={MMredirectURL:location.href,MMplayerType:"PlugIn",MMdoctitle:document.title};m.innerHTML=a(p,l)}else{if(m.innerHTML.replace(/\s/g,"")!==""){}else{m.innerHTML="<h2>Flash version "+q+" or greater is required</h2><h3>"+(k[0]>0?"Your version is "+k:"You have no flash plugin installed")+"</h3>"+(m.tagName=="A"?"<p>Click here to download latest version</p>":"<p>Download latest version from <a href='http://www.adobe.com/go/getflashplayer'>here</a></p>");if(m.tagName=="A"){m.onclick=function(){location.href="http://www.adobe.com/go/getflashplayer"}}}}}if(!o&&p.onFail){var n=p.onFail.call(this);if(typeof n=="string"){m.innerHTML=n}}if(document.all){window[p.id]=document.getElementById(p.id)}}window.flashembed=function(l,m,k){if(typeof l=="string"){var n=document.getElementById(l);if(n){l=n}else{c(function(){flashembed(l,m,k)});return}}if(!l){return}if(typeof m=="string"){m={src:m}}var o=f({},i);f(o,m);return new d(l,o,k)};f(window.flashembed,{getVersion:function(){var m=[0,0];if(navigator.plugins&&typeof navigator.plugins["Shockwave Flash"]=="object"){var l=navigator.plugins["Shockwave Flash"].description;if(typeof l!="undefined"){l=l.replace(/^.*\s+(\S+\s+\S+$)/,"$1");var n=parseInt(l.replace(/^(.*)\..*$/,"$1"),10);var r=/r/.test(l)?parseInt(l.replace(/^.*r(.*)$/,"$1"),10):0;m=[n,r]}}else{if(window.ActiveXObject){try{var p=new ActiveXObject("ShockwaveFlash.ShockwaveFlash.7")}catch(q){try{p=new ActiveXObject("ShockwaveFlash.ShockwaveFlash.6");m=[6,0];p.AllowScriptAccess="always"}catch(k){if(m[0]==6){return m}}try{p=new ActiveXObject("ShockwaveFlash.ShockwaveFlash")}catch(o){}}if(typeof p=="object"){l=p.GetVariable("$version");if(typeof l!="undefined"){l=l.replace(/^\S+\s+(.*)$/,"$1").split(",");m=[parseInt(l[0],10),parseInt(l[2],10)]}}}}return m},isSupported:function(k){var m=flashembed.getVersion();var l=(m[0]>k[0])||(m[0]==k[0]&&m[1]>=k[1]);return l},domReady:c,asString:g,getHTML:a});if(e){jQuery.fn.flashembed=function(l,k){var m=null;this.each(function(){m=flashembed(this,l,k)});return l.api===false?this:m}}})();
  32. (function(){
  33. var DomReady = window.DomReady = {};
  34. // Everything that has to do with properly supporting our document ready event. Brought over from the most awesome jQuery.
  35. var userAgent = navigator.userAgent.toLowerCase();
  36. // Figure out what browser is being used
  37. var browser = {
  38. version: (userAgent.match( /.+(?:rv|it|ra|ie)[\/: ]([\d.]+)/ ) || [])[1],
  39. safari: /webkit/.test(userAgent),
  40. opera: /opera/.test(userAgent),
  41. msie: (/msie/.test(userAgent)) && (!/opera/.test( userAgent )),
  42. mozilla: (/mozilla/.test(userAgent)) && (!/(compatible|webkit)/.test(userAgent))
  43. };
  44. var readyBound = false;
  45. var isReady = false;
  46. var readyList = [];
  47. // Handle when the DOM is ready
  48. function domReady() {
  49. // Make sure that the DOM is not already loaded
  50. if(!isReady) {
  51. // Remember that the DOM is ready
  52. isReady = true;
  53. if(readyList) {
  54. for(var fn = 0; fn < readyList.length; fn++) {
  55. readyList[fn].call(window, []);
  56. }
  57. readyList = [];
  58. }
  59. }
  60. };
  61. // From Simon Willison. A safe way to fire onload w/o screwing up everyone else.
  62. function addLoadEvent(func) {
  63. var oldonload = window.onload;
  64. if (typeof window.onload != 'function') {
  65. window.onload = func;
  66. } else {
  67. window.onload = function() {
  68. if (oldonload) {
  69. oldonload();
  70. }
  71. func();
  72. }
  73. }
  74. };
  75. // does the heavy work of working through the browsers idiosyncracies (let's call them that) to hook onload.
  76. function bindReady() {
  77. if(readyBound) {
  78. return;
  79. }
  80. readyBound = true;
  81. // Mozilla, Opera (see further below for it) and webkit nightlies currently support this event
  82. if (document.addEventListener && !browser.opera) {
  83. // Use the handy event callback
  84. document.addEventListener("DOMContentLoaded", domReady, false);
  85. }
  86. // If IE is used and is not in a frame
  87. // Continually check to see if the document is ready
  88. if (browser.msie && window == top) (function(){
  89. if (isReady) return;
  90. try {
  91. // If IE is used, use the trick by Diego Perini
  92. // http://javascript.nwbox.com/IEContentLoaded/
  93. document.documentElement.doScroll("left");
  94. } catch(error) {
  95. setTimeout(arguments.callee, 0);
  96. return;
  97. }
  98. // and execute any waiting functions
  99. domReady();
  100. })();
  101. if(browser.opera) {
  102. document.addEventListener( "DOMContentLoaded", function () {
  103. if (isReady) return;
  104. for (var i = 0; i < document.styleSheets.length; i++)
  105. if (document.styleSheets[i].disabled) {
  106. setTimeout( arguments.callee, 0 );
  107. return;
  108. }
  109. // and execute any waiting functions
  110. domReady();
  111. }, false);
  112. }
  113. if(browser.safari) {
  114. var numStyles;
  115. (function(){
  116. if (isReady) return;
  117. if (document.readyState != "loaded" && document.readyState != "complete") {
  118. setTimeout( arguments.callee, 0 );
  119. return;
  120. }
  121. if (numStyles === undefined) {
  122. var links = document.getElementsByTagName("link");
  123. for (var i=0; i < links.length; i++) {
  124. if(links[i].getAttribute('rel') == 'stylesheet') {
  125. numStyles++;
  126. }
  127. }
  128. var styles = document.getElementsByTagName("style");
  129. numStyles += styles.length;
  130. }
  131. if (document.styleSheets.length != numStyles) {
  132. setTimeout( arguments.callee, 0 );
  133. return;
  134. }
  135. // and execute any waiting functions
  136. domReady();
  137. })();
  138. }
  139. // A fallback to window.onload, that will always work
  140. addLoadEvent(domReady);
  141. };
  142. // This is the public function that people can use to hook up ready.
  143. DomReady.ready = function(fn, args) {
  144. // Attach the listeners
  145. bindReady();
  146. // If the DOM is already ready
  147. if (isReady) {
  148. // Execute the function immediately
  149. fn.call(window, []);
  150. } else {
  151. // Add the function to the wait list
  152. readyList.push( function() { return fn.call(window, []); } );
  153. }
  154. };
  155. bindReady();
  156. })();
  157. /*
  158. * HTML 5 media compatibility layer.
  159. *
  160. * Copyright 2010 Dave Hall <dave@etianen.com>.
  161. *
  162. * This script is part of the html5media project. The html5media project enables
  163. * HTML5 video and audio tags in all major browsers.
  164. *
  165. * The html5media project is free software: you can redistribute it and/or
  166. * modify it under the terms of the GNU General Public License as published by
  167. * the Free Software Foundation, either version 3 of the License, or (at your
  168. * option) any later version.
  169. *
  170. * The html5media project is distributed in the hope that it will be useful,
  171. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  172. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
  173. * Public License for more details.
  174. *
  175. * You should have received a copy of the GNU General Public License
  176. * along with html5media. If not, see<http://www.gnu.org/licenses/>.
  177. *
  178. * Developed by Dave Hall.
  179. *
  180. * <http://www.etianen.com/>
  181. */
  182. (function(window, document, undefined) {
  183. "use strict";
  184. // Tagnames for the different types of media tag.
  185. var VIDEO_TAG = "video";
  186. var AUDIO_TAG = "audio";
  187. // If no video tag is supported, go ahead and enable all HTML5 elements.
  188. if (!document.createElement(VIDEO_TAG).canPlayType) {
  189. document.createElement(AUDIO_TAG);
  190. document.createElement("source");
  191. }
  192. // Checks whether this is a broken Android implementation.
  193. var isBrokenAndroid = window.navigator.userAgent.toLowerCase().match(/android 2\.[12]/) !== null;
  194. // Checks if this is opera.
  195. var isOpera = window.navigator.userAgent.toLowerCase().match(/opera/) !== null;
  196. // Checks whether the given element can play the fiven format.
  197. function canPlayFormat(element, format) {
  198. return element.canPlayType(format) || (isBrokenAndroid && format.search("mp4") > -1);
  199. }
  200. //swf播放器
  201. function SWFplay(element, url){
  202. var replacement = document.createElement("span");
  203. replacement.id = element.id;
  204. replacement.style.cssText = element.style.cssText;
  205. replacement.className = element.className +" video-play-wrapper-swf";
  206. replacement.title = element.title;
  207. replacement.style.display = "block";
  208. replacement.style.width = getDimension(element, "width", "300px");
  209. replacement.innerHTML = "<object width='720' height='446' class='object-swf-player'>" +
  210. "<param name='movie' value="+ url +">" +
  211. "<param name='wmode' value='transparent'>" +
  212. "<embed width='720' height='446' align='middle' type='application/x-shockwave-flash' allowscriptaccess='always' quality='high' allowfullscreen='true' src="+ url +">" +
  213. "</object>";
  214. // Replace the element with the div.
  215. element.parentNode.replaceChild(replacement, element);
  216. }
  217. // Scans over elements with the given tag name, creating fallbacks if required.
  218. function scanElementsByTagName(tagName) {
  219. var elements = document.getElementsByTagName(tagName);
  220. var elementsList = [];
  221. for (var n = 0; n < elements.length; n++) {
  222. elementsList.push(elements[n]);
  223. }
  224. for (n = 0; n < elementsList.length; n++) {
  225. var element = elementsList[n];
  226. var requiresFallback = true;
  227. var createSWFplay = false; //是否用swf播放
  228. var videoUrl = "";
  229. // Test if the media tag is supported.
  230. if (element.canPlayType) {
  231. // If the media has a src attribute, and can play it, then all is good.
  232. if (element.src) {
  233. if ( canPlayFormat(element, guessFormat(tagName, element.src)) && !(element.src.search(/.flv/i) > 0) ) { //增加是否是flv格式视频的判断
  234. if( element.src.search(/.swf/i) > 0 ){
  235. requiresFallback = false;
  236. createSWFplay = true;
  237. videoUrl = element.src;
  238. }else{
  239. requiresFallback = false;
  240. createSWFplay = false;
  241. }
  242. }
  243. } else {
  244. // Check for source child attributes.
  245. var sources = element.getElementsByTagName("source");
  246. for (var m = 0; m < sources.length; m++) {
  247. var source = sources[m];
  248. if ( canPlayFormat(element, guessFormat(tagName, source.src, source.type)) && !(source.src.search(/.flv/i) > 0) ) { //增加是否是flv格式视频的判
  249. if( source.src.search(/.swf/i) > 0 ){
  250. requiresFallback = false;
  251. createSWFplay = true;
  252. videoUrl = source.src;
  253. break;
  254. }else{
  255. requiresFallback = false;
  256. createSWFplay = false;
  257. break;
  258. }
  259. }
  260. }
  261. }
  262. }else{
  263. //不支持html5标签
  264. if (element.src) {
  265. if( element.src.search(/.swf/i) > 0 ){
  266. requiresFallback = false;
  267. createSWFplay = true;
  268. videoUrl = element.src;
  269. }else{
  270. createSWFplay = false;
  271. }
  272. } else {
  273. // Check for source child attributes.
  274. var sources = element.getElementsByTagName("source");
  275. for (var m = 0; m < sources.length; m++) {
  276. var source = sources[m];
  277. if( source.src.search(/.swf/i) > 0 ){
  278. requiresFallback = false;
  279. createSWFplay = true;
  280. videoUrl = source.src;
  281. break;
  282. }else{
  283. createSWFplay = false;
  284. break;
  285. }
  286. }
  287. }
  288. }
  289. //使用swf播放视频
  290. if( createSWFplay ){
  291. SWFplay(element, videoUrl);
  292. }
  293. // If cannot play media, create the fallback. 是否使用flowplay播放视频判断
  294. if (requiresFallback || html5media.forceFallback(tagName, element)) {
  295. html5media.createFallback(tagName, element);
  296. } else {
  297. // HACK: Enables playback in android mobile.
  298. if (isBrokenAndroid) {
  299. element.addEventListener("click", function() {
  300. this.play();
  301. }, false);
  302. }
  303. }
  304. }
  305. }
  306. /**
  307. * Replaces all video tags with flowplayer video player if the browser does
  308. * not support either the video tag the h.264 codex.
  309. *
  310. * This is run automatically on document ready, but can be run manually
  311. * again after dynamically creating HTML5 video tags.
  312. */
  313. function html5media() {
  314. scanElementsByTagName("video");
  315. scanElementsByTagName("audio");
  316. }
  317. /**
  318. * Callback to allow conditional forcing of the fallback player.
  319. *
  320. * Return true to force the flash fallback. The default implementation never
  321. * forces the flash fallback.
  322. */
  323. html5media.forceFallback = function(tagName, element) {
  324. return false;
  325. };
  326. // Removes the final filename from the given path.
  327. function dirname(path) {
  328. return path.split("/").slice(0, -1).join("/") + "/";
  329. }
  330. /**
  331. * The locations of the flowplayer and flowplayer controls SWF files.
  332. *
  333. * Override this if they are not located in the same folder as the
  334. */
  335. var scriptRoot = (function() {
  336. var scripts = document.getElementsByTagName("script");
  337. for (var n = 0; n < scripts.length; n++) {
  338. var script = scripts[n];
  339. if (script.src.match(/html5media(\.min|)\.js/)) {
  340. return dirname(script.src);
  341. }
  342. }
  343. return "";
  344. }());
  345. html5media.flowplayerSwf = scriptRoot + "flowplayer.swf";
  346. html5media.flowplayerAudioSwf = scriptRoot + "flowplayer.audio.swf";
  347. html5media.flowplayerControlsSwf = scriptRoot + "flowplayer.controls.swf";
  348. html5media.expressInstallSwf = scriptRoot + "expressInstall.swf";
  349. // Known media formats.
  350. var THEORA_FORMAT = 'video/ogg; codecs="theora, vorbis"';
  351. var H264_FORMAT = 'video/mp4; codecs="avc1.42E01E, mp4a.40.2"';
  352. var VORBIS_FORMAT = 'audio/ogg; codecs="vorbis"';
  353. var WEBM_FORMAT = 'video/webm;';
  354. var M4A_FORMAT = 'audio/x-m4a;';
  355. var MP3_FORMAT = 'audio/mpeg;';
  356. var WAV_FORMAT = 'audio/wav; codecs="1"';
  357. /**
  358. * The video format to assume if it cannot be determined what format a media
  359. * file is.
  360. */
  361. var assumedFormats = {
  362. video: H264_FORMAT,
  363. audio: MP3_FORMAT
  364. };
  365. /**
  366. * Formats that the fallback Flash player is able to understand.
  367. */
  368. var fallbackFormats = [H264_FORMAT, M4A_FORMAT, MP3_FORMAT];
  369. /**
  370. * Known file extensions that can be used to guess media formats in the
  371. * absence of other information.
  372. */
  373. var fileExtensions = {
  374. video: {
  375. "ogg": THEORA_FORMAT,
  376. "ogv": THEORA_FORMAT,
  377. "avi": H264_FORMAT,
  378. "mp4": H264_FORMAT,
  379. "mkv": H264_FORMAT,
  380. "h264": H264_FORMAT,
  381. "264": H264_FORMAT,
  382. "avc": H264_FORMAT,
  383. "m4v": H264_FORMAT,
  384. "3gp": H264_FORMAT,
  385. "3gpp": H264_FORMAT,
  386. "3g2": H264_FORMAT,
  387. "mpg": H264_FORMAT,
  388. "mpeg": H264_FORMAT,
  389. "webm": WEBM_FORMAT
  390. },
  391. audio: {
  392. "ogg": VORBIS_FORMAT,
  393. "oga": VORBIS_FORMAT,
  394. "aac": M4A_FORMAT,
  395. "m4a": M4A_FORMAT,
  396. "mp3": MP3_FORMAT,
  397. "wav": WAV_FORMAT
  398. }
  399. };
  400. // Trys to determine the format of a given video file.
  401. function guessFormat(tag, src, type) {
  402. // An explicit type is always best.
  403. if (type) {
  404. return type;
  405. }
  406. // Try to match based on file extension.
  407. var extensionMatch = (/\.([a-z1-9]+)(\?|#|\s|$)/i).exec(src);
  408. if (extensionMatch) {
  409. var format = fileExtensions[tag][extensionMatch[1]];
  410. if (format) {
  411. return format;
  412. }
  413. }
  414. return assumedFormats[tag];
  415. }
  416. // Detects presence of HTML5 attributes.
  417. function hasAttr(element, attr) {
  418. var val = element.getAttribute(attr);
  419. return !!val || typeof val == "string";
  420. }
  421. // Standardizes URLs to avoid confusing Flowplayer.
  422. function fixPath(url) {
  423. var link = document.createElement("a");
  424. link.href = url;
  425. return link.href;
  426. }
  427. // Calculates the given dimension of the given element.
  428. function getDimension(element, dimension, fallback) {
  429. // Attempt to use it's attribute value.
  430. var result = element.getAttribute(dimension);
  431. if (result) {
  432. return result + "px";
  433. }
  434. // Attempt to use it's computed style.
  435. var style;
  436. if (element.currentStyle) {
  437. style = element.currentStyle[dimension];
  438. } else if (window.getComputedStyle) {
  439. style = document.defaultView.getComputedStyle(element, null).getPropertyValue(dimension);
  440. } else {
  441. return fallback;
  442. }
  443. if (style == "auto") {
  444. return fallback;
  445. }
  446. return style;
  447. }
  448. // Extracts the mimetype from a format string.
  449. function getMimeType(format) {
  450. return format.match(/\s*([\w-]+\/[\w-]+)(;|\s|$)/)[1];
  451. }
  452. // Checks whether the two formats are equivalent.
  453. function formatMatches(format1, format2) {
  454. return (getMimeType(format1) == getMimeType(format2));
  455. }
  456. /**
  457. * Callback for adding custom configuration options to Flowplayer before it
  458. * launches. This callback is supplied with the tagname of the element being
  459. * replaced ("video" or "audio"), the element being replaced, and the
  460. * generated Flowplayer configuration.
  461. *
  462. * This callback should return the updated Flowplayer configuration. By
  463. * The default implementation leaves the generated configuration intact.
  464. */
  465. html5media.configureFlowplayer = function(element, config) {
  466. return config;
  467. };
  468. /**
  469. * Default callback for creating a fallback for html5 media tags.
  470. *
  471. * This implementation creates flowplayer instances, but this can
  472. * theoretically be used to support all different types of flash player.
  473. */
  474. html5media.createFallback = function(tagName, element) {
  475. var hasControls = hasAttr(element, "controls");
  476. // Standardize the src and poster.
  477. var poster = element.getAttribute("poster") || "";
  478. var src = element.getAttribute("src") || "";
  479. if (!src) {
  480. // Find a compatible fallback file.
  481. var sources = element.getElementsByTagName("source");
  482. for (var sn = 0; sn < sources.length; sn++) {
  483. var source = sources[sn];
  484. var srcValue = source.getAttribute("src");
  485. if (srcValue) {
  486. for (var fn = 0; fn < fallbackFormats.length; fn++) {
  487. var fallbackFormat = fallbackFormats[fn];
  488. if (formatMatches(fallbackFormat, guessFormat(tagName, srcValue, source.getAttribute("type")))) {
  489. src = srcValue;
  490. break;
  491. }
  492. }
  493. }
  494. if (src) {
  495. break;
  496. }
  497. }
  498. }
  499. // If there is no src, then fail silently for now.
  500. if (!src) {
  501. return;
  502. }
  503. // Create the replacement element div.
  504. var replacement = document.createElement("span");
  505. replacement.id = element.id;
  506. replacement.style.cssText = element.style.cssText;
  507. replacement.className = element.className;
  508. replacement.title = element.title;
  509. replacement.style.display = "block";
  510. replacement.style.width = getDimension(element, "width", "300px");
  511. if (tagName == "audio") {
  512. replacement.style.height = "26px";
  513. } else {
  514. replacement.style.height = getDimension(element, "height", "200px");
  515. }
  516. // Replace the element with the div.
  517. element.parentNode.replaceChild(replacement, element);
  518. var preload = (element.getAttribute("preload") || "").toLowerCase();
  519. // Activate flowplayer.
  520. var playlist = [];
  521. if (poster) {
  522. playlist.push({url: fixPath(poster)});
  523. }
  524. if (src) {
  525. playlist.push({
  526. url: fixPath(src),
  527. autoPlay: hasAttr(element, "autoplay"),
  528. autoBuffering: hasAttr(element, "autobuffer") || (hasAttr(element, "preload") && (preload === "" || preload == "auto")),
  529. onBeforeFinish: function() {
  530. return !hasAttr(element, "loop");
  531. }
  532. });
  533. }
  534. // Determine which plugins should be loaded.
  535. var plugins = {
  536. controls: hasControls && {
  537. url: fixPath(html5media.flowplayerControlsSwf),
  538. opacity: 0.8,
  539. backgroundColor: "#181818",
  540. backgroundGradient: "none",
  541. fullscreen: tagName == VIDEO_TAG,
  542. autoHide: tagName == VIDEO_TAG && {
  543. fullscreenOnly: false,
  544. enabled: true,
  545. hideStyle: "fade",
  546. mouseOutDelay: 0
  547. } || {
  548. enabled: false
  549. }
  550. } || null
  551. };
  552. // HACK: Opera cannot autohide controls, for some reason.
  553. if (isOpera && plugins.controls) {
  554. plugins.controls.autoHide.enabled = false;
  555. }
  556. // Audio-specific config.
  557. if (tagName == "audio") {
  558. // Load the audio plugin.
  559. plugins.audio = {
  560. url: fixPath(html5media.flowplayerAudioSwf)
  561. };
  562. // HACK: The Flowplayer audio plugin requires that the controls plugin is present.
  563. if (!hasControls) {
  564. plugins.controls = {
  565. url: fixPath(html5media.flowplayerControlsSwf),
  566. display: "none"
  567. };
  568. replacement.style.height = 0;
  569. }
  570. // HACK: Disable autoBuffering, since a flowplayer audio bug can cause uncontrollable autoplaying.
  571. playlist[playlist.length - 1].autoBuffering = false;
  572. }
  573. // Load the Flowplayer.
  574. var config = {
  575. play: null,
  576. playlist: playlist,
  577. clip: {
  578. scaling: "fit",
  579. fadeInSpeed: 0,
  580. fadeOutSpeed: 0
  581. },
  582. canvas: {
  583. backgroundGradient: "none",
  584. backgroundColor: "#000000"
  585. },
  586. plugins: plugins
  587. };
  588. config = html5media.configureFlowplayer(element, config);
  589. flowplayer(replacement, {
  590. src: fixPath(html5media.flowplayerSwf),
  591. expressInstall: fixPath(html5media.expressInstallSwf),
  592. wmode: "opaque"
  593. }, config);
  594. };
  595. // Automatically execute the html5media function on page load.
  596. DomReady.ready(html5media);
  597. // Expose html5media to the global object.
  598. window.html5media = html5media;
  599. })(this, document);