zoukankan      html  css  js  c++  java
  • 用js控制网页播放器

    我整理的一些,不是很全。但应该够用了

    media player控制

    player.controls.play(); 播放
    player.controls.stop(); 停止
    player.controls.pause(); 暂停
    player.controls.currentPosition 返回播放文件的当前时间位置(以秒为单位)
    player.controls.currentPositionString 时间格式的字符串 "0:32"
    player.currentMedia.duration 返回播放文件的总长度(以秒为单位)
    player.currentMedia.durationString 时间格式的字符串 "4:34"
    player.settings.volume 音量 (0-100)
    player.settings.balance 声道,通过它应该可以进行立体声、左声道、右声道的控制。但对应的取值尚不清楚。
    player.settings.mute = s 静音(s取值为true和false)
    player.closedCaption.CaptioningID 网页中出现字幕的容器的ID
    player.closedCaption.SAMIFileName 字幕文件地址
    player.playState 返回播放器状态( 3:正在播放,2:暂停1:已停止)

    ======================================================

    REAL PLAYER控制

    player.DoPlay() 播放
    player.DoPause() 暂停
    player.DoStop() 停止
    player.GetLength() 返回播放文件的总长度(以毫秒为单位)
    player.GetPosition() 返回播放文件的当前时间位置(以毫秒为单位)
    player.GetPlayState() 返回播放器状态(0:停止,1:连接,2:缓冲,3:播放,4:暂停,5:寻找)
    player.SetPosition(n) 时间位置跳到n的地方(n取值以毫秒为单位)
    player.SetVolume(n) 设置音量(n取值为0到100)
    player.SetMute(s) 静音(s取值为true和false)
    player.SetFullScreen() 全屏
    player.setSource() 设置文件来源

    这个可以播放MP3
    <HTML>
    <HEAD>
      <TITLE>MP3播放器</TITLE>
      <SCRIPT language=javascript event=OpenComplete for=Player>
        Player_OpenComplete()
      </SCRIPT>

      <SCRIPT language=javascript event=PositionChange for=Player>
        Player_PositionChange()
      </SCRIPT>

      <SCRIPT language=javascript event=Timer for=Player>
        Player_Timer()
      </SCRIPT>

      <SCRIPT language=javascript event=StateChange for=Player>
        Player_StateChange()
      </SCRIPT>
    </HEAD>

    <BODY language=javascript leftMargin=0 topMargin=0 onload="PlayInit()">
    <br><br><br>
    <center>
    <table width="390" height="121" background="MP3bg.gif" border=0 cellSpacing=0 cellPadding=0 borderColorDark=#FFFFFF borderColorLight=#ff0000>
      <tr>
       <td height="18" width="22"></td>
       <td height="18" width="87"></td>
       <td height="18" width="87"></td>
       <td height="18" width="72"></td>
       <td height="18" width="83"></td>
       <td height="18" width="27"></td>
      </tr>

      <tr>
       <td height="27" width="22"></td>
       <td height="27" width="87"></td>
       <td height="27" width="246" colspan="3"><LABEL id=FileNameLabel style="FONT-SIZE: larger; COLOR: blue"></LABEL></td>
       <td height="27" width="27"></td>
      </tr>

      <tr>
       <td height="31" width="22"></td>
       <td height="31" width="87"></td>
       <td height="31" width="87" align=center><LABEL id=TimeLabel style="FONT-SIZE: larger; COLOR: blue">00:00</LABEL></td>
       <td height="31" width="72">
        
       </td>
       <td height="31" width="83" align="center"><LABEL id=LengthLabel style="FONT-SIZE: larger; COLOR: blue">00:00</LABEL></td>
       <td height="31" width="27"></td>
      </tr>
      <tr>
       <td height="22" width="22"></td>
       <td height="22" width="87"></td>
       <td height="22" width="246" colspan="3" align=center><DIV id=Progress style="LEFT: 115px; WIDTH: 240px;BACKGROUND-COLOR: red"></DIV></td>
       <td height="22" width="27"></td>
      </tr>

      <tr>
       <td colspan="6" align=center valign=bottom height="20" width="388"></td>
      </tr>
      <tr>
      <td colspan="6" align=center valign=bottom height="20" width="388">
       <IMG id=OpenBtn onclick="OpenBtn()" alt=FileOpen  src="open.gif" width=55><IMG id=PlayBtn onclick="PlayBtn()" alt=Play    src="play.gif" width=55><IMG id=StopBtn onclick="StopBtn()" alt=Stop    src="stop.gif" width=55><IMG id=PauseBtn onclick="PauseBtn()" alt=Pause   src="pause.gif" width=55><IMG id=RewBtn  onclick="RewBtn()"  alt=Rewind   src="rew.gif"  width=55><IMG id=FFBtn  onclick="FFBtn()"  alt=FastFoward src="FF.gif"  width=55 height="29">
      </td>
      </tr>
      <tr>
      <td colspan="6" align=center valign=bottom height="4" width="388"></td>
      </tr>
    </table>
    </center>

      
     
        
    <OBJECT id=Player style="VISIBILITY:hidden;" height=10 width=10 classid=clsid:05589FA1-C356-11CE-BF01-00AA0055595A>    
      <PARAM NAME="Appearance" VALUE="0">    
      <PARAM NAME="AutoStart" VALUE="0">    
      <PARAM NAME="AllowChangeDisplayMode" VALUE="-1">    
      <PARAM NAME="AllowHideDisplay" VALUE="0">    
      <PARAM NAME="AllowHideControls" VALUE="-1">    
      <PARAM NAME="AutoRewind" VALUE="-1">    
      <PARAM NAME="Balance" VALUE="0">    
      <PARAM NAME="CurrentPosition" VALUE="0">    
      <PARAM NAME="DisplayBackColor" VALUE="0">    
      <PARAM NAME="DisplayForeColor" VALUE="16777215">    
      <PARAM NAME="DisplayMode" VALUE="0">    
      <PARAM NAME="Enabled" VALUE="-1">    
      <PARAM NAME="EnableContextMenu" VALUE="-1">    
      <PARAM NAME="EnablePositionControls" VALUE="-1">    
      <PARAM NAME="EnableSelectionControls" VALUE="0">    
      <PARAM NAME="EnableTracker" VALUE="-1">    
      <PARAM NAME="Filename" VALUE="">    
      <PARAM NAME="FullScreenMode" VALUE="0">    
      <PARAM NAME="MovieWindowSize" VALUE="0">    
      <PARAM NAME="PlayCount" VALUE="1">    
      <PARAM NAME="Rate" VALUE="1">    
      <PARAM NAME="SelectionStart" VALUE="-1">    
      <PARAM NAME="SelectionEnd" VALUE="-1">    
      <PARAM NAME="ShowControls" VALUE="-1">    
      <PARAM NAME="ShowDisplay" VALUE="0">    
      <PARAM NAME="ShowPositionControls" VALUE="0">    
      <PARAM NAME="ShowTracker" VALUE="-1">    
      <PARAM NAME="Volume" VALUE="-830">    
    </OBJECT>    
    <INPUT type=file id=FileBtn style="VISIBILITY:hidden;">       
           


    <SCRIPT language=javascript>

    var OldPos, Length, Width

    function PlayInit()
    {
     OldPos = 0    
     Width = Progress.style.posWidth    
     Progress.style.posWidth = 0 
    }

    function Player_OpenComplete(){Length=Player.Duration;LengthLabel.innerText=FormatTime(Length);}
    function Player_Timer()
    {
     var CurPos
     CurPos=Math.floor(Player.CurrentPosition)
     alert(CurPos)
     if ( CurPos != OldPos )
     {
      OldPos=CurPos
      TimeLabel.innerText=FormatTime(CurPos)
      Progress.style.posWidth=(Width * CurPos)/Length
     }
    }

    function Player_PositionChange()
    {
     TimeLabel.innerText=FormatTime(Player.CurrentPosition)
     Progress.style.posWidth=(Width * Player.CurrentPosition) / Length
    }

    function Player_StateChange()    
    {    
     if(Player.CurrentState==0){TimeLabel.innerText = FormatTime(0);Progress.style.posWidth=0}
    }


    function OpenBtn()
    {
     var fstr=''
     FileBtn.click()    
     if (FileBtn.value=='') return
     Player.FileName=FileBtn.value
     fstr=FileBtn.value
     var temparr=fstr.split('\\')
     FileNameLabel.innerText= ' ' + temparr[temparr.length-1]
     Player.Run()
    }

    function PlayBtn(){Player.Run()}

    function StopBtn(){Player.Stop()}

    function PauseBtn(){Player.Pause()}

    function RewBtn(){Player.CurrentPosition=Player.CurrentPosition-10}

    function FFBtn(){Player.CurrentPosition=Player.CurrentPosition+10}

    function FormatTime(value)
    {
     var min, sec, str
     min=Math.floor(value / 60)
     sec=Math.floor(value % 60)
     if (isNaN(min)){return "00:00"}
     if (min>9){str=min.toString() + ":"}else{str="0" + min.toString() + ":"}
     if (sec>9){str=str + sec.toString()}else{str=str + "0" + sec.toString()}
     return str
    }


    </SCRIPT>

    </BODY></HTML>

  • 相关阅读:
    PMM Client 安装异常报错
    安装Docker时错误提示 "could not change group /var/run/docker.sock to docker: group docker not found"的解决方案
    简单概括下MongoDB 4.0 新特性
    MySQL 关于性能的参数配置梳理
    MySQL数据库在IO性能优化方面的设置选择(硬件)
    MongoDB 集合间关联查询后通过$filter进行筛选
    MySQL 基础知识梳理学习(七)----sync_binlog
    第八章 (一)分治 练习题
    第八章 (一)分治
    Logistic回归
  • 原文地址:https://www.cnblogs.com/MaxIE/p/1041387.html
Copyright © 2011-2022 走看看