?? 15-5 自定義播放列表.htm
字號(hào):
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=GB2312" />
<title>15-5 自定義播放列表</title>
<style>
* { font-size:12px; font-family:宋體, Arial; } /*規(guī)定了所有的字體樣式*/
body { overflow:auto; }
a { color:blue; }
p { padding:0px; margin-top:0px; }
#playlist { width:140px; height:100px; }
</style>
<script>
//函數(shù)“$”根據(jù)指定字符串獲取相應(yīng)ID的對(duì)象
function $(str){ return(document.getElementById(str)); }
//窗體載入完畢時(shí)初始化
window.onload = function(){
//創(chuàng)建一個(gè)新的播放列表
$("hutia").currentPlaylist = $("hutia").PlaylistCollection.newPlaylist("默認(rèn)1");
//初始化列表框?qū)ο蟮氖髽?biāo)雙擊事件
$("playlist").ondblclick = function(){
//停止當(dāng)前的媒體播放
$("hutia").controls.stop();
//跳轉(zhuǎn)到所選擇的播放列表中的媒體
$("hutia").controls.currentItem = $("hutia").currentPlaylist.item(this.selectedIndex);
//播放
$("hutia").controls.play();
}
}
//向播放列表中添加新的媒體文件
function addMedia(){
var obj, strFilePath, strFileName, media;
//創(chuàng)建一個(gè)新的文件選擇輸入框
obj = document.createElement("input");
obj.type = "file"; obj.style.display = "none";
document.body.appendChild(obj);
//模擬其鼠標(biāo)單擊事件,以彈出文件選擇對(duì)話框
obj.click();
strFilePath = obj.value;
//移除文件選擇輸入框
document.body.removeChild(obj);
//如果用戶沒有選擇文件則退出程序
if(strFilePath=="")return;
//獲取文件名
strFileName = strFilePath.match(/[^\\\/]+$/)[0].replace(/\.[^\.]+$/,"");
//向列表框中添加新的元素
$("playlist").options[$("playlist").options.length] = new Option(strFileName, strFilePath);
//生成新的“Media”對(duì)象
media = $("hutia").newMedia(strFilePath);
//將新“Media”對(duì)象插入當(dāng)前播放列表中
$("hutia").currentPlaylist.appendItem(media);
}
</script>
</head>
<body>
<!-- Windows Media Player 控件,設(shè)置其尺寸為0*0,因此其被隱藏 -->
<OBJECT ID="hutia" height="0" width="0"
CLASSID="CLSID:6BF52A52-394A-11d3-B153-00C04F79FAA6">
<param name="AutoStart" value="False" />
</OBJECT>
<p>
播放列表
<a href="#" onclick="addMedia();return(false);">添加</a>
</p>
<!-- 用于顯示播放列表的列表框?qū)ο笕萜?-->
<select id="playlist" size="2"></select>
</body>
</html>
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -