Skip to content

Commit

Permalink
Update UrlAudioPlayer.cpp
Browse files Browse the repository at this point in the history
fix: audioEngine anr
  • Loading branch information
tangzhijun authored Oct 30, 2024
1 parent edeb5c7 commit 80160e2
Showing 1 changed file with 12 additions and 9 deletions.
21 changes: 12 additions & 9 deletions native/cocos/audio/android/UrlAudioPlayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -133,20 +133,23 @@ void UrlAudioPlayer::stop() {
ALOGV("UrlAudioPlayer::stop (%p, %d)", this, getId());
SLresult r = (*_playItf)->SetPlayState(_playItf, SL_PLAYSTATE_STOPPED);
SL_RETURN_IF_FAILED(r, "UrlAudioPlayer::stop failed");
{
std::lock_guard<std::mutex> guard(destoryMutex); // 加入互斥锁
if (_state == State::PLAYING || _state == State::PAUSED) {
setLoop(false);
setState(State::STOPPED);

if (_state == State::PLAYING || _state == State::PAUSED) {
setLoop(false);
setState(State::STOPPED);

if (_playEventCallback != nullptr) {
_playEventCallback(State::STOPPED);
}
if (_playEventCallback != nullptr) {
_playEventCallback(State::STOPPED);
}

destroy();
delete this;
destroy();
delete this;
} else {
ALOGW("UrlAudioPlayer (%p, state:%d) isn't playing or paused, could not invoke stop!", this, static_cast<int>(_state));
}
}

}

void UrlAudioPlayer::pause() {
Expand Down

0 comments on commit 80160e2

Please sign in to comment.