//是否安装了flash |
function flashChecker() { |
var hasFlash = 0; //是否安装了flash |
var flashVersion = 0; //flash版本 |
if (document.all) { |
var swf = new ActiveXObject('ShockwaveFlash.ShockwaveFlash'); |
if (swf) { |
hasFlash = 1; |
VSwf = swf.GetVariable("$version"); |
flashVersion = parseInt(VSwf.split(" ")[1].split(",")[0]); |
} |
} else { |
if (navigator.plugins && navigator.plugins.length > 0) { |
var swf = navigator.plugins["Shockwave Flash"]; |
if (swf) { |
hasFlash = 1; |
var words = swf.description.split(" "); |
for (var i = 0; i < words.length; ++i) { |
if (isNaN(parseInt(words[i]))) continue; |
flashVersion = parseInt(words[i]); |
} |
} |
} |
} |
return { f: hasFlash, v: flashVersion }; |
} |
var isSafari = /Safari/.test(navigator.userAgent)// Safari浏览器 |
var oScriptFirst = document.getElementsByTagName('script')[0];//页面中第一个script标签 |
var newScript = document.createElement('script');//创建一个script标签 |
if(isSafari){ |
newScript.src=videojsURL;//设置src |
var ovideo = document.getElementById('example-video');//获取video标签 |
var osource =ovideo.getElementsByTagName('source')[0]; |
osource.setAttribute('src',om3u8); |
}else{ |
if(!flashChecker().f){ |
var str = '您没有安装flash请下载安装<a target="_blank" href="https://get2.adobe.com/cn/flashplayer/" target="_blank" rel="external nofollow" style="color:#c90000">点击下载</a>'; |
$("#video_box").html(str).attr("style","line-height: 400px;text-align: center;font-size: 16px;"); |
}else{ |
var videoObject = { |
container: '#video_box',//“#”代表容器的ID,“.”或“”代表容器的class |
variable: 'player',//该属性必需设置,值等于下面的new chplayer()的对象 |
autoplay:true, |
live:false,//直播为true;时移false |
poster:my_pic, |
video:om3u8//视频地址 |
}; |
var player=new ckplayer(videoObject); |
} |
} |
oScriptFirst.parentNode.insertBefore(newScript,oScriptFirst);//videojs插入第一个script元素之前 |
newScript.onload = function(){//js加载完毕调用初始化 |
if(isSafari){ |
videojs('example-video',{ |
controls: true,//是否控制条 |
autoplay: true,//自动播放 |
preload: 'auto'//预加载 |
},function(){ |
this.on('playing', function() { |
ovideo.muted = false; |
}); |
}); |
} |
}; |