Control media player with JavaScript JS

Source: Internet
Author: User

 If you cannot find the audio and video files on your computer, you can use an image instead; <br/> <HTML> <br/> <pead> <br/> <meta http-equiv = "Content-Type" content = "text/html; charset = gb2312 "> <br/> <title> control your player </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 = "stop"; <br/> break; <br/> case 2: <br/> playerinfo. innerhtml = "paused"; <br/> break; <br/> case 3: <br/> playerinfo. innerhtml = "playing"; <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 = "buffering... "; <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 = "Connecting... "; <br/> break; <br/> case 10: <br/> playerinfo. innerhtml = "ready"; <br/> break; <br/> case 11: <br/> playerinfo. innerhtml = "11"; <br/> break; <br/> default: <br/> playerinfo. innerhtml = ""; <br/>}< br/> </SCRIPT> <br/> </pead> </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/> <TD Height = "20" colspan = "2" align = "center"> <br/> <font color = Red> <span id = "playerinfo3"> </span> </font> <br/> </TD> <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/> <TD colspan =" 2 "align =" center "> <br/> <input type =" button "name =" openfile "Title =" Open File "<br/> onclick =" openfile () "value =" Open File "> <br/> <input type =" button "name =" play "Title =" play "onclick =" Play (); "<br/> value =" play "> <br/> <input type =" button "name =" pause "Title =" pause "onclick =" Pause (); "<br/> value =" pause "> <br/> <input type =" button "name =" stop "Title =" stop "onclick =" Stop (); "<br/> value =" stop "> <br/> <input type =" button "name =" voldown "Title =" volume-"<br/> onclick =" voldown (); "value =" volume-"> <br/> <input type =" button "name =" volup "Title =" volume + "<br/> onclick =" volup (); "value =" volume + "> <br/> <input type =" button "name =" mute "Title =" mute/"onclick =" mute (); "<br/> value =" mute/"> <br/> <input type =" button "name =" balance "Title =" "<br/> onclick =" balance (); "value =" "> <br/> <input type =" button "Title =" refresh "onclick =" location. reload (); "<br/> value =" refresh "> <br/> <input type =" button "Title =" full screen "value =" full screen "<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> the path and name of the current playback file are: </font> </B> "+ Filebtn. value; <br/>}< br/> function playerinit () {<br/> windowsmediaplayer. url = "test. WMV "; // define your own file <br/> windowsmediaplayer. settings. autostart = false; <br/>}< br/> function play () {<br/> // If (windowsmediaplayer. url = '') Alert ('Open the file'); return; onload =" playerinit () "<br/> If (windowsmediaplayer. controls. isavailable ("play") {<br/> windowsmediaplayer. controls. play (); <br/> state = setinterval ("Updatetime ()", 1000); <br/> playerinfo. innerhtml = "play"; <br/> varfullscreen = 1; <br/> playerinfo2.innerhtml = "volume:" + windowsmediaplayer. settings. volume; <br/>}< br/> function voldown () {<br/> If (windowsmediaplayer. settings. volume <5) {<br/> windowsmediaplayer. settings. volume = 0; <br/> playerinfo2.innerhtml = "volume: 0"; <br/> playerinfo1.innerhtml = "0 volume"; <br/>} else {<br/> windowsmediaplayer. Settings. volume-= 5; <br/> playerinfo2.innerhtml = "volume:" + windowsmediaplayer. settings. volume; <br/> playerinfo1.innerhtml = "non-Mute"; <br/>}< br/> function volup () {<br/> If (windowsmediaplayer. settings. volume> 95) {<br/> windowsmediaplayer. settings. volume = 100; <br/> playerinfo2.innerhtml = "volume: 100"; <br/> playerinfo1.innerhtml = "maximum sound"; <br/>} else {<br/> windowsmediaplayer. settings. volume + = 5; <br/> playerinfo2.innerhtml = "volume:" + windowsmediaplayer. settings. volume; <br/> playerinfo1.innerhtml = "non-Mute"; <br/>}< br/> function pause () {<br/> If (windowsmediaplayer. controls. isavailable ("pause") {<br/> windowsmediaplayer. controls. pause (); <br/> clearinterval (State); <br/> playerinfo. innerhtml = "paused"; <br/> varfullscreen = 1; <br/>}< br/> function stop () {<br/> If (windowsmediapla Yer. controls. isavailable ("stop") {<br/> windowsmediaplayer. controls. stop (); <br/> clearinterval (State); <br/> playerinfo. innerhtml = "stop"; <br/> varfullscreen = 0; <br/>}< br/> function mute () {<br/> windowsmediaplayer. settings. mute =! Windowsmediaplayer. settings. Mute; <br/> If (varb! = 1) {<br/> playerinfo1.innerhtml = "mute"; <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 = "non-Mute"; <br/> document. all. volup. disabled = false; <br/> document. all. voldown. disabled = false; <br/> document. all. balance. disabled = false; <br/> varb = 0; <br/>}< br/> function balance () {<br/> switch (windowsmediaplayer. settings. balance) {<br/> case 0: <br/> windowsmediaplayer. settings. balance = 100; <br/> playerinfo1.innerhtml = "left channel"; <br/> break; <br/> case 100: <br/> windowsmediaplayer. settings. balance =-100; <br/> playerinfo1.innerhtml = "right channel"; <br/> break; <br/> case-100: <br/> windowsmediaplayer. settings. balance = 0; <br/> playerinfo1.innerhtml = "Full Channel"; <br/> break; <br/> default: <br/> windowsmediaplayer. settings. balance = 0; <br/> playerinfo1.innerhtml = "Full Channel"; <br/> break; <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: Set the appearance <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/>}</P> <p>

For more information about how to control Media Player attributes, see http://blog.csdn.net/IBM_hoojo/archive/2010/06/09/5658181.aspx.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.