Midp2.0 sound usage

Source: Internet
Author: User
// Private int gamelevel = 0 for game level control; // Private player treadsoundplayer for game music control; player backgroundmusicplayer; private int volumelevel = 100; // volume control private volumecontrol VC; private Boolean playstate = false; // (play/close) status // audio processing ///// /// // public void playerupdate (player P, string event, object eventdata) {// player listens to try {If (event = pl Ayerlistener. end_of_media) {playstate = false;} If (event = playerlistener. started) {playstate = true; // This. musicvolume () ;}} catch (exception e) {system. out. println ("error at 11:" + event + E. tostring () ;}} protected void musicstart () {// randomly generate a music try {backgroundmusicplayer = NULL; backgroundmusicplayer = createplayer ("/2C. mid "," audio/Midi "); // backgroundmusicplayer. addplayerlistener (This); // backgroundmusicplayer. setloopcount (-1); Vc = (volumecontrol) backgroundmusicplayer. getcontrol ("volumecontrol"); If (VC! = NULL) {If (gamelevel = 0) backgroundmusicplayer. setloopcount (-1); else backgroundmusicplayer. setloopcount (5); backgroundmusicplayer. start () ;}} catch (exception e) {system. out. println ("error at 20:" + backgroundmusicplayer + E. tostring () ;}} protected void musicclose () {// turn off the music try {If (backgroundmusicplayer! = NULL) {backgroundmusicplayer. close (); backgroundmusicplayer = NULL;} catch (exception e) {system. out. println ("error at 30:" + E. tostring () ;}} protected void musicpause () {// pause music try {If (backgroundmusicplayer! = NULL & playstate) pausetime = backgroundmusicplayer. getmediatime (); backgroundmusicplayer. stop ();} catch (exception e) {system. out. println ("error at 40:" + E. tostring () ;}} protected void musiccontinue () {// The music continues try {If (backgroundmusicplayer! = NULL &&! Playstate) backgroundmusicplayer. setmediatime (pausetime); backgroundmusicplayer. start ();} catch (exception e) {system. out. println ("error at 50:" + E. tostring () ;}} protected void musicvolume () // set the Music volume {If (VC! = NULL) VC. setlevel (volumelevel);} protected player createplayer (string filename, string format) {// create music player P = NULL; try {inputstream is = getclass (). getresourceasstream (filename); P = manager. createplayer (is, format); p. prefetch ();} catch (exception X) {system. out. println ("error at 60:" + filename + X. tostring ();} return P ;}

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.