From 249d34b707429aec6906f600d3bb472748ef1090 Mon Sep 17 00:00:00 2001 From: Dhilan007 Date: Thu, 13 Nov 2014 11:28:08 +0800 Subject: [PATCH] fix AudioEngine can't looping audio on Android 2.3.x --- cocos/audio/android/AudioEngine-inl.cpp | 21 ++++++++++++++++----- cocos/audio/android/AudioEngine-inl.h | 7 +++---- 2 files changed, 19 insertions(+), 9 deletions(-) diff --git a/cocos/audio/android/AudioEngine-inl.cpp b/cocos/audio/android/AudioEngine-inl.cpp index 05be61036f..7860aedc18 100644 --- a/cocos/audio/android/AudioEngine-inl.cpp +++ b/cocos/audio/android/AudioEngine-inl.cpp @@ -46,7 +46,15 @@ void PlayOverEvent(SLPlayItf caller, void* context, SLuint32 playEvent) if (context && playEvent == SL_PLAYEVENT_HEADATEND) { AudioPlayer* player = (AudioPlayer*)context; - player->_playOver = true; + //fix issue#8965:AudioEngine can't looping audio on Android 2.3.x + if (player->_loop) + { + (*(player->_fdPlayerPlay))->SetPlayState(player->_fdPlayerPlay, SL_PLAYSTATE_PLAYING); + } + else + { + player->_playOver = true; + } } } @@ -55,6 +63,7 @@ AudioPlayer::AudioPlayer() , _finishCallback(nullptr) , _duration(0.0f) , _playOver(false) + , _loop(false) { } @@ -143,6 +152,7 @@ bool AudioPlayer::init(SLEngineItf engineEngine, SLObjectItf outputMixObject,con result = (*_fdPlayerObject)->GetInterface(_fdPlayerObject, SL_IID_VOLUME, &_fdPlayerVolume); if(SL_RESULT_SUCCESS != result){ ERRORLOG("get the volume interface fail"); break; } + _loop = loop; if (loop){ (*_fdPlayerSeek)->SetLoop(_fdPlayerSeek, SL_BOOLEAN_TRUE, 0, SL_TIME_UNKNOWN); } @@ -286,13 +296,14 @@ void AudioEngineImpl::setVolume(int audioID,float volume) } auto result = (*player._fdPlayerVolume)->SetVolumeLevel(player._fdPlayerVolume, dbVolume); if(SL_RESULT_SUCCESS != result){ - log("%s error:%lu",__func__, result); + log("%s error:%u",__func__, result); } } void AudioEngineImpl::setLoop(int audioID, bool loop) { auto& player = _audioPlayers[audioID]; + player._loop = loop; SLboolean loopEnabled = SL_BOOLEAN_TRUE; if (!loop){ loopEnabled = SL_BOOLEAN_FALSE; @@ -305,7 +316,7 @@ void AudioEngineImpl::pause(int audioID) auto& player = _audioPlayers[audioID]; auto result = (*player._fdPlayerPlay)->SetPlayState(player._fdPlayerPlay, SL_PLAYSTATE_PAUSED); if(SL_RESULT_SUCCESS != result){ - log("%s error:%lu",__func__, result); + log("%s error:%u",__func__, result); } } @@ -314,7 +325,7 @@ void AudioEngineImpl::resume(int audioID) auto& player = _audioPlayers[audioID]; auto result = (*player._fdPlayerPlay)->SetPlayState(player._fdPlayerPlay, SL_PLAYSTATE_PLAYING); if(SL_RESULT_SUCCESS != result){ - log("%s error:%lu",__func__, result); + log("%s error:%u",__func__, result); } } @@ -323,7 +334,7 @@ void AudioEngineImpl::stop(int audioID) auto& player = _audioPlayers[audioID]; auto result = (*player._fdPlayerPlay)->SetPlayState(player._fdPlayerPlay, SL_PLAYSTATE_STOPPED); if(SL_RESULT_SUCCESS != result){ - log("%s error:%lu",__func__, result); + log("%s error:%u",__func__, result); } _audioPlayers.erase(audioID); diff --git a/cocos/audio/android/AudioEngine-inl.h b/cocos/audio/android/AudioEngine-inl.h index 209f52b206..c28e0edb53 100644 --- a/cocos/audio/android/AudioEngine-inl.h +++ b/cocos/audio/android/AudioEngine-inl.h @@ -50,16 +50,15 @@ public: bool init(SLEngineItf engineEngine, SLObjectItf outputMixObject,const std::string& fileFullPath, float volume, bool loop); bool _playOver; -private: - - SLObjectItf _fdPlayerObject; + bool _loop; SLPlayItf _fdPlayerPlay; +private: + SLObjectItf _fdPlayerObject; SLSeekItf _fdPlayerSeek; SLVolumeItf _fdPlayerVolume; float _duration; int _audioID; - std::function _finishCallback;