A midiaplayer class written in Javascript

Source: Internet
Author: User

Modify the settings as needed.

MPL. Openurl ("dusktodawn.wma ");

Below is the completeCode:

<! Doctype HTML public "-// W3C // dtd xhtml 1.0 transitional // en" <br/> "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> </P> <p> <HTML xmlns = "http://www.w3.org/1999/xhtml"> <br/> <pead> <br/> <title> mediaplayer example </title> <br/> <MCE: style type = "text/CSS"> <! -- <Br/> body <br/> {<br/> font-size: 12px; <br/> font-family:; <br/>}< br/> # divmpl <br/>{< br/> Height: 137px; <br/> width: 277px; <br/>}< br/> # divmsg <br/>{< br/> Height: 155px; <br/> overflow: auto; <br/> width: 376px; <br/>}</P> <p> --> </MCE: style> <style type = "text/CSS" mce_bogus = "1"> body <br/>{< br/> font-size: 12px; <br/> font-family:; <br/>}< br/> # divmpl <br/>{< br/> Height: 137 p X; <br/> width: 277px; <br/>}< br/> # divmsg <br/>{< br/> Height: 155px; <br/> overflow: auto; <br/> width: 376px; <br/>}< br/> </style> <br/> <MCE: script Language = "JavaScript" type = "text/JavaScript"> <! -- <Br/>/* mediaplayer class definition original freezing point */<br/> function mediaplayer () <br/> {<br/> This. DOM = NULL; <br/>}< br/> mediaplayer. uimode = <br/>{< br/> full: "full", <br/> mini: "mini", <br/> none: "NONE ", <br/> invisible: "invisible" <br/>}< br/> mediaplayer. prototype = {<br/> createat: function (ID) // create a mediaplayer control in the tag of the specified ID, the size is determined by the tag <br/>{< br/> This. DOM = document. createelement ("object"); <br/> This. dom. classid = "CLSID: 6bf52a52-394a-11d3-b153-00c04f79faa6"; <br/> This. dom. style. width = "100%"; <br/> This. dom. style. height = "100%"; <br/> var Container = document. getelementbyid (ID); <br/> container. innerhtml = ""; <br/> container. appendchild (this. dom); <br/> This. _ Init (); <br/>}, <br/> bindid: function (ID) // bind an existing object tag, this label should be a mediaplayer Control <br/>{< br/> This. DOM = document. getelementbyid (ID); <br/> This. _ Init (); <br/>}, <br/> _ init: function () // initialization, register event <br/>{< br/> VaR _ this = This; <br/> This. dom. attachevent ("playstatechange", <br/> function (newstate) {_ this. onplaystatechange (newstate)}); <br/> This. dom. attachevent ("Buffering", function (bstart) {_ this. onbuffering (bstart)}); <br/> This. dom. attachevent ("error", function () {_ this. onerror () ;}); <br/> This. dom. attachevent ("positionchange", <br/> function (oldpos, newpos) {_ this. onpositionchange (oldpos, newpos) ;}); <br/> This. dom. attachevent ("statuschange", function () {_ this. onstatuschange () ;}) <br/>}, <br/> onplaystatechange: function (newstate) <br/>{< br/> switch (newstate) <br/>{< br/> case 1: // wmppsstopped <br/> This. onstop (); <br/> break; <br/> case 2: // wmppspaused <br/> This. onpaused (); <br/> break; <br/> case 3: // wmppsplaying <br/> This. onplay (); <br/> break; <br/> case 4: // wmppsscanforward <br/> break; <br/> case 5: // wmppsscanreverse <br/> break; <br/> case 6: // wmppsbuffering <br/> This. onbuffering_ SC (); <br/> break; <br/> case 7: // wmppswaiting <br/> break; <br/> case 8: // wmppsmediaended <br/> This. onmediaended (); <br/> break; <br/> case 9: // wmppstransitioning <br/> This. ontransitioning (); <br/> break; <br/> case 10: // wmppsready <br/> break; <br/> case 11: // wmppsreconnecting <br/> break; <br/> case 12: // wmppslast <br/> break; <br/> case 0: // wmppsundefined <br/> break; <br/> default: <br/> break; <br/>}< br/> }, <br/> // event list <br/> onstop: function () {}, <br/> onpaused: function () {}, <br/> onplay: function () {}, <br/> onbuffering_ SC: function () {}, <br/> ontransitioning: function () {}, <br/> onmediaended: function () {}, <br/> onerror: function () {}, <br/> onpositionchange: function (oldpos, newpos) {}, <br/> onstatuschange: function () {}, <br/> onbuffering: function (bstart) {}, </P> <p> // currently, only two setmode: function (mode) are supported. <br/>) {This. dom. uimode = mode ;}, <br/> setvalume: function (v) {This. dom. settings. volume = V ;}, </P> <p> // various attributes <br/> getmedianame: function () <br/>{< br/> var media = This. dom. currentmedia; <br/> If (media) <br/>{< br/> return media. name; <br/>}< br/> return ""; <br/>}, <br/> getmediaduration: function () <br/>{< br/> var media = This. dom. currentmedia; <br/> If (media) <br/>{< br/> return media. duration; <br/>}< br/> return ""; <br/>}, <br/> getmediadurationstring: function () <br/>{< br/> var media = This. dom. currentmedia; <br/> If (media) <br/>{< br/> return media. durationstring; <br/>}< br/> return ""; <br/>}, <br/> getstatus: function () {return this. dom. status ;}, <br/> getposition: function () {return this. dom. controls. currentposition ;}, <br/> getpositionstring: function () {return this. dom. controls. currentpositionstring ;}, <br/> getplaystate: function () {return this. dom. playstate; },</P> <p> // operation method <br/> Openurl: function (URL) {This. dom. url = URL ;}, <br/> play: function () {This. dom. controls. play () ;}, <br/> pause: function () {This. dom. controls. pause () ;}, <br/> stop: function () {This. dom. controls. stop () ;}< br/>}< br/>/* mediaplayer class definition original freezing point */</P> <p> var MPL = new mediaplayer (); // create a mediaplayer <br/> window. onload = function () <br/>{< br/> MPL. createat ("divmpl"); <br/> MPL. setvalume (100); <br/> MPL. setmode (mediaplayer. uimode. full); <br/> MPL. onplay = function () {showmessage ("playing [" + this. getmedianame () + "]") ;}; <br/> MPL. onpaused = function () {showmessage ("Suspend") ;}; <br/> MPL. onmediaended = function () {showmessage ("playing end") ;}; <br/> MPL. onstop = function () {showmessage ("stop") ;}; <br/> MPL. onpositionchange = function (oldpos, newpos) {<br/> var pos1 = {<br/> min: parseint (oldpos/60), <br/> sec: parseint (oldpos % 60) <br/>}< br/> var pos2 ={< br/> min: parseint (newpos/60), <br/> sec: parseint (newpos % 60) <br/>}< br/> showmessage (pos1.min + ":" + pos1.sec + "->" + pos2.min + ":" + pos2.sec ); <br/>}; <br/> // MPL. onstatuschange = function () {showmessage (this. getstatus () ;}; <br/> MPL. openurl ("dusktodawn.wma"); <br/> window. setinterval ("showplaytime ()", 1000); <br/>}< br/> function showplaytime () <br/>{< br/> If (MPL. getplaystate () = 3) <br/>{< br/> showstatus (MPL. getpositionstring (); <br/>}< br/> function showmessage (STR) <br/>{< br/> var MSG = document. getelementbyid ("divmsg"); <br/> var Tn = document. createtextnode (STR); <br/> MSG. appendchild (TN); <br/> MSG. appendchild (document. createelement ("Br"); <br/>}< br/> function showstatus (STR) <br/>{< br/> document. getelementbyid ("divstatus "). innerhtml = STR; <br/>}</P> <p> // --> </MCE: SCRIPT> <br/> </pead> <br/> <body> <br/> <Div id = "divmpl"> </div> <br/> <Div ID = "divstatus"> </div> <br/> <input type = "button" value = "clear message" onclick = "document. getelementbyid ('divmsg '). innerhtml = ''; "/> <br/> <Div id =" divmsg "> </div> <br/> </body> <br/> </ptml> <br/>

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.