<script> //---------这是区分播放器的音乐类型,你可以填加修改------// var RS = new Array("rm","ram","mp3","ra","asf","rp","rmm","png","m3u","mp2","mpa","rmvb","smil","smi"); //-----------播放器状态-------------// var Rstate = new Array("停止","连接","缓冲","播放","暂停"); var player_doing = false; function choose_player(sound_path) { sound_path = sound_path.split("."); var sound_type = sound_path[sound_path.length-1].toLowerCase(); for(i=0;i<RS.length;i++) { if(sound_type==RS[i]) return "R" } return "U"; } function Do_play() { var the_player = document.getElementById("player"); the_player.DoPlay(); } function Do_pause() { var the_player = document.getElementById("player"); the_player.DoPause(); } function Do_stop() { var the_player = document.getElementById("player"); the_player.DoStop(); } function Set_position(num) { var the_player = document.getElementById("player"); the_player.SetPosition(num); } function Get_position() { var the_player = document.getElementById("player"); return the_player.GetPosition(); } function Get_length() { var the_player = document.getElementById("player"); return the_player.GetLength(); } function Set_volume(num) { var the_player = document.getElementById("player"); the_player.SetVolume(num); } function Show_time(num) { var time_minute = Math.floor( num / 60000 ); var time_second = Math.floor( ( num - time_minute*60000 ) / 1000 ); if( time_minute < 10 ) time_minute = "0" + time_minute; if( time_second < 10 ) time_second = "0" + time_second; return (time_minute + ":" +time_second); } function Get_state() { var the_player = document.getElementById("player"); return the_player.GetPlayState(); } function player_play() { var just_type = choose_player(document.getElementById("sound_path").innerHTML); var the_player = document.getElementById("player"); var the_state = Get_state(); if(the_state==1||the_state==2||the_state==3) { return; } if(the_state==4) { Do_play(); } if(the_state==0) { if(just_type=="R") { Do_stop(); the_player.SetSource(document.getElementById("sound_path").innerHTML); Do_play(); if(player_doing) { clearInterval(player_doing) } player_doing = setInterval("Set_all()",500); } } } function Set_all() { var the_player = document.getElementById("player"); document.getElementById("position_box").innerHTML = Show_time(Get_position()); document.getElementById("length_box").innerHTML = Show_time(Get_length()); document.getElementById("state_box").innerHTML = Rstate[Get_state()]; var the_max = (document.getElementById("position_button_box").offsetWidth - document.getElementById("position_button").offsetWidth); document.getElementById("position_button").style.pixelLeft = Math.round(the_max*Get_position()/Get_length()); if(Get_state()==0) { clearInterval(player_doing); } } function Go_direction(num) { var the_player = document.getElementById("player"); var the_state = Get_state(); if(the_state==3) { var the_direction = num*1000; var judger = (Get_position() + the_direction) if(judger>=0&&judger<=Get_length()) { Set_position(judger); } } } var Ox,Nx; var move_obj_can_move = false; var move_obj = false; function start_move() { move_obj_can_move = true; move_obj = event.srcElement.id; document.getElementById(move_obj).setCapture(); Ox = event.clientX; } function document.onmouseup() { if(!move_obj) return; document.getElementById(move_obj).releaseCapture(); move_obj_can_move = false; move_obj = false; } function document.onmousemove() { if(!document.getElementById(move_obj)) { return; } //看看再什么样的条件下才能够滑动 if(move_obj=="position_button"&&(Get_state()!=3&&Get_state()!=4)) { return; } Nx = event.clientX; var judger = document.getElementById(move_obj).style.pixelLeft + Nx - Ox; var max = document.getElementById(move_obj+"_box").offsetWidth - document.getElementById(move_obj).offsetWidth; if(!move_obj_can_move||!move_obj||judger>max||judger<0) { return; } document.getElementById(move_obj).style.pixelLeft += Nx - Ox; eval(move_obj+"_event("+document.getElementById(move_obj).style.pixelLeft+","+max+")"); Ox = Nx; } function volume_button_event(s_num,b_num) { var judger = Math.round(100*s_num/b_num) if(judger>=0&&judger<=100) { Set_volume(judger) } } function position_button_event(s_num,b_num) { var judger = Math.round(Get_length()*s_num/b_num); if(judger>=0||judger<=Get_length()) { Set_position(judger) } } function changeurl() { var url="http://liudechao-pc:7070/ramgen//flash.smi"; var the_player = document.getElementById("player"); document.getElementById("sound_path").innerHTML=url; //the_player.SetSource(document.getElementById("sound_path").innerHTML); player_play(); } </script>
?
<table align="center" border="0" width="100%" cellspacing="0" cellpadding="0"> <tr> <td align="center"> <OBJECT ID="player" CLASSID="clsid:CFCDAA03-8BE4-11cf-B84B-0020AFBBCCFA" width="350" height="300" > <param name="CONTROLS" value="ImageWindow"> <embed src="" type="audio/x-pn-realaudio"> </OBJECT> <script event="OnStateChange(old,new)" for="player" language="javascript"> if(new==0&& old==3) alert("Over!"); </script> </td> </tr> </table> <table border="1" cellpadding="0" cellspacing="0" align="center" bordercolor="#CCCCCC"bgcolor="#6699CC"> <td> <input id="change" value="Change Audio" type="button" onClick="changeurl()"> </td> </table> <div class="AudioPlayer" id="musicPlayer"> <table align="center"> <tr> <td height="15" width="120"> <a onClick="player_play()" title="Play" href="javascript:void(0)"> <img alt="Play" src="/jlpt/JLPT/gif/play.gif" width="15" height="15"></a> <a onClick="Do_pause()" title="Pause" href="javascript:void(0)"> <img alt="Pause" src="/jlpt/JLPT/gif/Pause.gif" width="15" height="15"></a> <a onClick="Do_stop()" title="Stop" href="javascript:void(0)"> <img alt="Stop" src="/jlpt/JLPT/gif/stop.gif" width="15" height="15"></a> <a onClick="DoNextEntry()" title="Back" href="javascript:void(0)"> <img alt="Back" src="/jlpt/JLPT/gif/skipback.gif" width="15" height="15"></a> <a onClick="DoPrevEntry()" title="Next" href="javascript:void(0)"> <img alt="Next" src="/jlpt/JLPT/gif/skip.gif" width="15" height="15"></a> <!-- 后面两个是快进和后退,这两个功能不需要,研究一下函数或者是根据上面的代码实现一下播放列表的下一首和前一首 !--> </td> <td id="position_button_box" bgcolor="#C0C0C0" width="300"> <input id="position_button" type="button" style="position: relative; left:0; height: 20; width:10" onmousedown="start_move()"> </td> <td id="position_box" width="40" bgcolor="#6699FF" align="center"></td> <td id="length_box" width="40" bgcolor="#6699FF" align="center"></td> <td id="state_box" width="40" bgcolor="#6699FF"align="center"></td> <td id="audio"><a><img src="/jlpt/JLPT/gif/audio.gif" width="15" height="15"></a></td> <td id="volume_button_box" width="100" bgcolor="#C0C0C0"> <input id="volume_button" type="button" style="position: relative; left:20; height:20; width: 10" onMouseDown="start_move()"> </td> </tr> </table> </div> <div style="visibility:hidden" id="sound_path">http://localhost:7070/ramgen//shiyueweicheng.rmvb</div>
?js脚本利用RealPlayer提供的方法进行控制,HTML脚本进行一些美化方面的显示。
播放结束后的事件触发也做上了。real网页嵌入的一个问题:对于播放列表如ram等不能够
顺序播放(不能一首一首非常连续),解决方案是使用了smil将所有的连成了相当于一个文件,
但是此解决方案的弊端是:无法使用下一首或前一首按钮,只能是顺序播放。
PS:找到了一个中文版的关于网页嵌入REAL的官方说明,见附件,以后不用再上网找了。