Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix:AudioEngine->stop #17786

Open
wants to merge 2 commits into
base: v3.8.5
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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); // 加入互斥锁
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where is destoryMutex defined? And did you mean stop function is invoked more than once, then cause the crash?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, I forgot to upload it; in UrlAudioPlayer.h, it is a member variable.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you can try

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How to reproduce it?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I analyzed it from the logs, and it is intermittent, occurring in the background

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How did you know it is cause by not use mutex?

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
1 change: 1 addition & 0 deletions native/cocos/audio/android/UrlAudioPlayer.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,25 +40,25 @@
class UrlAudioPlayer : public IAudioPlayer {
public:
// Override Functions Begin
virtual int getId() const override { return _id; };

Check failure on line 43 in native/cocos/audio/android/UrlAudioPlayer.h

View workflow job for this annotation

GitHub Actions / ClangTidy Android

'virtual' is redundant since the function is already declared 'override' (modernize-use-override)

virtual void setId(int id) override { _id = id; };

Check failure on line 45 in native/cocos/audio/android/UrlAudioPlayer.h

View workflow job for this annotation

GitHub Actions / ClangTidy Android

'virtual' is redundant since the function is already declared 'override' (modernize-use-override)

virtual ccstd::string getUrl() const override { return _url; };

Check failure on line 47 in native/cocos/audio/android/UrlAudioPlayer.h

View workflow job for this annotation

GitHub Actions / ClangTidy Android

'virtual' is redundant since the function is already declared 'override' (modernize-use-override)

virtual State getState() const override { return _state; };

Check failure on line 49 in native/cocos/audio/android/UrlAudioPlayer.h

View workflow job for this annotation

GitHub Actions / ClangTidy Android

'virtual' is redundant since the function is already declared 'override' (modernize-use-override)

virtual void play() override;

Check failure on line 51 in native/cocos/audio/android/UrlAudioPlayer.h

View workflow job for this annotation

GitHub Actions / ClangTidy Android

'virtual' is redundant since the function is already declared 'override' (modernize-use-override)

virtual void pause() override;

Check failure on line 53 in native/cocos/audio/android/UrlAudioPlayer.h

View workflow job for this annotation

GitHub Actions / ClangTidy Android

'virtual' is redundant since the function is already declared 'override' (modernize-use-override)

virtual void resume() override;

Check failure on line 55 in native/cocos/audio/android/UrlAudioPlayer.h

View workflow job for this annotation

GitHub Actions / ClangTidy Android

'virtual' is redundant since the function is already declared 'override' (modernize-use-override)

virtual void stop() override;

Check failure on line 57 in native/cocos/audio/android/UrlAudioPlayer.h

View workflow job for this annotation

GitHub Actions / ClangTidy Android

'virtual' is redundant since the function is already declared 'override' (modernize-use-override)

virtual void rewind() override;

Check failure on line 59 in native/cocos/audio/android/UrlAudioPlayer.h

View workflow job for this annotation

GitHub Actions / ClangTidy Android

'virtual' is redundant since the function is already declared 'override' (modernize-use-override)

virtual void setVolume(float volume) override;

Check failure on line 61 in native/cocos/audio/android/UrlAudioPlayer.h

View workflow job for this annotation

GitHub Actions / ClangTidy Android

'virtual' is redundant since the function is already declared 'override' (modernize-use-override)

virtual float getVolume() const override;

Expand Down Expand Up @@ -119,6 +119,7 @@

std::thread::id _callerThreadId;
std::shared_ptr<bool> _isDestroyed;
std::mutex destoryMutex;

friend class SLUrlAudioPlayerCallbackProxy;
friend class AudioPlayerProvider;
Expand Down
Loading