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

[Android] fix an audio bug #1788

Merged
merged 3 commits into from Aug 2, 2019

Conversation

@unace
Copy link
Contributor

commented Jul 31, 2019

[Android] fix an audio bug that audios are not paused when locking screen while notification drawer is showing. Technically they are paused however they are resumed right after paused even though the screen locked.

repro steps:

  1. play audio
  2. swipe down the notification drawer
  3. lock the screen
unace added 2 commits Jul 28, 2019
Add ability to not stop sound & music on game start in android
This comes from cocos2d/cocos2d-x#18640.
fix an audio bug that audios are not paused when locking screen while notification drawer is showing.
@minggo

This comment has been minimized.

Copy link
Contributor

commented Aug 1, 2019

It is strange that #1785 is merged, why this PR also has these modifications.

@minggo

This comment has been minimized.

Copy link
Contributor

commented Aug 1, 2019

Ok, i got it, you use the same branch without synchronizing the codes.

@@ -355,7 +371,7 @@ public void onWindowFocusChanged(boolean hasFocus) {
}

private void resumeIfHasFocus() {
if(hasFocus) {
if(hasFocus && !paused) {

This comment has been minimized.

Copy link
@minggo

minggo Aug 1, 2019

Contributor

Why it is needed? resumeIfHasFocus() is invoked by onResume(), and paused is set to false.

This comment has been minimized.

Copy link
@unace

unace Aug 1, 2019

Author Contributor

in the scenario that I described, below steps happen.

  1. onWindowFocusChanged(false) is called when swiping down notification drawer.
  2. onPause() is called when locking the screen. -> This pauses all audios.
  3. onWindowFocusChanged(true) is called right after 2. -> call resumeIfHasFocus() -> This resumes all audios even though the screen has been locked.

So it seems to be needed to check pause status.

I verified this scenario on Google Pixel XL and Google Pixel 2.

detail Cocos2dxActivity logs
D/Cocos2dxActivity: onWindowFocusChanged() hasFocus=false
D/Cocos2dxActivity: onPause()
D/Cocos2dxActivity: onWindowFocusChanged() hasFocus=true
D/Cocos2dxActivity: onWindowFocusChanged() hasFocus=false

@minggo minggo merged commit 55ccf41 into cocos-creator:v2.1.3 Aug 2, 2019
1 check passed
1 check passed
continuous-integration/travis-ci/pr The Travis CI build passed
Details
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants
You can’t perform that action at this time.