用JavaScript js 控制 Media Player 播放器

來源:互聯網
上載者:User

 如果你的電腦上面找不到播放的音影檔案,可以用一張圖片代替;<br /><html><br /><head><br /><meta http-equiv="Content-Type" content="text/html; charset=gb2312"><br /><title>控制你的播放器</title><br /><script language="javascript" src="player.js"></script><br /><script language="JavaScript" for=WindowsMediaPlayer event=playstatechange(newstate)><br />switch(newstate) {<br />case 1:<br />playerinfo.innerHTML = "停止";<br />break;<br />case 2:<br />playerinfo.innerHTML = "暫停";<br />break;<br />case 3:<br />playerinfo.innerHTML = "現正播放";<br />break;<br />case 4:<br />playerinfo.innerHTML = "4";<br />break;<br />case 5:<br />playerinfo.innerHTML = "5";<br />break;<br />case 6:<br />playerinfo.innerHTML = "正在緩衝...";<br />break;<br />case 7:<br />playerinfo.innerHTML = "7";<br />break;<br />case 8:<br />playerinfo.innerHTML = "8";<br />break;<br />case 9:<br />playerinfo.innerHTML = "正在串連...";<br />break;<br />case 10:<br />playerinfo.innerHTML = "準備就緒";<br />break;<br />case 11:<br />playerinfo.innerHTML = "11";<br />break;<br />default:<br />playerinfo.innerHTML = "";<br />}<br /></script><br /></head></p><p><body><br /><table width="100%" border="0" cellpadding="0" cellspacing="0" id="table1"><br /><tr><br /><td colspan="2" align="center"><br /><object classid="clsid:6BF52A52-394A-11D3-B153-00C04F79FAA6" id="WindowsMediaPlayer" width="400" height="300"><br /><param name="URL" value=""><br /><param name="rate" value="1"><br /><param name="balance" value="0"><br /><param name="currentPosition" value="0"><br /><param name="defaultFrame" value=""><br /><param name="playCount" value=""><br /><param name="autoStart" value="0"><br /><param name="currentMarker" value="0"><br /><param name="invokeURLs" value="0"><br /><param name="baseURL" value=""><br /><param name="volume" value="100"><br /><param name="mute" value="-1"><br /><param name="uiMode" value="none"><br /><param name="stretchToFit" value="0"><br /><param name="windowlessVideo" value="0"><br /><param name="enabled" value="-1"><br /><param name="enableContextMenu" value="-1"><br /><param name="fullScreen" value="false"><br /><param name="SAMIStyle" value=""><br /><param name="SAMILang" value=""><br /><param name="SAMIFilename" value=""><br /><param name="captioningID" value=""><br /><param name="enableErrorDialogs" value="0"><br /></object><br /></td><br /></tr><br /><tr><br /><td height="20" colspan="2" align="center"><br /><font color=red><span id="playerinfo3"></span></font><br /></td><br /></tr><br /><tr><br /><td width="60%" height="20"><br /><input type="file" id="FileBtn" style="visibility: hidden"><br /><span id="playerinfo1"></span><br /><font color="blue"><span id="playerinfo2"></span></font><br /></td><br /><td width="40%" height="20"><br /><span id="playerinfo"></span><br /></td><br /></tr><br /><tr><br /><td colspan="2" align="center"><br /><input type="button" name="openfile" title="開啟檔案 "<br />onclick="openfile()" value="開啟檔案 "><br /><input type="button" name="play" title="播放" onclick="play();"<br />value="播放 "><br /><input type="button" name="pause" title="暫停" onclick="pause();"<br />value="暫停"><br /><input type="button" name="stop" title="停止" onclick="stop();"<br />value="停止 "><br /><input type="button" name="voldown" title="音量-"<br />onclick="voldown();" value="音量-"><br /><input type="button" name="volup" title="音量+"<br />onclick="volup();" value="音量+"><br /><input type="button" name="mute" title="靜音/" onclick="mute();"<br />value="靜音/"><br /><input type="button" name="balance" title="聲道"<br />onclick="balance();" value="聲道"><br /><input type="button" title="重新整理" onclick="location.reload();"<br />value="重新整理"><br /><input type="button" title="全屏" value="全屏"<br />onclick="fullScreen();"><br /></td><br /></tr><br /></table><br /></body><br /></html><br />

player.js

