加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

cocos2dx 安卓环境播放mid音乐

发布时间:2020-12-14 19:10:35 所属栏目:百科 来源:网络整理
导读:修改 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.mBack

修改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");
			}
		}
	}

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读