<script src="//www.chinanews.com/m/part/shipin/6/78/vdeojs6.0.min.js"></script>
<script>
$(function () {
var videoTotal = 0;
var videoObj = [];
var myPlayer = null;
if(isIEVer(7) || isIEVer(8) || isIEVer(6)){//低版本使用flash
addElement();
}
$(".eachVideoAttr").each(function(index){
console.log("index:",index);
var videoUrl = $(this).children(".videoUrl").val();
var picUrl = $(this).children(".picUrl").val()==""?'http://www.chinanews.com/fileftp/2016/12/2016-12-20/U719P4T47D37869F969DT20161220090816.png':$(this).children(".picUrl").val();
var title = $(this).children(".videoTitle").val();
//console.log("第" + index + "个:",videoUrl);
if(!!videoUrl){
var obj = {};
obj.videoUrl = videoUrl;
obj.picUrl = picUrl;
obj.videoTitle = title;
videoObj.push(obj);
videoTotal++;
}
})
console.log("videoTotal:",videoTotal);
console.log("videoObj:",videoObj);
switchVideo(videoObj[0].videoUrl,videoObj[0].picUrl);
var rightHtml = "";
var leftHtml = "";
/*切换视频*/
$(".videolist li").click(function(){
$(this).addClass("current");
$(this).siblings().removeClass("current");
var index = $(this).index();
var videoUrl = videoObj[index].videoUrl;
//alert("当前视频地址:" + videoUrl);
var picUrl = videoObj[index].picUrl;
var title = videoObj[index].videoTitle;
switchVideo(videoUrl,picUrl);
});
})
function switchVideo(videoUrl,picUrl){
if(/.mp4$/ig.test(videoUrl)){
if(isIEVer(7) || isIEVer(8) || isIEVer(9)){
$(".videoHtml,.iframeObj").addClass("isShow");
$(".videoHtml source,.iframeObj").attr("src","");
if(!!$(".flashObj")){
$(".flashObj").remove();
}
$(".videoLeft").append('
');
}else{
$(".flashObj").remove();
$(".iframeObj").attr("src","");
$(".iframeObj").addClass("isShow");
$(".videoHtml").removeClass("isShow");
$(".videoHtml").attr("poster",picUrl);
$(".videoHtml source").attr("src",videoUrl);
var myPlayer = videojs("myVideo");
myPlayer.src(videoUrl);
myPlayer.load(videoUrl);
myPlayer.play();
}
}else{
$(".flashObj").remove();
$(".videoHtml").addClass("isShow");
$(".videoHtml source").attr("src","");
$(".iframeObj").removeClass("isShow");
$(".iframeObj").attr("src",videoUrl);
}
}
function isIEVer(ieVer){
var b = document.createElement('b');
b.innerHTML = '';
return b.getElementsByTagName('i').length === 1;
}
function addElement(){
var divEle = document.createElement('div');
divEle.innerHTML = '浏览器版本过低,建议使用火狐、谷歌浏览器或360极速浏览器';
divEle.className = 'browserTips';
var firstChild = document.getElementById('alldiv');
try{
document.body.insertBefore(divEle,firstChild);
}catch(e){
}
}
</script>