Javascript代码:
document.onreadystatechange = function () {
if (document.readyState == "complete") { // 页面加载完之后执行,必须;
// 获取HTML5播放器
// VideoJS会自动在Video标签的ID后自动加上_html5_api;
myVid=document.getElementById("xvast_player_html5_api");
// 获取播放器返回的详细信息,如果需要获取许可证,将会返回获取许可证的URL,
// 不然将会返回受保护文件的详细信息和许可证信息。
isSupp=myVid.canPlayType('xvast');
// 检测是否为手机访问
if(navigator.userAgent.indexOf("Mobile Xvast") > 0){
var con = window.navigator.connection;
var network = con.type; // 移动网络:cellular; 无线网络:wifi
// 检测手机是使用移动网络还是wifi
if (network == "cellular"){ // 如果手机使用移动网络,需要为页面添加获取许可证的按钮
document.getElementById("cellular_button").innerHTML = '播放加密的文件(点击两次)';
}
}
// 如果返回信息包含URL,说明需要获取许可证。
if(isSupp.indexOf("http")>0){
// 显示提示,非必须;
document.getElementById("LoadingText").style.display='block';
// 通过substring截取获取许可证的URL;
licURL = isSupp.substring(isSupp.indexOf("http"));
// 跳转到获取许可证页面验证并获取许可证。
window.location.href = licURL;
}
}
}
下面的方法提供参考,用来获取更多信息,包含许可证信息,非必须,根据您的需求添加。
function supportType(e,vidType,codType){
myVid=document.getElementById("xvast_player_html5_api");
isSupp=myVid.canPlayType("xvast");
myVid.play();
licURL = isSupp.substring(isSupp.indexOf("http"));
if(isSupp.indexOf("http")>0){
window.location.href = licURL;
}else{
if(isSupp.indexOf("License")>0){
// 获取打开次数
var openCount=isSupp.substring(isSupp.indexOf(":"),isSupp.indexOf(";"));
// 获取许可证的过期时间
var ft=isSupp.substring(isSupp.indexOf(";")+1);
var ut = filetime_to_unixtime(ft);
var d = new Date(ut * 1000);
e.target.parentNode.innerHTML ="打开次数" + openCount + ", 过期日期:" + d.toLocaleString();
return;
}
if(isSupp.indexOf("Error ID = 3")>0){
e.target.parentNode.innerHTML ="许可证已经过期。请关闭Xvast,重新打开受保护的文件,来获取新的许可证";
return;
}
}
}