java 游戏背景mp3音乐_java-J2ME背景音乐

旧城等待, 2022-11-06 12:58 262阅读 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;

发表评论

表情:
评论列表 (有 0 条评论,262人围观)

还没有评论,来说两句吧...

相关阅读

    相关 MFC添加游戏背景音乐

    前一阵在给基于MFC的一个小游戏添加背景音乐的时候,刚开始是准备new一个新线程,但是在参考了一些资料与教程之后,决定采用MCI这个API,开始使用的是winmm.lib接口,