(转)让所有浏览器支持HTML5 video视频标签_weixin_30480583的博客-程序员宅基地

技术标签: ViewUI  php  javascript  

转自http://www.zhangxinxu.com/wordpress/?p=661

 

一、前面的唠叨

我记得就是前几个月吧,有条消息说YouTube支持了HTML5视频嵌入标签video,好吧,我听说而已,因为我不是个擅长FQ的人,到底如何我也不得而知。

与主题不相关的HTML5方面的东西我就不多说了,对于video标签,获取大家都听说了,这个标签的功能如同现在HTML语言中的img标签,就现在,比如要链接并显示一张图片,可以这样子:

<img data-src="http://image.zhangxinxu.com/image/study/s/s256/mm1.jpg" />

结果就可以显示下面这张美女图片(张含韵小妹妹):

所以,在HTML5的时代里,基本上只要一个<video>标签加一个视频的src链接地址就可以播放视频了,对于开发人员来讲真是“酷毕了”(《神话》中经典台词)。

然而,当现实照进遐想,我们不得不去正视,现在,支持HTML5 video标签的浏览器寥寥无几。我知道chrome2以及Safari是支持的,看下面这张截自chrome 2的图:
chrome下HTML5 video视频截图 张鑫旭-鑫空间-鑫生活

使用的代码如下:

<video width="352" height="264" controls autobuffer>
	 <source src="../media/cat.mp4" type='video/mp4; codecs="avc1.42E01E, mp4a.40.2"'></source>
</video>

对于Opera浏览器,您可以参阅这篇上周才发表的文章“Everything you need to know about HTML5 video and audio

对于IE浏览器,那还不知道要等到猴年马月才等到支持HTML5 video标签的时候。然而,广大劳动人民的智慧是无穷无尽的,广大开发人员的智慧也会无穷无尽的。国外领先的web开拓者们通过js,已经实现了可以让各个主流浏览器支持video标签的方法。

二、主流浏览器支持video标签

方法很简单,只要调用一段js,就可以让主流浏览器实现video标签的视频播放。

此项目已经放到Google code上,您可以点击这里查看。

使用方法:
要想让主流浏览器都支持HTML5标签,使用非常简单,只要链接一个js文件就可以了。所以,只要您的页面上(头部或底部)有这么段代码:

<script src="http://html5media.googlecode.com/svn/trunk/src/html5media.min.js"></script>

就可以了。

对于HTML部分,使用类似下面:

<video src="video.mp4" width="320" height="240" controls autobuffer></video>

是不是很简单啊!

为了演示效果,我就直接把此js以及video标签签到这篇文章里,您将会在下面看到这段10秒钟的关于猫咪的视频,您可以切换IE或是Firefox或是chrome或是Safari观看(界面有差别的哦~~)。

 

