在網頁上播放警報或音樂
Posted In:
Javascript
,
WindowsMediaPlayer
.
By 卡西卡
目標:由playlist.mp3控制播放內容(可空或多首),播完10秒後重新載入本頁。
說明:
- playlist.mp3可以是真的mp3音樂檔,或是內容為多首mp3網址(一行一首)的文字檔。
- playlist.mp3的內容由server端控制,可依警報或時間或隨機產生內容。
[body]
<OBJECT id=player type=application/x-oleobject height=1 width=1
classid='CLSID:6BF52A52-394A-11d3-B153-00C04F79FAA6' >
<PARAM NAME="URL" VALUE="playlist.mp3">
<PARAM NAME="rate" VALUE="1">
<PARAM NAME="playCount" VALUE="1">
<PARAM NAME="autoStart" VALUE="true">
<PARAM NAME="baseURL" VALUE="">
<PARAM NAME="volume" VALUE="100">
<PARAM NAME="mute" VALUE="0">
<PARAM NAME="uiMode" VALUE="none">
</OBJECT>
[/body]
接收PlayStateChange[msdn]事件
[script]
window.onload = function() {
var player = document.getElementById('player');
player.attachEvent("playstatechange",MediaPlayer_playStateChange);
}
function MediaPlayer_playStateChange(newState) {
if ( newState == 10/*Ready*/ ) {
// 10秒後重新載入
window.setTimeout("document.location.reload();", 1000*10);
} // if
}
[/script]
參考資料:
- Windows Media Player Reference - W3Schools
- Using the Windows Media Player Control with Firefox - MSDN
- Player.playState - MSDN
Value State Description 0 Undefined Windows Media Player is in an undefined state. 1 Stopped Playback of the current media item is stopped. 2 Paused Playback of the current media item is paused. When a media item is paused, resuming playback begins from the same location. 3 Playing The current media item is playing. 4 ScanForward The current media item is fast forwarding. 5 ScanReverse The current media item is fast rewinding. 6 Buffering The current media item is getting additional data from the server. 7 Waiting Connection is established, but the server is not sending data. Waiting for session to begin. 8 MediaEnded Media item has completed playback. 9 Transitioning Preparing new media item. 10 Ready Ready to begin playing. 11 Reconnecting Reconnecting to stream. - ASX Elements Reference - MSDN
Advanced Stream Redirector (ASX) files are based on the Extensible Markup Language (XML) syntax, and are made up of various elements with their associated tags and attributes.
0 Responses to 在網頁上播放警報或音樂
Something to say?