jquery实现优酷视频切换自动播放

我公司的站要求国内用户访问网站播放优酷视频,国外用户访问播放youtube视频

关于用户访问判断我已经解决了。请看  javascript判断是否为国内(国外)用户

下面来看如何实现优库视频切换播放。

js代码:

<script type=”text/javascript” language=”javascript”>
var vid=jQuery.noConflict();
function initurl() {
vid.ajax({
type:”GET”,
url:”/ip/checkip.php”,
dataType:”html”,
data:”&time=”+new Date(),
cache: false,
async: false,
beforeSend:function(XMLHttpRequest) {
},
success:function(msg) {
if(msg == 1){
vid(“.youtube”).hide();
vid(“.youkuv”).show();
vid(“#videoControls .youku”).show();
vid(“.youkuv .vmainbox”).ajaxStart(function(){
vid(this).show();
});
vid(“.youkuv .vmainbox”).ajaxStop(function(){
vid(this).hide();
});
vid(“.youkuv”).load(‘/wp/youku.html .XMzI3ODk1ODky’,function(){});
vid(“#videoControls .youku a”).eq(0).click(function(){
vid(“.youkuv”).load(‘/wp/youku.html .XMzI3ODk1ODky’,function(){});
});
vid(“#videoControls .youku a”).eq(1).click(function(){
vid(“.youkuv”).load(‘/wp/youku.html .XMzIwMTk0NDA4’,function(){});
});
vid(“#videoControls .youku a”).eq(2).click(function(){
vid(“.youkuv”).load(‘/wp/youku.html .XMzIwNzk3NTYw’,function(){});
});
vid(“#videoControls .youku a”).eq(3).click(function(){
vid(“.youkuv”).load(‘/wp/youku.html .XMzIzODY0NTgw’,function(){});
});
}
else {
//alert(‘I am not China ip’);
//location.href=”en”;
vid(“.youkuv”).hide();
vid(“#videoDiv”).show();
vid(“#videoControls .youtube”).show();
}
},
complete:function(XMLHttpRequest,textStatus) {

},
error:function() {

}
});
}

</script>

html代码:

<div>//class=youkuv
<div><img src=”<?php echo home_url(); ?>/img/loading-thumb.gif” width=”80″ height=”80″ border=”0″ ></div>
</div>
<div> //class=youtube
<div id=”videoDiv”><div><img src=”<?php echo home_url(); ?>/img/loading-thumb.gif” width=”80″ height=”80″ border=”0″ ></div></div>
</div>

<div>
<div id=”videoControls”>
<ul>//class=youtube
<li><a href=”#video” onClick=”loadVideo(‘P37bM0TOXMQ’);” title=”City of Steam: Classes & Combat Trailer “> <img src=”<?php echo home_url(); ?>/img/video5.jpg” /></a></li>
<li><a href=”#video” onClick=”loadVideo(‘0BH6OgJM7tc’);” title=”City of Steam: Gardenworks: First Look “> <img src=”<?php echo home_url(); ?>/img/video2.jpg”  /></a></li>
<li><a href=”#video” onClick=”loadVideo(‘BiwZJWOigE4’);” title=”City of Steam: Ebonwax Central: Revisited”> <img src=”<?php echo home_url(); ?>/img/video3.jpg”></a></li>
<li><a href=”#video” onClick=”loadVideo(‘4nFyN2JKBhk’);” title=”Mechanist Game -GDC China 2011″> <img src=”<?php echo home_url(); ?>/img/gdc_china_video.jpg”  /></a></li>
</ul>

<ul>//class=youku
<li><a href=”#video”  title=”City of Steam: Classes & Combat Trailer “> <img src=”<?php echo home_url(); ?>/img/video5.jpg” /></a></li>
<li><a href=”#video”  title=”City of Steam: Gardenworks: First Look “> <img src=”<?php echo home_url(); ?>/img/video2.jpg”  /></a></li>
<li><a href=”#video”  title=”City of Steam: Ebonwax Central: Revisited”> <img src=”<?php echo home_url(); ?>/img/video3.jpg”></a></li>
<li><a href=”#video”  title=”City of Steam Deepholm video”> <img src=”<?php echo home_url(); ?>/img/video4.jpg”  /></a></li>
</ul>
</div></div>

 

当然最前面还需要加入jquery

我这是新建了一个html文档,然后通过juqery加载html文档里面的视频播放代码就行了。

这个youku.html我放在了wp文件夹下。

代码如下:

<div>//class=”XMzI3ODk1ODky”
<embed src=”http://static.youku.com/v1.0.0206/v/swf/loader.swf?winType=index&VideoIDS=XMzI3ODk1ODky&embedid=&isAutoPlay=true” allowFullScreen=”true” quality=”high” width=”586″ height=”360″ align=”middle” allowScriptAccess=”always” type=”application/x-shockwave-flash”></embed></div>
<div>//class=”XMzIwMTk0NDA4″
<embed src=”http://static.youku.com/v1.0.0206/v/swf/loader.swf?winType=index&VideoIDS=XMzIwMTk0NDA4&embedid=&isAutoPlay=true” allowFullScreen=”true” quality=”high” width=”586″ height=”360″ align=”middle” allowScriptAccess=”always” type=”application/x-shockwave-flash”></embed></div>
<div>//class=”XMzIwNzk3NTYw”
<embed src=”http://static.youku.com/v1.0.0206/v/swf/loader.swf?winType=index&VideoIDS=XMzIwNzk3NTYw&embedid=&isAutoPlay=true” allowFullScreen=”true” quality=”high” width=”586″ height=”360″ align=”middle” allowScriptAccess=”always” type=”application/x-shockwave-flash”></embed></div>
<div>//class=”XMzIzODY0NTgw”
<embed src=”http://static.youku.com/v1.0.0206/v/swf/loader.swf?winType=index&VideoIDS=XMzIzODY0NTgw&embedid=&isAutoPlay=true” allowFullScreen=”true” quality=”high” width=”586″ height=”360″ align=”middle” allowScriptAccess=”always” type=”application/x-shockwave-flash”></embed></div>

 

结合上面js代码。你就可以看出来了。这里主要是判断控制按钮,不同要求出现不同按钮。

这样你就可以看到实现了视频切换功能!!

图: 实现网址:http://www.cityofsteam.com/