Merge pull request #9098 from Dhilan007/v3-audio-loopfix

fix AudioEngine can't looping audio on Android 2.3.x
This commit is contained in:
minggo 2014-11-13 14:45:22 +08:00
commit 09738136ca
2 changed files with 19 additions and 9 deletions

View File

@ -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);

View File

@ -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<void (int, const std::string &)> _finishCallback;