我想根據瀏覽器加載動態播放器,如使用對象標籤的activeX插件和使用嵌入標籤的Firefox和谷歌瀏覽器的vlc插件,所以我試圖加入它在腳本中,這樣的onload它可以檢測它是什麼瀏覽器,並根據但不幸的是,我發現了以下錯誤顯示播放器:通過腳本加載動態播放器的問題
無法獲得屬性的值「加」:對象爲空或未定義
以下是我的代碼:
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"> </script>
<script type="text/javascript">
var client = "FF";
$(document).ready(function(){
checkIE();
startUp();
//startIt();
$(function(){
$("#vlcIE").css({ "width": "400px", "height": "300px" });
});
});
function checkIE() {
var clientCheck = window.navigator.appName;
if (clientCheck == "Microsoft Internet Explorer") {
alert("IE");
client = "IE";
return true;
} else {
alert("FF");
client = "FF";
return false;
}
}
function startIt(){
if(client == "IE"){
playInIE();
}else{
playInOthers();
}
}
function playInOthers() {
alert("playin FF");
var players = document.getElementsByName("video1");
var options = new Array("");
url = "rtsp://184.72.239.149/vod/mp4:BigBuckBunny_115k.mov";
var id = players[0].playlist.add(url, null, options);
players[0].playlist.playItem(id);
alert("playing video");
}
function playInIE() {
alert("play in IE");
var vlc = document.getElementById("vlcIE");
var options = new Array(":aspect-ratio=16:10", "--rtsp-tcp");
//var options=[":ts-csa-ck="+EncryptionkeyValue];
var urlVideofile = "rtsp://184.72.239.149/vod/mp4:BigBuckBunny_115k.mov";
var targetURL = "rtsp://184.72.239.149/vod/mp4:BigBuckBunny_115k.mov";
var itemId = vlc.playlist.add(targetURL, "", options);
var id = vlc.playlist.add(urlVideofile, null, options);
vlc.playlist.playItem(id);
}
function startUp(){
var player;
if (client == "IE") {
player = "<object type='application/x-vlc-plugin' id='vlcIE' width='300' height='225' classid='clsid:9BE31822-FDAD-461B-AD51-BE1D1C159921' ></object>";
} else {
player = "<embed type='application/x-vlc-plugin' pluginspage='http://www.videolan.org' id='vlc' name='video1' autostart='yes' toolbar='false' loop='yes' width='400' height='300' target='rtsp://184.72.239.149/vod/mp4:BigBuckBunny_115k.mov' />";
}
//$("#video_holder").html(player);
document.getElementById("video_holder").innerHTML=player;
}
</script>
</head>
<body>
<div id="video_holder" style="border:1px solid #00FF33"></div>
<button type="button" id="start" onClick="startIt()">Start</button>
</body>
仍然給出相同的錯誤 – Priya
@Priya,我已經更新了我的答案,正確的代碼 – Mathlight
現在它給出了以下錯誤:Uncaught TypeError:無法讀取屬性'播放列表'未定義的行:var itemId = vlc .playlist.add(targetURL,「」,options); – Priya