一个页面中只有一个播放器
如http://player.youku.com/embed/XMTMwODg5OTcyMA
查看源代码:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<title>Youku Universal Player</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<style>
html, body { height:100%; }
body { margin:0; }
</style>
</head>
<body>
<div id="youku-playerBox" style="width:100%;height:100%;"></div>
<script id='_youkujs_' type="text/javascript"></script>
<script language="javascript">
// var wh = { };
window.onload = function(){
/*wh = function () {
var dimension = {};
dimension.width = window.innerWidth;
dimension.height = window.innerHeight;
//console.log(dimension);
return dimension;
}();*/
<!-- 这个页面是直接内嵌的,第三方用户不需要管 -->
<!-- 目前不支持starttime等动作参数 -->
var script = document.getElementById('_youkujs_');
script.src = 'http://player.youku.com/jsapi';
script.onload = script.onreadystatechange = function(){
if(!this.readyState || this.readyState == 'loaded' || this.readyState == 'complete'){
var _QS = QS();
<span style="color:#cccccc;"> /*QS.width = QS.width ? QS.width : wh.width;
QS.height = QS.height ? QS.height :wh.height;*/
var arr = window.location.pathname.split('/');
if(arr.length == 3 && arr[1] == 'embed' && arr[2].charAt(0) == 'X' ){
_QS.vid = arr[2];//这里只是对优酷地址的验证
}</span>
<span style="color:#ff0000;"> </span><u><span style="color:#ff0000;">_QS.vid = </span><span style="color:#ff6666;"><span style="background-color: rgb(255, 255, 255);">"</span><span style="background-color: rgb(255, 255, 255);">XNzAxMzExMzU2</span><span style="background-color: rgb(255, 255, 255);">"</span>;替换此ID即可</span></u>
if(_QS.target == null ) _QS.target = "youku-playerBox";
if(_QS.client_id == null) _QS.client_id = "0edbfd2e4fc91b72";//"youkuind_";
var _select = new YoukuPlayerSelect(_QS);
_select.select();
}
};
};
</script>
</body>
</html>
代码中引用的优酷jsapi,并对页面地址进行了判断,保证是优酷地址,提取出视频id
我们要播放优酷视频直接替换红字部分的id即可(可在视频播放页面地址中获取)