⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 15-5 自定义播放列表.htm

📁 JAVASCRIPT完全自学手册,中源码的验证修订实例
💻 HTM
字号:
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=GB2312" />
<title>15-5  自定义播放列表</title>
<style>
* { font-size:12px; font-family:宋体, Arial; } /*规定了所有的字体样式*/
body { overflow:auto; }
a { color:blue; }
p { padding:0px; margin-top:0px; }
#playlist { width:140px; height:100px; }
</style>
<script>
//函数“$”根据指定字符串获取相应ID的对象
function $(str){ return(document.getElementById(str)); }
//窗体载入完毕时初始化
window.onload = function(){
    //创建一个新的播放列表
    $("hutia").currentPlaylist = $("hutia").PlaylistCollection.newPlaylist("默认1");
    //初始化列表框对象的鼠标双击事件
    $("playlist").ondblclick = function(){
        //停止当前的媒体播放
        $("hutia").controls.stop();
        //跳转到所选择的播放列表中的媒体
        $("hutia").controls.currentItem = $("hutia").currentPlaylist.item(this.selectedIndex);
        //播放
        $("hutia").controls.play();
    }
}

//向播放列表中添加新的媒体文件
function addMedia(){
    var obj, strFilePath, strFileName, media;
    //创建一个新的文件选择输入框
    obj = document.createElement("input");
    obj.type = "file"; obj.style.display = "none";
    document.body.appendChild(obj);
    //模拟其鼠标单击事件,以弹出文件选择对话框
    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”对象
    media = $("hutia").newMedia(strFilePath);
    //将新“Media”对象插入当前播放列表中
    $("hutia").currentPlaylist.appendItem(media);
}

</script>
</head>
<body>
<!-- Windows Media Player 控件,设置其尺寸为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>
<!-- 用于显示播放列表的列表框对象容器 -->
<select id="playlist" size="2"></select>
</body>
</html>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -