mirror of https://github.com/axmolengine/axmol.git
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:
commit
09738136ca
|
@ -46,7 +46,15 @@ void PlayOverEvent(SLPlayItf caller, void* context, SLuint32 playEvent)
|
||||||
if (context && playEvent == SL_PLAYEVENT_HEADATEND)
|
if (context && playEvent == SL_PLAYEVENT_HEADATEND)
|
||||||
{
|
{
|
||||||
AudioPlayer* player = (AudioPlayer*)context;
|
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)
|
, _finishCallback(nullptr)
|
||||||
, _duration(0.0f)
|
, _duration(0.0f)
|
||||||
, _playOver(false)
|
, _playOver(false)
|
||||||
|
, _loop(false)
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -143,6 +152,7 @@ bool AudioPlayer::init(SLEngineItf engineEngine, SLObjectItf outputMixObject,con
|
||||||
result = (*_fdPlayerObject)->GetInterface(_fdPlayerObject, SL_IID_VOLUME, &_fdPlayerVolume);
|
result = (*_fdPlayerObject)->GetInterface(_fdPlayerObject, SL_IID_VOLUME, &_fdPlayerVolume);
|
||||||
if(SL_RESULT_SUCCESS != result){ ERRORLOG("get the volume interface fail"); break; }
|
if(SL_RESULT_SUCCESS != result){ ERRORLOG("get the volume interface fail"); break; }
|
||||||
|
|
||||||
|
_loop = loop;
|
||||||
if (loop){
|
if (loop){
|
||||||
(*_fdPlayerSeek)->SetLoop(_fdPlayerSeek, SL_BOOLEAN_TRUE, 0, SL_TIME_UNKNOWN);
|
(*_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);
|
auto result = (*player._fdPlayerVolume)->SetVolumeLevel(player._fdPlayerVolume, dbVolume);
|
||||||
if(SL_RESULT_SUCCESS != result){
|
if(SL_RESULT_SUCCESS != result){
|
||||||
log("%s error:%lu",__func__, result);
|
log("%s error:%u",__func__, result);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void AudioEngineImpl::setLoop(int audioID, bool loop)
|
void AudioEngineImpl::setLoop(int audioID, bool loop)
|
||||||
{
|
{
|
||||||
auto& player = _audioPlayers[audioID];
|
auto& player = _audioPlayers[audioID];
|
||||||
|
player._loop = loop;
|
||||||
SLboolean loopEnabled = SL_BOOLEAN_TRUE;
|
SLboolean loopEnabled = SL_BOOLEAN_TRUE;
|
||||||
if (!loop){
|
if (!loop){
|
||||||
loopEnabled = SL_BOOLEAN_FALSE;
|
loopEnabled = SL_BOOLEAN_FALSE;
|
||||||
|
@ -305,7 +316,7 @@ void AudioEngineImpl::pause(int audioID)
|
||||||
auto& player = _audioPlayers[audioID];
|
auto& player = _audioPlayers[audioID];
|
||||||
auto result = (*player._fdPlayerPlay)->SetPlayState(player._fdPlayerPlay, SL_PLAYSTATE_PAUSED);
|
auto result = (*player._fdPlayerPlay)->SetPlayState(player._fdPlayerPlay, SL_PLAYSTATE_PAUSED);
|
||||||
if(SL_RESULT_SUCCESS != result){
|
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& player = _audioPlayers[audioID];
|
||||||
auto result = (*player._fdPlayerPlay)->SetPlayState(player._fdPlayerPlay, SL_PLAYSTATE_PLAYING);
|
auto result = (*player._fdPlayerPlay)->SetPlayState(player._fdPlayerPlay, SL_PLAYSTATE_PLAYING);
|
||||||
if(SL_RESULT_SUCCESS != result){
|
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& player = _audioPlayers[audioID];
|
||||||
auto result = (*player._fdPlayerPlay)->SetPlayState(player._fdPlayerPlay, SL_PLAYSTATE_STOPPED);
|
auto result = (*player._fdPlayerPlay)->SetPlayState(player._fdPlayerPlay, SL_PLAYSTATE_STOPPED);
|
||||||
if(SL_RESULT_SUCCESS != result){
|
if(SL_RESULT_SUCCESS != result){
|
||||||
log("%s error:%lu",__func__, result);
|
log("%s error:%u",__func__, result);
|
||||||
}
|
}
|
||||||
|
|
||||||
_audioPlayers.erase(audioID);
|
_audioPlayers.erase(audioID);
|
||||||
|
|
|
@ -50,16 +50,15 @@ public:
|
||||||
bool init(SLEngineItf engineEngine, SLObjectItf outputMixObject,const std::string& fileFullPath, float volume, bool loop);
|
bool init(SLEngineItf engineEngine, SLObjectItf outputMixObject,const std::string& fileFullPath, float volume, bool loop);
|
||||||
|
|
||||||
bool _playOver;
|
bool _playOver;
|
||||||
private:
|
bool _loop;
|
||||||
|
|
||||||
SLObjectItf _fdPlayerObject;
|
|
||||||
SLPlayItf _fdPlayerPlay;
|
SLPlayItf _fdPlayerPlay;
|
||||||
|
private:
|
||||||
|
SLObjectItf _fdPlayerObject;
|
||||||
SLSeekItf _fdPlayerSeek;
|
SLSeekItf _fdPlayerSeek;
|
||||||
SLVolumeItf _fdPlayerVolume;
|
SLVolumeItf _fdPlayerVolume;
|
||||||
|
|
||||||
float _duration;
|
float _duration;
|
||||||
int _audioID;
|
int _audioID;
|
||||||
|
|
||||||
|
|
||||||
std::function<void (int, const std::string &)> _finishCallback;
|
std::function<void (int, const std::string &)> _finishCallback;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue