📄 15-1 通用媒体播放器.htm
字号:
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=GB2312" />
<title>15-1 通用媒体播放器</title>
<style>
* { font-size:12px; font-family:宋体, Arial; } /*规定了所有的字体样式*/
body { overflow:auto; }
/* 定义了媒体播放器的背景和尺寸 */
#playerDIV {
background-image: url(../inc/img/15-1.gif);
width:300px;
height:200px;
}
</style>
<script>
//在全局变量中保存各个不同媒体播放控件的CLSID
var rmID="clsid:CFCDAA03-8BE4-11cf-B84B-0020AFBBCCFA";
var wmID="clsid:22D6F312-B0F6-11D0-94AB-0080C74C7E95";
var swfID="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000";
//在全局变量“thePlayer”中保存播放器控件对象
var thePlayer;
//函数“doPlay”根据需要播放的文件的URL判断,并载入相应的媒体播放器控件进行播放
function doPlay(fPath){
if(!fPath)fPath=document.getElementById("txtURL").value;
if(fPath==""||fPath==null)return(false);
fType=fPath.substring(fPath.lastIndexOf(".")+1).toLowerCase();
//如果原本存在播放器,则将播放器清空
if(thePlayer){
document.getElementById("theTurePlayerID").outerHTML="";
}
//建立新的播放器
thePlayer=document.createElement("object");
thePlayer.width="100%";
thePlayer.height="100%";
//播放器的默认显示状态为“隐藏”
thePlayer.style.display="none";
thePlayer.id="theTurePlayerID";
//将播放器插入文档中
document.getElementById("playerDIV").appendChild(thePlayer);
//根据文件后缀名判断媒体类型
switch(fType){
case "rm":case "rmvb":
thePlayer.classid=rmID;
with(thePlayer){
_ExtentX=12118;_ExtentY=8573;
AUTOSTART=-1;SHUFFLE=0;PREFETCH=0;
NOLABELS=0;CONTROLS="Imagewindow";
LOOP=0;NUMLOOP=0;CENTER=0;
MAINTAINASPECT=0;BACKGROUNDCOLOR="#000000";
}
thePlayer.Source=fPath;
thePlayer.DoPlay();
break;
case "swf":
thePlayer.classid=swfID;
thePlayer.movie=fPath;
break;
default:
thePlayer.classid=wmID;
thePlayer.fileName=fPath;
thePlayer.Play();
}
setTimeout("thePlayer.style.display='';",1000);
}
</script>
</head>
<body>
<div id="playerDIV" ></div>
<p>输入需要播放的文件的URL地址,或点击链接测试:</p>
<ul>
<li>
<input id="txtURL" /><input type=button onclick="doPlay();" value="Play" />
</li>
<li>
<a href="javascript:doPlay('test001.mp3');">"*.mp3"音乐文件(Windows Media Player)</a>
</li>
<li>
<a href="javascript:doPlay('test002.rm');">"*.rm"流媒体文件(Realone)</a>
</li>
<li>
<a href="javascript:doPlay('test003.swf');">Flash动画文件(Flash Player)</a>
</li>
</ul></p>
</body>
</html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -