From 80160e24d5038625defd80f76da31e7d3354540e Mon Sep 17 00:00:00 2001 From: tangzhijun Date: Wed, 30 Oct 2024 10:05:33 +0800 Subject: [PATCH 1/2] Update UrlAudioPlayer.cpp fix: audioEngine anr --- native/cocos/audio/android/UrlAudioPlayer.cpp | 21 +++++++++++-------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/native/cocos/audio/android/UrlAudioPlayer.cpp b/native/cocos/audio/android/UrlAudioPlayer.cpp index 881f49bd537..69277921cf2 100644 --- a/native/cocos/audio/android/UrlAudioPlayer.cpp +++ b/native/cocos/audio/android/UrlAudioPlayer.cpp @@ -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 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(_state)); } + } + } void UrlAudioPlayer::pause() { From 69592eabd6a48a46a64799c8373ea6f25a9f73b8 Mon Sep 17 00:00:00 2001 From: tangzhijun Date: Wed, 30 Oct 2024 15:39:46 +0800 Subject: [PATCH 2/2] Update UrlAudioPlayer.h forget upload --- native/cocos/audio/android/UrlAudioPlayer.h | 1 + 1 file changed, 1 insertion(+) diff --git a/native/cocos/audio/android/UrlAudioPlayer.h b/native/cocos/audio/android/UrlAudioPlayer.h index 0b289e85873..601ef50b7cc 100644 --- a/native/cocos/audio/android/UrlAudioPlayer.h +++ b/native/cocos/audio/android/UrlAudioPlayer.h @@ -119,6 +119,7 @@ class UrlAudioPlayer : public IAudioPlayer { std::thread::id _callerThreadId; std::shared_ptr _isDestroyed; + std::mutex destoryMutex; friend class SLUrlAudioPlayerCallbackProxy; friend class AudioPlayerProvider;