var state;<br />var varb;<br />var varfullscreen = 0;<br />function loop() {<br />WindowsMediaPlayer.playCount = 2;<br />}<br />function openfile() {<br />var fstr = "";<br />FileBtn.click();<br />if (FileBtn.value == "") {<br />return;<br />}<br />WindowsMediaPlayer.URL = FileBtn.value;<br />playerinfo1.innerHTML = "全聲道";<br />playerinfo3.innerHTML = " <b><font color=green>當前播放檔案的路徑和名稱是:</font></b>" + FileBtn.value;<br />}<br />function playerinit() {<br />WindowsMediaPlayer.url = "test.wmv"; //定義你自己的檔案<br />WindowsMediaPlayer.settings.autoStart = false;<br />}<br />function play() {<br />//if(WindowsMediaPlayer.URL= '')alert('請開啟檔案');return; onload= "playerinit()"<br />if (WindowsMediaPlayer.controls.isavailable("play")) {<br />WindowsMediaPlayer.controls.play();<br />state = setInterval("updatetime()", 1000);<br />playerinfo.innerHTML = "播放";<br />varfullscreen = 1;<br />playerinfo2.innerHTML = "音量:" + WindowsMediaPlayer.settings.volume;<br />}<br />}<br />function voldown() {<br />if (WindowsMediaPlayer.settings.volume < 5) {<br />WindowsMediaPlayer.settings.volume = 0;<br />playerinfo2.innerHTML = "音量:0";<br />playerinfo1.innerHTML = "0音量";<br />} else {<br />WindowsMediaPlayer.settings.volume -= 5;<br />playerinfo2.innerHTML = "音量:" + WindowsMediaPlayer.settings.volume;<br />playerinfo1.innerHTML = "非靜音";<br />}<br />}<br />function volup() {<br />if (WindowsMediaPlayer.settings.volume > 95) {<br />WindowsMediaPlayer.settings.volume = 100;<br />playerinfo2.innerHTML = "音量:100";<br />playerinfo1.innerHTML = "最大音";<br />} else {<br />WindowsMediaPlayer.settings.volume += 5;<br />playerinfo2.innerHTML = "音量:" + WindowsMediaPlayer.settings.volume;<br />playerinfo1.innerHTML = "非靜音";<br />}<br />}<br />function pause() {<br />if (WindowsMediaPlayer.controls.isavailable("pause")) {<br />WindowsMediaPlayer.controls.pause();<br />clearInterval(state);<br />playerinfo.innerHTML = "暫停";<br />varfullscreen = 1;<br />}<br />}<br />function stop() {<br />if (WindowsMediaPlayer.controls.isavailable("stop")) {<br />WindowsMediaPlayer.controls.stop();<br />clearInterval(state);<br />playerinfo.innerHTML = "停止";<br />varfullscreen = 0;<br />}<br />}<br />function mute() {<br />WindowsMediaPlayer.settings.mute = !WindowsMediaPlayer.settings.mute;<br />if (varb != 1) {<br />playerinfo1.innerHTML = "靜音中";<br />document.all.volup.disabled = true;<br />document.all.voldown.disabled = true;<br />document.all.balance.disabled = true;<br />varb = 1;<br />} else {<br />playerinfo1.innerHTML = "非靜音";<br />document.all.volup.disabled = false;<br />document.all.voldown.disabled = false;<br />document.all.balance.disabled = false;<br />varb = 0;<br />}<br />}<br />function balance() {<br />switch (WindowsMediaPlayer.settings.balance) {<br /> case 0:<br />WindowsMediaPlayer.settings.balance = 100;<br />playerinfo1.innerHTML = "左聲道";<br />break;<br /> case 100:<br />WindowsMediaPlayer.settings.balance = -100;<br />playerinfo1.innerHTML = "右聲道";<br />break;<br /> case -100:<br />WindowsMediaPlayer.settings.balance = 0;<br />playerinfo1.innerHTML = "全聲道";<br />break;<br /> default:<br />WindowsMediaPlayer.settings.balance = 0;<br />playerinfo1.innerHTML = "全聲道";<br />break;<br />}<br />}<br />function fullScreen() {<br />if (varfullscreen) {<br />WindowsMediaPlayer.fullScreen = true;<br />} else {<br />WindowsMediaPlayer.fullScreen = false;<br />}<br />//WindowsMediaPlayer.uiMode = "Invisible";//Full, Mini, None, Invisible設定外觀<br />}<br />function updatetime() {<br />if (WindowsMediaPlayer.controls.currentPositionString == "") {<br />playerinfo.innerHTML = "00:00" + "/" + WindowsMediaPlayer.currentMedia.durationString;<br />varfullscreen = 0;<br />} else {<br />playerinfo.innerHTML = WindowsMediaPlayer.controls.currentPositionString + "/" + WindowsMediaPlayer.currentMedia.durationString;<br />}<br />}</p><p>

控制Media player的更多屬性方法參考:http://blog.csdn.net/IBM_hoojo/archive/2010/06/09/5658181.aspx

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.