(function(){
     function B(a){console.log("$f.fireEvent",[].slice.call(a))}function y(a){
     if(!a||typeof a!="object")return a;var d=new a.constructor;for(var c in a)if(a.hasOwnProperty(c))d[c]=y(a[c]);return d}function o(a,d){
     if(a){
     var c,p=0,f=a.length;if(f===undefined)for(c in a){
     if(d.call(a[c],c,a[c])===false)break}else for(c=a[0];p<f&&d.call(c,p,c)!==false;c=a[++p]);return a}}function s(a){
     return document.getElementById(a)}function w(a,d,c){
     if(typeof d!="object")return a;a&&d&&o(d,function(p,f){
     if(!c||
typeof f!="function")a[p]=f});return a}function z(a){
     var d=a.indexOf(".");if(d!=-1){
     var c=a.substring(0,d)||"*",p=a.substring(d+1,a.length),f=[];o(document.getElementsByTagName(c),function(){
     this.className&&this.className.indexOf(p)!=-1&&f.push(this)});return f}}function E(a){a=a||window.event;if(a.preventDefault){a.stopPropagation();a.preventDefault()}else{a.returnValue=false;a.cancelBubble=true}return false}function i(a,d,c){a[d]=a[d]||[];a[d].push(c)}function v(){
     return"_"+(""+Math.random()).substring(2,
10)}function n(a,d,c){
     function p(){
     function g(k){!f.isLoaded()&&f._fireEvent("onBeforeClick")!==false&&f.load();return E(k)}if($f(a)){$f(a).getParent().innerHTML="";F=$f(a).getIndex();t[F]=f}else{t.push(f);F=t.length-1}L=parseInt(a.style.height,10)||a.clientHeight;if(typeof d=="string")d={src:d};A=a.id||"fp"+v();G=d.id||A+"_api";d.id=G;c.playerId=A;if(typeof c=="string")c={clip:{url:c}};if(typeof c.clip=="string")c.clip={url:c.clip};c.clip=c.clip||{};if(a.getAttribute("href",2)&&!c.clip.url)c.clip.url=
a.getAttribute("href",2);h=new e(c.clip,-1,f);c.playlist=c.playlist||[c.clip];var q=0;o(c.playlist,function(){
     var k=this;if(typeof k=="object"&&k.length)k={url:""+k};o(c.clip,function(u,C){
     if(C!==undefined&&k[u]===undefined&&typeof C!="function")k[u]=C});c.playlist[q]=k;k=new e(k,q,f);j.push(k);q++});o(c,function(k,u){
     if(typeof u=="function"){h[k]?h[k](u):i(x,k,u);delete c[k]}});o(c.plugins,function(k,u){
     if(u)r[k]=new l(k,u,f)});if(!c.plugins||c.plugins.controls===undefined)r.controls=new l("controls",
null,f);r.canvas=new l("canvas",null,f);d.bgcolor=d.bgcolor||"#000000";d.version=d.version||[9,0];d.expressInstall="http://www.flowplayer.org/swf/expressinstall.swf";D=a.innerHTML;if(D.replace(/\s/g,"")!=="")if(a.addEventListener)a.addEventListener("click",g,false);else a.attachEvent&&a.attachEvent("onclick",g);else{a.addEventListener&&a.addEventListener("click",E,false);f.load()}}var f=this,m=null,D,h,j=[],r={},x={},A,G,F,J,M,L;w(f,{id:function(){
     return A},isLoaded:function(){
     return m!==null},getParent:function(){
     return a},
hide:function(g){
     if(g)a.style.height="0px";if(m)m.style.height="0px";return f},show:function(){a.style.height=L+"px";if(m)m.style.height=M+"px";return f},isHidden:function(){
     return m&&parseInt(m.style.height,10)===0},load:function(g){
     if(!m&&f._fireEvent("onBeforeLoad")!==false){o(t,function(){
     this.unload()});if((D=a.innerHTML)&&!flashembed.isSupported(d.version))a.innerHTML="";flashembed(a,d,{config:c});if(g){g.cached=true;i(x,"onLoad",g)}}return f},unload:function(){
     if(D.replace(/\s/g,"")!==""){
     if(f._fireEvent("onBeforeUnload")===
false)return f;try{
     if(m){m.fp_close();f._fireEvent("onUnload")}}catch(g){}m=null;a.innerHTML=D}return f},getClip:function(g){
     if(g===undefined)g=J;return j[g]},getCommonClip:function(){
     return h},getPlaylist:function(){
     return j},getPlugin:function(g){
     var q=r[g];if(!q&&f.isLoaded()){
     var k=f._api().fp_getPlugin(g);if(k){q=new l(g,k,f);r[g]=q}}return q},getScreen:function(){
     return f.getPlugin("screen")},getControls:function(){
     return f.getPlugin("controls")},getConfig:function(g){
     return g?y(c):c},getFlashParams:function(){
     return d},
loadPlugin:function(g,q,k,u){
     if(typeof k=="function"){u=k;k={}}var C=u?v():"_";f._api().fp_loadPlugin(g,q,k,C);q={};q[C]=u;u=new l(g,null,f,q);return r[g]=u},getState:function(){
     return m?m.fp_getState():-1},play:function(g,q){
     function k(){g!==undefined?f._api().fp_play(g,q):f._api().fp_play()}m?k():f.load(function(){k()});return f},getVersion:function(){
     if(m){
     var g=m.fp_getVersion();g.push("flowplayer.js 3.1.4");return g}return"flowplayer.js 3.1.4"},_api:function(){
     if(!m)throw"Flowplayer "+f.id()+
" not loaded when calling an API method";return m},setClip:function(g){f.setPlaylist([g]);return f},getIndex:function(){
     return F}});o("Click*,Load*,Unload*,Keypress*,Volume*,Mute*,Unmute*,PlaylistReplace,ClipAdd,Fullscreen*,FullscreenExit,Error,MouseOver,MouseOut".split(","),function(){
     var g="on"+this;if(g.indexOf("*")!=-1){g=g.substring(0,g.length-1);var q="onBefore"+g.substring(2);f[q]=function(k){i(x,q,k);return f}}f[g]=function(k){i(x,g,k);return f}});o("pause,resume,mute,unmute,stop,toggle,seek,getStatus,getVolume,setVolume,getTime,isPaused,isPlaying,startBuffering,stopBuffering,isFullscreen,toggleFullscreen,reset,close,setPlaylist,addClip,playFeed".split(","),
function(){
     var g=this;f[g]=function(q,k){
     if(!m)return f;var u=null;u=q!==undefined&&k!==undefined?m["fp_"+g](q,k):q===undefined?m["fp_"+g]():m["fp_"+g](q);return u==="undefined"||u===undefined?f:u}});f._fireEvent=function(g){
     if(typeof g=="string")g=[g];var q=g[0],k=g[1],u=g[2],C=g[3],H=0;c.debug&&B(g);if(!m&&q=="onLoad"&&k=="player"){m=m||s(G);M=m.clientHeight;o(j,function(){
     this._fireEvent("onLoad")});o(r,function(N,K){K._fireEvent("onUpdate")});h._fireEvent("onLoad")}if(!(q=="onLoad"&&k!="player")){
     if(q==
"onError")if(typeof k=="string"||typeof k=="number"&&typeof u=="number"){k=u;u=C}if(q=="onContextMenu")o(c.contextMenu[k],function(N,K){K.call(f)});else if(q=="onPluginEvent"){
     if(C=r[k.name||k]){C._fireEvent("onUpdate",k);C._fireEvent(u,g.slice(3))}}else{
     if(q=="onPlaylistReplace"){j=[];var O=0;o(k,function(){j.push(new e(this,O++,f))})}if(q=="onClipAdd"){
     if(k.isInStream)return;k=new e(k,u,f);j.splice(u,0,k);for(H=u+1;H<j.length;H++)j[H].index++}var I=true;if(typeof k=="number"&&k<j.length){J=k;if(g=
j[k])I=g._fireEvent(q,u,C);if(!g||I!==false)I=h._fireEvent(q,u,C,g)}o(x[q],function(){I=this.call(f,k,u);this.cached&&x[q].splice(H,1);if(I===false)return false;H++});return I}}};typeof a=="string"?flashembed.domReady(function(){
     var g=s(a);if(g){a=g;p()}else throw"Flowplayer cannot access element: "+a;}):p()}function b(a){
     this.length=a.length;this.each=function(d){o(a,d)};this.size=function(){
     return a.length}}var e=function(a,d,c){
     var p=this,f={},m={};p.index=d;if(typeof a=="string")a={url:a};w(this,
a,true);o("Begin*,Start,Pause*,Resume*,Seek*,Stop*,Finish*,LastSecond,Update,BufferFull,BufferEmpty,BufferStop".split(","),function(){
     var h="on"+this;if(h.indexOf("*")!=-1){h=h.substring(0,h.length-1);var j="onBefore"+h.substring(2);p[j]=function(r){i(m,j,r);return p}}p[h]=function(r){i(m,h,r);return p};if(d==-1){
     if(p[j])c[j]=p[j];if(p[h])c[h]=p[h]}});w(this,{onCuepoint:function(h,j){
     if(arguments.length==1){f.embedded=[null,h];return p}if(typeof h=="number")h=[h];var r=v();f[r]=[h,j];c.isLoaded()&&
c._api().fp_addCuepoints(h,d,r);return p},update:function(h){w(p,h);c.isLoaded()&&c._api().fp_updateClip(h,d);var j=c.getConfig();w(d==-1?j.clip:j.playlist[d],h,true)},_fireEvent:function(h,j,r,x){
     if(h=="onLoad"){o(f,function(F,J){J[0]&&c._api().fp_addCuepoints(J[0],d,F)});return false}x=x||p;if(h=="onCuepoint"){
     var A=f[j];if(A)return A[1].call(c,x,r)}if(j&&"onBeforeBegin,onMetaData,onStart,onUpdate,onResume".indexOf(h)!=-1){w(x,j);if(j.metaData)if(x.duration)x.fullDuration=j.metaData.duration;else x.duration=
j.metaData.duration}var G=true;o(m[h],function(){G=this.call(c,x,j,r)});return G}});if(a.onCuepoint){
     var D=a.onCuepoint;p.onCuepoint.apply(p,typeof D=="function"?[D]:D);delete a.onCuepoint}o(a,function(h,j){
     if(typeof j=="function"){i(m,h,j);delete a[h]}});if(d==-1)c.onCuepoint=this.onCuepoint},l=function(a,d,c,p){
     var f={},m=this,D=false;p&&w(f,p);o(d,function(h,j){
     if(typeof j=="function"){f[h]=j;delete d[h]}});w(this,{animate:function(h,j,r){
     if(!h)return m;if(typeof j=="function"){r=j;j=500}if(typeof h==
"string"){
     var x=h;h={};h[x]=j;j=500}if(r){
     var A=v();f[A]=r}if(j===undefined)j=500;d=c._api().fp_animate(a,h,j,A);return m},css:function(h,j){
     if(j!==undefined){
     var r={};r[h]=j;h=r}d=c._api().fp_css(a,h);w(m,d);return m},show:function(){
     this.display="block";c._api().fp_showPlugin(a);return m},hide:function(){
     this.display="none";c._api().fp_hidePlugin(a);return m},toggle:function(){
     this.display=c._api().fp_togglePlugin(a);return m},fadeTo:function(h,j,r){
     if(typeof j=="function"){r=j;j=500}if(r){
     var x=
v();f[x]=r}this.display=c._api().fp_fadeTo(a,h,j,x);this.opacity=h;return m},fadeIn:function(h,j){
     return m.fadeTo(1,h,j)},fadeOut:function(h,j){
     return m.fadeTo(0,h,j)},getName:function(){
     return a},getPlayer:function(){
     return c},_fireEvent:function(h,j){
     if(h=="onUpdate"){
     var r=c._api().fp_getPlugin(a);if(!r)return;w(m,r);delete m.methods;if(!D){o(r.methods,function(){
     var x=""+this;m[x]=function(){
     var A=[].slice.call(arguments);A=c._api().fp_invoke(a,x,A);return A==="undefined"||A===undefined?m:A}});
D=true}}if(r=f[h]){r.apply(m,j);h.substring(0,1)=="_"&&delete f[h]}}})},t=[];window.flowplayer=window.$f=function(){
     var a=null,d=arguments[0];if(!arguments.length){o(t,function(){
     if(this.isLoaded()){a=this;return false}});return a||t[0]}if(arguments.length==1)if(typeof d=="number")return t[d];else{
     if(d=="*")return new b(t);o(t,function(){
     if(this.id()==d.id||this.id()==d||this.getParent()==d){a=this;return false}});return a}if(arguments.length>1){
     var c=arguments[1],p=arguments.length==3?arguments[2]:
{};if(typeof d=="string")if(d.indexOf(".")!=-1){
     var f=[];o(z(d),function(){f.push(new n(this,y(c),y(p)))});return new b(f)}else{
     var m=s(d);return new n(m!==null?m:d,c,p)}else if(d)return new n(d,c,p)}return null};w(window.$f,{fireEvent:function(){
     var a=[].slice.call(arguments),d=$f(a[0]);return d?d._fireEvent(a.slice(1)):null},addPlugin:function(a,d){n.prototype[a]=d;return $f},each:o,extend:w});if(typeof jQuery=="function")jQuery.prototype.flowplayer=function(a,d){
     if(!arguments.length||typeof arguments[0]==
"number"){
     var c=[];this.each(function(){
     var p=$f(this);p&&c.push(p)});return arguments.length?c[arguments[0]]:new b(c)}return this.each(function(){$f(this,y(a),d?y(d):{})})}})();
