cocos2dx 安卓环境播放mid音乐

修改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 called
			this.mBackgroundMediaPlayer = this.createMediaplayer(pPath);
			this.mCurrentPath = pPath;
		} else {
			if (!this.mCurrentPath.equals(pPath)) {
				// play new background music

				// release old resource and create a new one
				if (this.mBackgroundMediaPlayer != null) {
					this.mBackgroundMediaPlayer.release();
				}
				this.mBackgroundMediaPlayer = this.createMediaplayer(pPath);

				// record the path
				this.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 it
			boolean 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");
			}
		}
	}

相关文章

    本文实践自 RayWenderlich、Ali Hafizji 的文章《...
Cocos-code-ide使用入门学习地点:杭州滨江邮箱:appdevzw@1...
第一次開始用手游引擎挺激动!!!进入正题。下载资源1:从C...
    Cocos2d-x是一款强大的基于OpenGLES的跨平台游戏开发...
1.  来源 QuickV3sample项目中的2048样例游戏,以及最近《...
   Cocos2d-x3.x已经支持使用CMake来进行构建了,这里尝试...