java 游戏背景mp3音乐_java-J2ME背景音乐 旧城等待, 2022-11-06 12:58 157阅读 0赞 您在Playing Audio with J2ME有类似的问题 为了简便起见,我从该线程发布了一些代码: // 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;
还没有评论,来说两句吧...