wmplayer.js 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296
  1. /////////////////////////////////////////////////////////////////////////////////////////////
  2. function Init(){
  3. // Initicalize State String
  4. WM_STATE[0]="播放已经停止";
  5. WM_STATE[1]="暂停播放";
  6. WM_STATE[2]="正在播放";
  7. WM_STATE[3]="等待媒体流开始……";
  8. WM_STATE[4]="正在快进……";
  9. WM_STATE[5]="正在快退……";
  10. WM_STATE[6]="正在搜索……";
  11. WM_STATE[7]="正在搜索……";
  12. WM_STATE[8]="没有打开的媒体流";
  13. WM_STATE[9]="Transitioning";
  14. WM_STATE[10]="Ready";
  15. }
  16. ///////////////////////////////////////////////////////////////////////////////////////////
  17. function GetStateFlag(){
  18. return Player.PlayState;
  19. }
  20. /////////////////////////////////////////////////////////////////////////////////////////////
  21. function GetStateString(flag){
  22. return WM_STATE[flag];
  23. }
  24. /////////////////////////////////////////////////////////////////////////////////////////////
  25. function StartStreamMonitor(){
  26. m_timer=window.setInterval("StreamMonitor()",1000);
  27. }
  28. /////////////////////////////////////////////////////////////////////////////////////////////
  29. function StreamMedia(){
  30. Play();
  31. }
  32. /////////////////////////////////////////////////////////////////////////////////////////////
  33. function StreamMonitor(){
  34. if(Player.DisplaySize!=3){
  35. strInfo="WindowsMedia 格式 ";
  36. if (BROD!=1){
  37. strInfo+="……视频点播";
  38. if(!DRAG_POS&&GetStateFlag()==2){
  39. myPosBar.style.left= TRACE_LEFT + Player.CurrentPosition/Player.Duration*TRACE_WIDTH-8;
  40. }
  41. }else{
  42. strInfo+="……网络直播";
  43. }
  44. strInfo+= GetStateString(GetStateFlag());//+(TRACE_LEFT+Player.CurrentPosition/Player.Duration*TRACE_WIDTH);
  45. if(Player.PlayState==2){
  46. m_current=Player.CurrentPosition;
  47. m_sec=Math.round(m_current)%60;
  48. m_min=Math.floor(m_current/60);
  49. m_hour=Math.floor(m_min/60);
  50. m_min=Math.round(m_min)%60;
  51. ShowTime(m_hour,m_min,m_sec);
  52. strInfo+="<BR>"
  53. strInfo+= (" 带宽:"+Math.round(Player.Bandwidth/1000)+"Kbps ");
  54. strInfo+=strMsg;
  55. }
  56. info.innerHTML=strInfo;
  57. }
  58. }
  59. /////////////////////////////////////////////////////////////////////////////////////////////
  60. //function _ShowInfo(){
  61. // strInfo="状态:";
  62. // strInfo=strInfo + GetStateString(GetStateFlag());
  63. // info.innerHTML=strInfo;
  64. // if(!DRAG_POS)
  65. // myPosBar.style.left= TRACE_LEFT + m_current*(TRACE_WIDTH/m_duration)-8;
  66. //
  67. // setTimeout("ShowInfo()",500);
  68. //}
  69. //
  70. /////////////////////////////////////////////////////////////////////////////////////////////
  71. function ShowBufferingPro(){
  72. if(Player.BufferingProgress<100){
  73. strMsg="正在缓冲……"+Player.BufferingProgress+"%";
  74. info.innerHTML=strMsg;
  75. setTimeout('ShowBufferingPro()',100);
  76. }else{
  77. strMsg="";
  78. }
  79. }
  80. function SetPos_Start(){
  81. if(Player.PlayState){
  82. DRAG_POS=true;
  83. CAN_SET_POS=false;
  84. }
  85. event.cancelBubble=true;
  86. }
  87. function SetPos(){
  88. if ((!DRAG_POS)&&(BROD!=1))
  89. {
  90. event.cancelBubble=true;
  91. event.returnValue=false;
  92. return false;
  93. }
  94. mouse_e_x=window.event.x;
  95. myPosBar.style.left=
  96. ((mouse_e_x>=(TRACE_LEFT+TRACE_WIDTH)) ? (TRACE_LEFT+TRACE_WIDTH):
  97. ((mouse_e_x<=TRACE_LEFT) ? TRACE_LEFT:mouse_e_x))-10;
  98. event.cancelBubble=true;
  99. }
  100. function SetPos_End(){
  101. if((!DRAG_POS)&&(BROD!=1))return;
  102. // Pause();
  103. CAN_SET_POS=true;
  104. Player.CurrentPosition =
  105. Math.round( Player.Duration *
  106. (parseInt(myPosBar.style.left)+10-TRACE_LEFT)/TRACE_WIDTH);
  107. // Play();
  108. DRAG_POS=false;
  109. event.cancelBubble=true;
  110. }
  111. /////////////////////////////////////////////////////////////////////////////////////////////
  112. function SetVol_Start(){
  113. DRAG_VOL=true;
  114. event.cancelBubble=true;
  115. }
  116. function SetVol(){
  117. if (!DRAG_VOL||event.button!=1)
  118. {
  119. event.cancelBubble=true;
  120. event.returnValue=false;
  121. return false;
  122. }
  123. mouse_e_x=window.event.x;
  124. myVolBar.style.left=mouse_e_x;
  125. myVolBar.style.left=(( mouse_e_x >= (VOL_TRACE_LEFT + VOL_TRACE_WIDTH )) ?
  126. ( VOL_TRACE_LEFT + VOL_TRACE_WIDTH ) :
  127. (( mouse_e_x <= VOL_TRACE_LEFT ) ?
  128. VOL_TRACE_LEFT : mouse_e_x ))-6;
  129. Player.Volume =
  130. 5000 * (( parseInt(myVolBar.style.left) + 6 - VOL_TRACE_LEFT ) /
  131. VOL_TRACE_WIDTH - 1);
  132. event.cancelBubble=true;
  133. }
  134. function SetVol_End(){
  135. DRAG_VOL=false;
  136. event.cancelBubble=true;
  137. }
  138. /////////////////////////////////////////////////////////////////////////////////////////////
  139. function SetMute(){
  140. IS_NUTE=!IS_NUTE;
  141. Player.Mute=IS_NUTE;
  142. mutebar.alt=(IS_NUTE)?"解除静音":"静音";
  143. }
  144. /////////////////////////////////////////////////////////////////////////////////////////////
  145. function SetBal_Start(){
  146. DRAG_BAL=true;
  147. event.cancelBubble=true;
  148. }
  149. function SetBal(){
  150. if (!DRAG_BAL)
  151. {
  152. event.cancelBubble=true;
  153. event.returnValue=false;
  154. return false;
  155. }
  156. mouse_e_x=window.event.x;
  157. myBalBar.style.left=mouse_e_x;
  158. myBalBar.style.left=(( mouse_e_x >= (BAL_TRACE_LEFT + BAL_TRACE_WIDTH )) ?
  159. ( BAL_TRACE_LEFT + BAL_TRACE_WIDTH ) :
  160. (( mouse_e_x <= BAL_TRACE_LEFT ) ? BAL_TRACE_LEFT : mouse_e_x ))-6;
  161. Player.Balance = -20000 * (( parseInt(myBalBar.style.left) + 6
  162. - BAL_TRACE_LEFT ) / BAL_TRACE_WIDTH )+10000;
  163. event.cancelBubble=true;
  164. }
  165. function SetBal_End(){
  166. DRAG_BAL=false;
  167. event.cancelBubble=true;
  168. }
  169. /////////////////////////////////////////////////////////////////////////////////////////////
  170. function FullScreen(){
  171. if (Player.PlayState!=2) return;//if not playing
  172. else{
  173. Player.DisplaySize=3;
  174. }
  175. }
  176. /////////////////////////////////////////////////////////////////////////////////////////////
  177. function SetPosition(pos){
  178. var seekpos=pos;
  179. if (seekpos<0) seekpos=Player.Duration-1;
  180. // Pause();
  181. seekpos=(seekpos>=Player.Duration)?Player.Duration:seekpos;
  182. seekpos=(seekpos<=0)?0:seekpos;
  183. Player.CurrentPosition=seekpos;
  184. // Play();
  185. }
  186. /////////////////////////////////////////////////////////////////////////////////////////////
  187. function _Seek(offset){
  188. var curpos=0;
  189. var seekpos=0;
  190. Pause();
  191. curpos=Player.CurrentPosition;
  192. seekpos=curpos+offset;
  193. seekpos=(seekpos>=Player.Duration)?Player.Duration:seekpos;
  194. seekpos=(seekpos<=0)?0:seekpos;
  195. Player.CurrentPosition=seekpos;
  196. Play();
  197. }
  198. /////////////////////////////////////////////////////////////////////////////////////////////
  199. function Play(){
  200. if (document.all.Player.PlayState==2||document.all.Player.OpenState<5) return;//if is playing
  201. document.all.Player.Play();
  202. document.all.playpause.alt="播放";
  203. // document.all.playpause.src="images/pause_d.gif";
  204. }
  205. /////////////////////////////////////////////////////////////////////////////////////////////
  206. function Pause(){
  207. if (document.all.Player.PlayState!=2) return;//if not playing
  208. document.all.Player.Pause();
  209. document.all.playpause.alt="暂停";
  210. // document.all.playpause.src="images/play_d.gif";
  211. }
  212. /////////////////////////////////////////////////////////////////////////////////////////////
  213. function Stop(){
  214. if (document.all.Player.PlayState==0||document.all.Player.PlayState==8)
  215. return;
  216. document.all.Player.Stop();
  217. document.all.playpause.alt="播放";
  218. }
  219. /////////////////////////////////////////////////////////////////////////////////////////////
  220. //function PlayPause(){
  221. // if (document.all.Player.PlayState==2){
  222. // Pause();
  223. // }else {
  224. // if (document.all.Player.PlayState<2){
  225. // Play();
  226. // }
  227. // }
  228. //}
  229. /////////////////////////////////////////////////////////////////////////////////////////////
  230. function ClosePlayer(){
  231. if(document.all.Player.PlayState>1)
  232. Stop();
  233. window.close();
  234. }