cocos2dx 安卓环境播放mid音乐

来源:互联网 发布:槽钢承载力计算软件 编辑:程序博客网 时间:2024/06/04 19:11

修改Cocos2dxMusic.java文件中的playBackgroundMusic函数

public void playBackgroundMusic(final String pPath, final boolean isLoop) {if (this.mCurrentPath == null) {// it is the first time to play background music or end() was calledthis.mBackgroundMediaPlayer = this.createMediaplayer(pPath);this.mCurrentPath = pPath;} else {if (!this.mCurrentPath.equals(pPath)) {// play new background music// release old resource and create a new oneif (this.mBackgroundMediaPlayer != null) {this.mBackgroundMediaPlayer.release();}this.mBackgroundMediaPlayer = this.createMediaplayer(pPath);// record the paththis.mCurrentPath = pPath;}}if (this.mBackgroundMediaPlayer == null) {Log.e(Cocos2dxMusic.TAG, "playBackgroundMusic: background media player is null");} else {// if the music is playing or paused, stop itboolean isStop = false;if(mBackgroundMediaPlayer.isPlaying()){isStop = true;this.mBackgroundMediaPlayer.stop();}this.mBackgroundMediaPlayer.setLooping(isLoop);try {Log.e(Cocos2dxMusic.TAG, "playBackgroundMusic");if(isStop)this.mBackgroundMediaPlayer.prepare();this.mBackgroundMediaPlayer.seekTo(0);this.mBackgroundMediaPlayer.start();this.mPaused = false;} catch (final Exception e) {Log.e(Cocos2dxMusic.TAG, "playBackgroundMusic: error state");}}}

0 0
原创粉丝点击