(function(){
     function B(){
     if(n.done)return false;var b=document;if(b&&b.getElementsByTagName&&b.getElementById&&b.body){clearInterval(n.timer);n.timer=null;for(b=0;b<n.ready.length;b++)n.ready[b].call();n.ready=null;n.done=true}}function y(b,e){
     if(e)for(key in e)if(e.hasOwnProperty(key))b[key]=e[key];return b}function o(b){
     switch(s(b)){
     case "string":b=b.replace(new RegExp('(["\\\\])',"g"),"\\$1");b=b.replace(/^\s?(\d+)%/,"$1pct");return'"'+b+'"';case "array":return"["+w(b,function(t){
     return o(t)}).join(",")+
"]";case "function":return'"function()"';case "object":var e=[];for(var l in b)b.hasOwnProperty(l)&&e.push('"'+l+'":'+o(b[l]));return"{"+e.join(",")+"}"}return String(b).replace(/\s/g," ").replace(/\'/g,'"')}function s(b){
     if(b===null||b===undefined)return false;var e=typeof b;return e=="object"&&b.push?"array":e}function w(b,e){
     var l=[];for(var t in b)if(b.hasOwnProperty(t))l[t]=e(b[t]);return l}function z(b,e){
     var l=y({},b),t=document.all;b='<object width="'+l.width+'" height="'+l.height+'"';if(t&&
!l.id)l.id="_"+(""+Math.random()).substring(9);if(l.id)b+=' id="'+l.id+'"';if(l.cachebusting)l.src+=(l.src.indexOf("?")!=-1?"&":"?")+Math.random();b+=l.w3c||!t?' data="'+l.src+'" type="application/x-shockwave-flash"':' classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"';b+=">";if(l.w3c||t)b+='<param name="movie" value="'+l.src+'" />';l.width=l.height=l.id=l.w3c=l.src=null;for(var a in l)if(l[a]!==null)b+='<param name="'+a+'" value="'+l[a]+'" />';a="";if(e){
     for(var d in e)if(e[d]!==null)a+=d+"="+
(typeof e[d]=="object"?o(e[d]):e[d])+"&";a=a.substring(0,a.length-1);b+='<param name="flashvars" value=\''+a+"' />"}b+="</object>";return b}function E(b,e,l){
     var t=flashembed.getVersion();y(this,{getContainer:function(){
     return b},getConf:function(){
     return e},getVersion:function(){
     return t},getFlashvars:function(){
     return l},getApi:function(){
     return b.firstChild},getHTML:function(){
     return z(e,l)}});var a=e.version,d=e.expressInstall,c=!a||flashembed.isSupported(a);if(c){e.onFail=e.version=e.expressInstall=
null;b.innerHTML=z(e,l)}else if(a&&d&&flashembed.isSupported([6,65])){y(e,{src:d});l={MMredirectURL:location.href,MMplayerType:"PlugIn",MMdoctitle:document.title};b.innerHTML=z(e,l)}else if(b.innerHTML.replace(/\s/g,"")===""){b.innerHTML="<h2>Flash version "+a+" or greater is required</h2><h3>"+(t[0]>0?"Your version is "+t:"You have no flash plugin installed")+"</h3>"+(b.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(b.tagName=="A")b.οnclick=function(){location.href="http://www.adobe.com/go/getflashplayer"}}if(!c&&e.onFail){a=e.onFail.call(this);if(typeof a=="string")b.innerHTML=a}if(document.all)window[e.id]=document.getElementById(e.id)}var i=typeof jQuery=="function",v={width:"100%",height:"100%",allowfullscreen:true,allowscriptaccess:"always",quality:"high",version:null,onFail:null,expressInstall:null,w3c:false,cachebusting:false};if(i){jQuery.tools=jQuery.tools||{};jQuery.tools.flashembed={version:"1.0.4",
conf:v}}var n=i?jQuery:function(b){
     if(n.done)return b();if(n.timer)n.ready.push(b);else{n.ready=[b];n.timer=setInterval(B,13)}};window.attachEvent&&window.attachEvent("onbeforeunload",function(){__flash_unloadHandler=function(){};__flash_savedUnloadHandler=function(){}});window.flashembed=function(b,e,l){
     if(typeof b=="string"){
     var t=document.getElementById(b);if(t)b=t;else{n(function(){flashembed(b,e,l)});return}}if(b){
     if(typeof e=="string")e={src:e};t=y({},v);y(t,e);return new E(b,t,l)}};y(window.flashembed,
{getVersion:function(){
     var b=[0,0];if(navigator.plugins&&typeof navigator.plugins["Shockwave Flash"]=="object"){
     var e=navigator.plugins["Shockwave Flash"].description;if(typeof e!="undefined"){e=e.replace(/^.*\s+(\S+\s+\S+$)/,"$1");b=parseInt(e.replace(/^(.*)\..*$/,"$1"),10);e=/r/.test(e)?parseInt(e.replace(/^.*r(.*)$/,"$1"),10):0;b=[b,e]}}else if(window.ActiveXObject){
     try{e=new ActiveXObject("ShockwaveFlash.ShockwaveFlash.7")}catch(l){
     try{e=new ActiveXObject("ShockwaveFlash.ShockwaveFlash.6");b=
[6,0];e.AllowScriptAccess="always"}catch(t){
     if(b[0]==6)return b}try{e=new ActiveXObject("ShockwaveFlash.ShockwaveFlash")}catch(a){}}if(typeof e=="object"){e=e.GetVariable("$version");if(typeof e!="undefined"){e=e.replace(/^\S+\s+(.*)$/,"$1").split(",");b=[parseInt(e[0],10),parseInt(e[2],10)]}}}return b},isSupported:function(b){
     var e=flashembed.getVersion();return e[0]>b[0]||e[0]==b[0]&&e[1]>=b[1]},domReady:n,asString:o,getHTML:z});if(i)jQuery.fn.flashembed=function(b,e){
     var l=null;this.each(function(){l=
flashembed(this,b,e)});return b.api===false?this:l}})();(function(){
     function B(){
     if(!i){i=true;if(v){
     for(var n=0;n<v.length;n++)v[n].call(window,[]);v=[]}}}function y(n){
     var b=window.onload;window.οnlοad=typeof window.onload!="function"?n:function(){b&&b();n()}}function o(){
     if(!E){E=true;document.addEventListener&&!z.opera&&document.addEventListener("DOMContentLoaded",B,false);z.msie&&window==top&&function(){
     if(!i){
     try{document.documentElement.doScroll("left")}catch(b){setTimeout(arguments.callee,0);return}B()}}();z.opera&&document.addEventListener("DOMContentLoaded",
function(){
     if(!i){
     for(var b=0;b<document.styleSheets.length;b++)if(document.styleSheets[b].disabled){setTimeout(arguments.callee,0);return}B()}},false);if(z.safari){
     var n;(function(){
     if(!i)if(document.readyState!="loaded"&&document.readyState!="complete")setTimeout(arguments.callee,0);else{
     if(n===undefined){
     for(var b=document.getElementsByTagName("link"),e=0;e<b.length;e++)b[e].getAttribute("rel")=="stylesheet"&&n++;b=document.getElementsByTagName("style");n+=b.length}document.styleSheets.length!=
n?setTimeout(arguments.callee,0):B()}})()}y(B)}}var s=window.DomReady={},w=navigator.userAgent.toLowerCase(),z={version:(w.match(/.+(?:rv|it|ra|ie)[\/: ]([\d.]+)/)||[])[1],safari:/webkit/.test(w),opera:/opera/.test(w),msie:/msie/.test(w)&&!/opera/.test(w),mozilla:/mozilla/.test(w)&&!/(compatible|webkit)/.test(w)},E=false,i=false,v=[];s.ready=function(n){o();i?n.call(window,[]):v.push(function(){
     return n.call(window,[])})};o()})();(function(B,y){
     function o(i,v){
     for(var n=[],b=0;b<i.length;b++)n.push(i[b]);for(b=0;b<n.length;b++)v(n[b])}function s(){o(y.getElementsByTagName("video"),function(i){
     var v=true;if(i.canPlayType)if(i.src&&i.canPlayType(w(i.src)))v=false;else o(i.getElementsByTagName("source"),function(n){
     if(i.canPlayType(w(n.src,n.type)))v=false});v&&s.createVideoFallback(i)})}function w(i,v){
     if(v)return v;return{avi:s.H264_FORMAT,mp4:s.H264_FORMAT,mkv:s.H264_FORMAT,h264:s.H264_FORMAT,"264":s.H264_FORMAT,avc:s.H264_FORMAT,
m4v:s.H264_FORMAT,"3gp":s.H264_FORMAT,"3gpp":s.H264_FORMAT,"3g2":s.H264_FORMAT,ogg:s.THEORA_FORMAT,ogv:s.THEORA_FORMAT}[i.split(".").slice(-1)[0]]||s.assumedFormat}function z(i,v){i=i.getAttribute(v);return i==true||typeof i=="string"}y.createElement("video").canPlayType||o(["abbr","article","aside","audio","canvas","details","figcaption","figure","footer","header","hgroup","mark","menu","meter","nav","output","progress","section","summary","time","video","source"],function(i){y.createElement(i)});
var E="";o(y.getElementsByTagName("script"),function(i){i=i.src;if(i.substr(i.length-17)=="html5media.min.js")E=i.split("/").slice(0,-1).join("/")+"/"});s.flowplayerSwf=E+"flowplayer.swf";s.flowplayerControlsSwf=E+"flowplayer.controls.swf";s.H264_FORMAT='video/mp4; codecs="avc1.42E01E, mp4a.40.2"';s.THEORA_FORMAT='video/ogg; codecs="theora, vorbis"';s.assumedFormat=s.H264_FORMAT;s.createVideoFallback=function(i){
     function v(c){
     if(c.substr(0,1)=="/")return n+c;return c}var n=B.location.protocol+"//"+
B.location.host,b=v(i.getAttribute("poster")||""),e=i.getAttribute("src");e||o(i.getElementsByTagName("source"),function(c){
     if(w(c.getAttribute("src"),c.getAttribute("type")).substr(0,9)=="video/mp4")e=c.getAttribute("src")});e=v(e||"");var l=y.createElement("span");l.id=i.id;l.className=i.className;l.title=i.title;l.style.display="block";l.style.width=i.getAttribute("width")+"px";l.style.height=i.getAttribute("height")+"px";i.parentNode.replaceChild(l,i);var t=(i.getAttribute("preload")||"").toLowerCase(),
a=null;if(z(i,"controls"))a={url:s.flowplayerControlsSwf,fullscreen:false,autoHide:"always"};var d=[];b&&d.push({url:b});if(e)d.push({url:e,autoPlay:z(i,"autoplay"),autoBuffering:z(i,"autobuffer")||z(i,"preload")&&(t==""||t=="auto"),onBeforeFinish:function(){
     return!z(i,"loop")}});flowplayer(l,s.flowplayerSwf,{play:null,playlist:d,clip:{scaling:"fit",fadeInSpeed:0,fadeOutSpeed:0},plugins:{controls:a}})};DomReady.ready(s);B.html5media=s})(this,document);
View Code

 

当加载完毕,点击播放按钮,就可以看到视频播放了。
或者您也可以狠狠地点击这里:HTML5 video多浏览器支持测试demo

三、一些说明

关于js
此js文件,您可以点击下面两处下载(右键 – [目标|链接]另存为):
1. 原项目地址下载
2. 鑫空间下载

关于实现
实现的原理大致是使用了flash技术,使用flash播放器嵌入视频的方式,使得IE及Firefox支持video标签。这个播放器称为flowplayer,具体我也不是很了解。

关于视频格式
目前,这种多浏览器支持方法所支持的视频格式有限,为mp4和ogv格式,否则视频可能不会播放。

可能遇到的问题
您可能会遇到这样的问题:我明明链接的是mp4格式的文件啊,为什么在IE及Firefox下有问题。如果您遇到的问题是在这两个浏览器下视频不播放,或是播放时只有声音而没有图像,而在chrome浏览器或是Safari下良好,则您可能要仔细您mp4文件的编码格式了。

对于编码,我不在行,好像是视频要存储为h.264文件,不要问我是什么东西,我也不知道,这可能还要靠您自己解决了。

最后,百无聊赖,先上一张Safari浏览器下的截图,原因是,Safari下的播放器真是卡哇伊。

Safari HTML5 video截图 张鑫旭-鑫空间-鑫生活

如果您发现文章中有表述不准确或是有相关问题需要交流可以通过评论或是去这里进行提问交流。
原创文章,转载请注明来自张鑫旭-鑫空间-鑫生活[http://www.zhangxinxu.com]
本文地址:http://www.zhangxinxu.com/wordpress/?p=661

转载于:https://www.cnblogs.com/mybabyyh/p/5158958.html

版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://blog.csdn.net/weixin_30480583/article/details/95842393

智能推荐

[多媒体][视频]压缩 、编码、信息熵_降低信息熵 压缩_ykun089的博客-程序员宅基地

为什么要编码?图像数据的原始数据量很大,因此在传输和存储之前需要进行压缩,否则占用的带宽开销和存储开销将是巨大的。因此需要对图像数据进行压缩,而压缩的一种手段就是对原数据进行编码。编码的一个重要目的是压缩,当然还有其他目的,比如加密。什么是信息熵?数据压缩会导致数据失真,或者说信息量丢失,这是显而易见的,但是同时也会带来数据量的缩减,那么如何衡量一个算法是否优秀呢?我们可以以 “损失的信息量与带来的数据压缩量的比率” 来表示一种信息量对数据量的比率关系。而用来表示信息量._降低信息熵 压缩

脉冲成形matlab代码,[转]MATLAB信号处理仿真-基带脉冲成形的数字滤波器-程序员宅基地

本次我们探讨另外一个在本科阶段让我们头痛的东西,通信原理之必考曲目,拼死也要背下来的内容,基带脉冲成形。然而俺对这个东西的理解和认识却是在本科以后的事情。早年(比如[黑][社][会]大佬用摩托罗拉的手机砸人的时代)的基带成形都是用模拟电路做的,那会儿的数字电路密度极低,想想大学本科数电实验里面的各种74系列芯片,如果用这个东西拼个数字滤波器估计会疯掉。况且,就算有数字滤波器,高速高精度的ADC、D...

cuda+cudnn安装-程序员宅基地

cuda+cudnn安装记录环境配置系统:ubuntu 18显卡:rtx 2080ticpu: e5 2678 v3tensorflow-gpu=1.14cuda=10.1cudnn7.6.5比较新的cuda已经自带显卡驱动了,所以已经不需要单独装显卡驱动了。。。软件下载准备传到网盘供下载。cuda安装将软件传到服务器上,进入软件目录:sudo sh cuda_10.1.105_418.39_linux.run按照指示一路确认即可。安装完后,要配置一下路径:vim ~/.

微信小程序可以打开公众号文章-程序员宅基地

微信今日晚间发布消息,宣布微信小程序基础能力、开发者工具全面升级,新增多项能力。基础功能方面:1、小程序新增打开公众号文章功能。可以打开已关联公众号的文章,不过文章内暂不支持赞赏、广告、关注公众号等。2、为提升服务质量,小程序新增“意见反馈”组件。用户可以在小程序内或小程序主页中反馈遇到的问题,开发者可以在小程序管理后台查看用户反馈内容以及操作日志。4、支持动态加载字体,让小程序获得最佳的视觉体验...

C格式化输入scanf()、sscanf()和fscanf()_scanf格式化-程序员宅基地

经常遇到文件、控制台和字符串为缓冲区的格式化输入输出,所以很有必要总结一下,争取毕其功于一役,以后遇到此类问题不再到处查阅。 C语言中的几种输入方式:scanf() 从控制台键盘输入;sscanf() 从字符串缓冲区输入与指定格式相符的数据;fscanf() 从文件输入;平时使用中遇到的最大问题就是这几个函数的参数弄不明白彻底;其实想搞明白这一点需要了解一下正则表..._scanf格式化

uboot启动流程-程序员宅基地

一、uboot说明1、uboot要做的事情CPU初始刚上电的状态。需要小心的设置好很多状态,包括cpu状态、中断状态、MMU状态等等。其次,就是要根据硬件资源进行板级的初始化,代码重定向等等。最后,就是进入命令行状态,等待处理命令。在armv7架构的uboot,主要需要做如下事情arch级的初始化关闭中断,设置svc模式禁用MMU、TLB关键寄存器的设置,包括时

随便推点

学习分享:RNN(持续更新)_rnn灾难性遗忘-程序员宅基地

目录1 RNN基础1.1 what RNN?1.2 why RNN?1.3 how RNN?1.3.1 隐含到隐含1.3.2 输出到隐含1.3.3 标签到隐含(导师驱动)1.4 RNN的问题2 Bi-RNN3 gated RNN3.1 LSTM3.2 窥孔LSTM3.3 耦合LSTM3.4 GRU参考1 RNN基础1.1 what RNN?用于处理序列数据(可变长)的NN1.2 why RNN?在模型不同部分,共享参数在几个时间步内,不需要分别学习权重也能能泛化到不同长度的样本 为什么每_rnn灾难性遗忘

Sql操作之二:不同数据库中表数据迁移_sql将不同库的表迁移到另一个库语句-程序员宅基地

一:在同一服务器insert into 数据库name1.dbo.table_name2(字段名称1,字段名称2,……)select 字段名称1,字段名称2,……from 数据库名称2.dbo.table_name2二:在不同服务器1.通过工具"DTS"的设计器进行导入或者导出DTS的设计器功能强大,支持多任务,也是可视化界面,容易操作_sql将不同库的表迁移到另一个库语句

《医间道》读后感<1>_医间道读书笔记-程序员宅基地

对中医感兴趣,朋友荐《医间道》一读果然写得不错,对于初学者并且自学中医的学生来说非常有用。为何学习中医?中医是教给人们养生的方法,教给人们预防和冶疗疾病的方法。学习中医就是让我们认识大自然,认识我们自身的身体,从而让我们去融入大自然,寻求健康生成的养生之道,寻求疾病的冶疗之道,每个人都可以学习中医,感受中医,因为学习中医就是感受我们身边的世界;因为学习中医就是内视我们自身的身体。_医间道读书笔记

win8鼠标设置的方法--win10专业版_w8的鼠标调节w10在哪-程序员宅基地

平时我们在一台新的电脑上玩游戏的时候,总会因为鼠标灵敏度而感觉到不适应,这个时候就需要调节鼠标灵敏度,那么windows 8怎么样调节鼠标灵敏度呢?其实很简单的,只要打开控制面板,找到硬件和声音,在里面设置即可,接下来让小编来给大家介绍一下windows8鼠标设置在哪吧。具体步骤如下:1、打开【控制面板】,找到【硬件和声音】。2、在【硬件和声音】界面上方找到【鼠标】。3、在【鼠标】界面对鼠标进行调整。4、点击鼠标中央的【DPI】按钮也可以对鼠标灵敏度进行调整。以上就是关于win8怎么样调_w8的鼠标调节w10在哪

jQuery Validator remote 远程Ajax校验器_<label>标签禁用远程验证-程序员宅基地

jQuery Validator remote 远程Ajax校验器中文手册 2016年05月26日 暂无评论jQuery Validator的remote远程校验器用于通过远程AJAX请求对指定输入进行校验。该校验器要求远程服务器端必须响应JSON对象字符串。语法jQuery Validator 1.0 新增。// 在校验规则对象中指定该属性r_标签禁用远程验证

CompletableFuture的简单应用-程序员宅基地

package com.zhao.sian.hah;import java.util.ArrayList;import java.util.List;import java.util.concurrent.CompletableFuture;import java.util.concurrent.ExecutionException;import java.util.concurre...