I would like to play background music in my J2ME game. How can I code this function?
Do you have a similar question in Playing audio with J2ME
For convenience, I posted the code from this thread:
// loads the InputStream for the sound InputStream inputStream = this.getClass().getResourceAsStream( musicFile ); // create the standard Player musicPlayer = Manager.createPlayer( inputStream, musicEncoding ); musicPlayer.prefetch(); // add player listener to access sound events musicPlayer.addPlayerListener( this ); if( loopMusic ) { // use the loop count method for infinite looping musicPlayer.setLoopCount( -1 ); } // The set occurs twice to prevent sound spikes at the very // beginning of the sound. VolumeControl volumeControl = (VolumeControl) musicPlayer.getControl( "VolumeControl" ); volumeControl.setLevel( curVolume ); // finally start the piece of music musicPlayer.start(); // set the volume once more volumeControl = (VolumeControl) musicPlayer.getControl( "VolumeControl" ); volumeControl.setLevel( curVolume ); // finally, delete the input stream to save on resources inputStream.close(); inputStream = null;
QuickRecipes Chan, MIDI , , WAV, MIDI, , , , , . MIDI WAV - , , .
Source: https://habr.com/ru/post/1728124/More articles:PHP 6 - roadmap? - phpBlock comment markup with ANTLR - compiler-constructionHow to get the absolute path to a website file from a WCF service hosted in IIS? - wcfSQL Server 2008 Express - loading a sample database? - sql-serverPayPal $ 0 Dollar Transaction? - transactionsMax for Live vs JVAP Tools - javaWhat event is canceled, and how does it differ from the finishing touches - iosRuby Claims and Disabled Inputs - ruby-on-railsThe cron command runs a php script every 10 minutes - cronWPF Documentviewerbase.Print. Удалить диалоговое окно - wpfAll Articles