The power button should dispatch the applicationSuspend event, where you can stop all audio. Does this not work?
Google Play Apps Editorial Board raises issue of sound playing after app was suspended (new Nexus 7)
Nope, the applicationSuspend is never dispatched before the app is shut down, there is just no time, the shutdown is instantly.
The applicationSuspend event is received when the app resumes to work (and that’s of course to late), and then closely followed by the applicationResume event. This is a known problem on Android, and because of this the switching off of sound is handled another way (by the Corona Labs SDK).
Well, and this switching off of the sound seems sometimes not to work on some devices. And because it happens only sometimes it’s hard to reproduce, that’s the reason for me testing if this might be an evil timing issue.
Thanks & best,
Andreas
Now it happened on our other Corona apps on the new NEXUS 7, too (like “Little Rainbow Fish”, test with the free LITE version on the NEXUS 7 - https://play.google.com/store/apps/details?id=de.oetinger.rainbowfishenandroidlite):
1.) when the user leaves the app idle on the Main Menu, and the screen darkens, the background music sometimes continues to play over the device Lock screen.
2.) when the the device is shut off sometimes (not often, but every so often) the bg music continues to play in the background
* daily build 1206
* new Google Nexus 7 tablet
* Android 4.3, kernel 3.4.0-g6537a16, build-number JSS15Q
[UPDATE]: As a workaround for problem #1 I set the idle timer to false and uploaded the new version 1.41, but you can still test the second problem with the persistent sound after turning off the device with the download.
We need some help here, it is really important for us to get featured by Google (ok, whom am I kidding, this would be important for everybody).
Best,
Andreas
Andreas,
I downloaded your Freeze! app onto my New Nexus 7, but was not able to reproduce this issue. I tried pressing the power button several times. The audio stopped playing every time for me. I tried with a screen lock set to “Slide” and “None” (if it matters). I even tried pressing the Home button too. The device was Android OS version 4.3, kernel version 3.4.0.g9e52a21, build number JSS15R. A different version than your, but our New Nexus 7 claims it is up to date.
I know this was an issue in the past on certain devices, but was fixed by the last release version, before build #1202.
Are you able to reproduce this issue with our sample projects? Can you try testing this with sample project “Media/SimpleMixer” please?
Hi Joshua,
thanks for checking this!
I will test with SimpleMixer tonight, and additionally with a totally stripped down version of “Freeze!” that only starts the looped bg music.
Best,
Andreas
Hi Joshua,
I tried with SimpleMixer, but couldn’t replicate the sound bug.
But it happens with “Freeze!” and our other Android apps (with and without Google Play Game Services) on the NEXUS 7.
We use only the following libraries, nothing fancy:
* Particle Candy
* gtween
I was wondering if maybe the size of the app (“Freeze!” is about 45 MB) may have something to do with the issue, because much more is going on internally than with the simple examples like SimpleMixer.
To locate the problem I started adb logcat and started “Freeze!” a few times, the bg music starts to play as soon as the home screen of the game is displayed.
And then I switched off with the power button - and after a few tries the bug occurred and the bg music continued to play on the switched off device.
Here is the log for the normal shut down when everything is fine and the music stops to play in the bg:
– BG MUSIC STOPPED AFTER SHUT DOWN
I/PowerManagerService( 518): Going to sleep by user request…
D/SurfaceFlinger( 176): Screen released, type=0 flinger=0xb8735478
D/audio_hw_primary( 179): adev_set_parameters: enter: screen_state=off
D/audio_hw_primary( 179): adev_set_parameters: exit with code(-2)
I/L ( 4498): videos.remote.MediaRouteManager.stopScan:155 Scanning stopped
D/BaseCastMediaRouteProvider( 4498): in onDiscoveryRequestChanged: request=null
D/YouTube ( 6518): youtube.app.prefetch.g.onReceive:367 Received: android.intent.action.SCREEN_OFF
V/KeyguardHostView( 518): hide transport, gen:1
V/KeyguardHostView( 518): music state changed: 0
D/SsdpScanner( 4498): Receive thread got an exception; mShouldStop=true
D/SsdpScanner( 4498): java.net.SocketException: Socket closed
D/SsdpScanner( 4498): at libcore.io.Posix.recvfromBytes(Native Method)
D/SsdpScanner( 4498): at libcore.io.Posix.recvfrom(Posix.java:140)
D/SsdpScanner( 4498): at libcore.io.BlockGuardOs.recvfrom(BlockGuardOs.java:164)
D/SsdpScanner( 4498): at libcore.io.IoBridge.recvfrom(IoBridge.java:506)
D/SsdpScanner( 4498): at java.net.PlainDatagramSocketImpl.doRecv(PlainDatagramSocketImpl.java:161)
D/SsdpScanner( 4498): at java.net.PlainDatagramSocketImpl.receive(PlainDatagramSocketImpl.java:169)
D/SsdpScanner( 4498): at java.net.DatagramSocket.receive(DatagramSocket.java:253)
D/SsdpScanner( 4498): at com.google.cast.SsdpScanner.a(SourceFile:372)
D/SsdpScanner( 4498): at com.google.cast.SsdpScanner.a(SourceFile:45)
D/SsdpScanner( 4498): at com.google.cast.SsdpScanner$b.run(SourceFile:625)
D/SsdpScanner( 4498): at java.lang.Thread.run(Thread.java:841)
D/DeviceManager( 4498): notifyStateChanged: 0
D/PhoneStatusBar( 653): disable: < expand icons alerts ticker system_info back home RECENT* clock search >
D/SurfaceControl( 518): Excessive delay in blankDisplay() while turning screen off: 292ms
V/TAG ( 518): bug 7643792: fitSystemWindows([0,50][0,0])
D/PhoneStatusBar( 653): disable: < expand icons alerts ticker system_info BACK* HOME* RECENT CLOCK* search >
I/wpa_supplicant( 633): wlan0: WPA: Group rekeying completed with 00:1c:4a:4a:27:e4 [GTK=TKIP]
D/audio_hw_primary( 179): out_standby: enter: usecase(1: low-latency-playback)
D/audio_hw_primary( 179): stop_output_stream: enter: usecase(1: low-latency-playback)
D/audio_hw_primary( 179): disable_audio_route: reset mixer path: low-latency-playback
D/audio_hw_primary( 179): disable_snd_device: snd_device(2: speaker)
D/audio_hw_primary( 179): stop_output_stream: exit: status(0)
D/audio_hw_primary( 179): out_standby: exit
And here is the log for the bug, the music didn’t stop playing:
– BG MUSIC CONTINUED TO PLAY AFTER SHUT DOWN
I/PowerManagerService( 518): Going to sleep by user request…
D/LightsService( 518): Excessive delay setting light: 53ms
D/SurfaceFlinger( 176): Screen released, type=0 flinger=0xb8735478
D/audio_hw_primary( 179): adev_set_parameters: enter: screen_state=off
D/audio_hw_primary( 179): adev_set_parameters: exit with code(-2)
V/KeyguardHostView( 518): hide transport, gen:1
V/KeyguardHostView( 518): music state changed: 0
I/L ( 4498): videos.remote.MediaRouteManager.stopScan:155 Scanning stopped
D/BaseCastMediaRouteProvider( 4498): in onDiscoveryRequestChanged: request=null
D/YouTube ( 6518): youtube.app.prefetch.g.onReceive:367 Received: android.intent.action.SCREEN_OFF
D/SsdpScanner( 4498): Receive thread got an exception; mShouldStop=true
D/SsdpScanner( 4498): java.net.SocketException: Socket closed
D/SsdpScanner( 4498): at libcore.io.Posix.recvfromBytes(Native Method)
D/SsdpScanner( 4498): at libcore.io.Posix.recvfrom(Posix.java:140)
D/SsdpScanner( 4498): at libcore.io.BlockGuardOs.recvfrom(BlockGuardOs.java:164)
D/SsdpScanner( 4498): at libcore.io.IoBridge.recvfrom(IoBridge.java:506)
D/SsdpScanner( 4498): at java.net.PlainDatagramSocketImpl.doRecv(PlainDatagramSocketImpl.java:161)
D/SsdpScanner( 4498): at java.net.PlainDatagramSocketImpl.receive(PlainDatagramSocketImpl.java:169)
D/SsdpScanner( 4498): at java.net.DatagramSocket.receive(DatagramSocket.java:253)
D/SsdpScanner( 4498): at com.google.cast.SsdpScanner.a(SourceFile:372)
D/SsdpScanner( 4498): at com.google.cast.SsdpScanner.a(SourceFile:45)
D/SsdpScanner( 4498): at com.google.cast.SsdpScanner$b.run(SourceFile:625)
D/SsdpScanner( 4498): at java.lang.Thread.run(Thread.java:841)
D/DeviceManager( 4498): notifyStateChanged: 0
D/PhoneStatusBar( 653): disable: < expand icons alerts ticker system_info back home RECENT* clock search >
D/SurfaceControl( 518): Excessive delay in blankDisplay() while turning screen off: 294ms
V/KeyguardHostView( 518): hide transport, gen:1
V/KeyguardHostView( 518): music state changed: 0
V/TAG ( 518): bug 7643792: fitSystemWindows([0,50][0,0])
D/PhoneStatusBar( 653): disable: < expand icons alerts ticker system_info BACK* HOME* RECENT CLOCK* search >
As you can see there is no internal crash of my game or bad stuff happening.
But once in a while after shut down the whole stop-audio-block is missing:
D/audio_hw_primary( 179): out_standby: enter: usecase(1: low-latency-playback)
D/audio_hw_primary( 179): stop_output_stream: enter: usecase(1: low-latency-playback)
D/audio_hw_primary( 179): disable_audio_route: reset mixer path: low-latency-playback
D/audio_hw_primary( 179): disable_snd_device: snd_device(2: speaker)
D/audio_hw_primary( 179): stop_output_stream: exit: status(0)
D/audio_hw_primary( 179): out_standby: exit
So there might be a problem with the audio HAL implementation, because on exit sometimes these functions are not called?
Hope this helps,
best,
Andreas
You said earlier that you’re app is not receiving an “applicationSuspend” event, right?
If that’s the case, then that is the root cause of this issue, because Corona will automatically pause audio playback when it raises a suspend event.
If this is the issue, then we’re likely running into a multithreading issue. Trouble is, we still can’t reproduce it… even after testing with your app. So, if the problem is in fact in our code, we’re left guessing as to where it could be. We’ll keep looking.
One more question. Is your app using any plugins?
If you are, then we can double check them for multithreading issues.
Oh and one more question. Are you positive that your app is built with build #1202 or higher?
Would you mind double checking please?
I ask because we thought we fixed this issue months ago. Sometimes developers have a “build.settings” option or system setting set to force the Corona Simulator to build with a specific build number (or special beta version) and I want to make sure that hasn’t happened to you. It’s rare, but sometimes it happens and causes confusion.
Just add the following line to your “main.lua” file. It’ll print the Corona build number to the Android log.
print("@@@ Corona Build: " … tostring(system.getInfo(“build”)))
Thanks.
Hi Joshua,
I thought that it is normal that we don’t get the “applicationSuspend” event before the shutdown when the power of the Android device is shut manually off using the button?
I get the event after the device is turned on again, closely followed by the resume event.
To your questions:
>Is your app using any plugins?
“Freeze!” is using the Google Play Games plugin for Leaderboards & Achievements, but e.g. the “Little Rainbow Fish” doesn’t use any plugins, and the same bug happens on the NEXUS 7.
>Are you positive that your app is built with build #1202 or higher?
Yes, in both cases I used 1206. This is definite, because I needed 1206 for the xxhdpi icons demanded by the Google Review Team, and now they accepted the apps and the xxhdpi icons are in.
Hm, both apps not only have the problem with the manual hard power off, but they both have the issue that the bg music sometimes continues to play when you do not touch the device for a while and a soft shutdown happens. In these cases the applicationSuspend event should have been sent, but it wasn’t. So this really seems to be the problem.
But you cannot test this with my apps, because for that part of the problem I made updates for my apps with the shutdown on idle set to false.
Best,
Andreas
This doesn’t directly fix your problem, but as a work around you can set the IdleTimerto false so that the device does not go to sleep while your game is open. There are many games that do this.
Hi Jon,
thanks for the idea, it’s a good one!
But it won’t solve the problem with the sound continuing to play when the device is shut off using the power button.
I tried to start my continuously playing bg music after a wait of a few seconds and not right in the beginning after the app started (I thought that the bug is so strange that it might be a timing issue), but it didn’t help at all.
And yes: I know that every developer just hates problems like these. And before I post a bug report I would like to know if the Corona Labs team (that was already looking into that problem, when I remember correctly they were able to confirm this on a NOOK device) is already on it.
Best,
Andreas
The power button should dispatch the applicationSuspend event, where you can stop all audio. Does this not work?
Nope, the applicationSuspend is never dispatched before the app is shut down, there is just no time, the shutdown is instantly.
The applicationSuspend event is received when the app resumes to work (and that’s of course to late), and then closely followed by the applicationResume event. This is a known problem on Android, and because of this the switching off of sound is handled another way (by the Corona Labs SDK).
Well, and this switching off of the sound seems sometimes not to work on some devices. And because it happens only sometimes it’s hard to reproduce, that’s the reason for me testing if this might be an evil timing issue.
Thanks & best,
Andreas
Now it happened on our other Corona apps on the new NEXUS 7, too (like “Little Rainbow Fish”, test with the free LITE version on the NEXUS 7 - https://play.google.com/store/apps/details?id=de.oetinger.rainbowfishenandroidlite):
1.) when the user leaves the app idle on the Main Menu, and the screen darkens, the background music sometimes continues to play over the device Lock screen.
2.) when the the device is shut off sometimes (not often, but every so often) the bg music continues to play in the background
* daily build 1206
* new Google Nexus 7 tablet
* Android 4.3, kernel 3.4.0-g6537a16, build-number JSS15Q
[UPDATE]: As a workaround for problem #1 I set the idle timer to false and uploaded the new version 1.41, but you can still test the second problem with the persistent sound after turning off the device with the download.
We need some help here, it is really important for us to get featured by Google (ok, whom am I kidding, this would be important for everybody).
Best,
Andreas
Andreas,
I downloaded your Freeze! app onto my New Nexus 7, but was not able to reproduce this issue. I tried pressing the power button several times. The audio stopped playing every time for me. I tried with a screen lock set to “Slide” and “None” (if it matters). I even tried pressing the Home button too. The device was Android OS version 4.3, kernel version 3.4.0.g9e52a21, build number JSS15R. A different version than your, but our New Nexus 7 claims it is up to date.
I know this was an issue in the past on certain devices, but was fixed by the last release version, before build #1202.
Are you able to reproduce this issue with our sample projects? Can you try testing this with sample project “Media/SimpleMixer” please?
Hi Joshua,
thanks for checking this!
I will test with SimpleMixer tonight, and additionally with a totally stripped down version of “Freeze!” that only starts the looped bg music.
Best,
Andreas
Hi Joshua,
I tried with SimpleMixer, but couldn’t replicate the sound bug.
But it happens with “Freeze!” and our other Android apps (with and without Google Play Game Services) on the NEXUS 7.
We use only the following libraries, nothing fancy:
* Particle Candy
* gtween
I was wondering if maybe the size of the app (“Freeze!” is about 45 MB) may have something to do with the issue, because much more is going on internally than with the simple examples like SimpleMixer.
To locate the problem I started adb logcat and started “Freeze!” a few times, the bg music starts to play as soon as the home screen of the game is displayed.
And then I switched off with the power button - and after a few tries the bug occurred and the bg music continued to play on the switched off device.
Here is the log for the normal shut down when everything is fine and the music stops to play in the bg:
– BG MUSIC STOPPED AFTER SHUT DOWN
I/PowerManagerService( 518): Going to sleep by user request…
D/SurfaceFlinger( 176): Screen released, type=0 flinger=0xb8735478
D/audio_hw_primary( 179): adev_set_parameters: enter: screen_state=off
D/audio_hw_primary( 179): adev_set_parameters: exit with code(-2)
I/L ( 4498): videos.remote.MediaRouteManager.stopScan:155 Scanning stopped
D/BaseCastMediaRouteProvider( 4498): in onDiscoveryRequestChanged: request=null
D/YouTube ( 6518): youtube.app.prefetch.g.onReceive:367 Received: android.intent.action.SCREEN_OFF
V/KeyguardHostView( 518): hide transport, gen:1
V/KeyguardHostView( 518): music state changed: 0
D/SsdpScanner( 4498): Receive thread got an exception; mShouldStop=true
D/SsdpScanner( 4498): java.net.SocketException: Socket closed
D/SsdpScanner( 4498): at libcore.io.Posix.recvfromBytes(Native Method)
D/SsdpScanner( 4498): at libcore.io.Posix.recvfrom(Posix.java:140)
D/SsdpScanner( 4498): at libcore.io.BlockGuardOs.recvfrom(BlockGuardOs.java:164)
D/SsdpScanner( 4498): at libcore.io.IoBridge.recvfrom(IoBridge.java:506)
D/SsdpScanner( 4498): at java.net.PlainDatagramSocketImpl.doRecv(PlainDatagramSocketImpl.java:161)
D/SsdpScanner( 4498): at java.net.PlainDatagramSocketImpl.receive(PlainDatagramSocketImpl.java:169)
D/SsdpScanner( 4498): at java.net.DatagramSocket.receive(DatagramSocket.java:253)
D/SsdpScanner( 4498): at com.google.cast.SsdpScanner.a(SourceFile:372)
D/SsdpScanner( 4498): at com.google.cast.SsdpScanner.a(SourceFile:45)
D/SsdpScanner( 4498): at com.google.cast.SsdpScanner$b.run(SourceFile:625)
D/SsdpScanner( 4498): at java.lang.Thread.run(Thread.java:841)
D/DeviceManager( 4498): notifyStateChanged: 0
D/PhoneStatusBar( 653): disable: < expand icons alerts ticker system_info back home RECENT* clock search >
D/SurfaceControl( 518): Excessive delay in blankDisplay() while turning screen off: 292ms
V/TAG ( 518): bug 7643792: fitSystemWindows([0,50][0,0])
D/PhoneStatusBar( 653): disable: < expand icons alerts ticker system_info BACK* HOME* RECENT CLOCK* search >
I/wpa_supplicant( 633): wlan0: WPA: Group rekeying completed with 00:1c:4a:4a:27:e4 [GTK=TKIP]
D/audio_hw_primary( 179): out_standby: enter: usecase(1: low-latency-playback)
D/audio_hw_primary( 179): stop_output_stream: enter: usecase(1: low-latency-playback)
D/audio_hw_primary( 179): disable_audio_route: reset mixer path: low-latency-playback
D/audio_hw_primary( 179): disable_snd_device: snd_device(2: speaker)
D/audio_hw_primary( 179): stop_output_stream: exit: status(0)
D/audio_hw_primary( 179): out_standby: exit
And here is the log for the bug, the music didn’t stop playing:
– BG MUSIC CONTINUED TO PLAY AFTER SHUT DOWN
I/PowerManagerService( 518): Going to sleep by user request…
D/LightsService( 518): Excessive delay setting light: 53ms
D/SurfaceFlinger( 176): Screen released, type=0 flinger=0xb8735478
D/audio_hw_primary( 179): adev_set_parameters: enter: screen_state=off
D/audio_hw_primary( 179): adev_set_parameters: exit with code(-2)
V/KeyguardHostView( 518): hide transport, gen:1
V/KeyguardHostView( 518): music state changed: 0
I/L ( 4498): videos.remote.MediaRouteManager.stopScan:155 Scanning stopped
D/BaseCastMediaRouteProvider( 4498): in onDiscoveryRequestChanged: request=null
D/YouTube ( 6518): youtube.app.prefetch.g.onReceive:367 Received: android.intent.action.SCREEN_OFF
D/SsdpScanner( 4498): Receive thread got an exception; mShouldStop=true
D/SsdpScanner( 4498): java.net.SocketException: Socket closed
D/SsdpScanner( 4498): at libcore.io.Posix.recvfromBytes(Native Method)
D/SsdpScanner( 4498): at libcore.io.Posix.recvfrom(Posix.java:140)
D/SsdpScanner( 4498): at libcore.io.BlockGuardOs.recvfrom(BlockGuardOs.java:164)
D/SsdpScanner( 4498): at libcore.io.IoBridge.recvfrom(IoBridge.java:506)
D/SsdpScanner( 4498): at java.net.PlainDatagramSocketImpl.doRecv(PlainDatagramSocketImpl.java:161)
D/SsdpScanner( 4498): at java.net.PlainDatagramSocketImpl.receive(PlainDatagramSocketImpl.java:169)
D/SsdpScanner( 4498): at java.net.DatagramSocket.receive(DatagramSocket.java:253)
D/SsdpScanner( 4498): at com.google.cast.SsdpScanner.a(SourceFile:372)
D/SsdpScanner( 4498): at com.google.cast.SsdpScanner.a(SourceFile:45)
D/SsdpScanner( 4498): at com.google.cast.SsdpScanner$b.run(SourceFile:625)
D/SsdpScanner( 4498): at java.lang.Thread.run(Thread.java:841)
D/DeviceManager( 4498): notifyStateChanged: 0
D/PhoneStatusBar( 653): disable: < expand icons alerts ticker system_info back home RECENT* clock search >
D/SurfaceControl( 518): Excessive delay in blankDisplay() while turning screen off: 294ms
V/KeyguardHostView( 518): hide transport, gen:1
V/KeyguardHostView( 518): music state changed: 0
V/TAG ( 518): bug 7643792: fitSystemWindows([0,50][0,0])
D/PhoneStatusBar( 653): disable: < expand icons alerts ticker system_info BACK* HOME* RECENT CLOCK* search >
As you can see there is no internal crash of my game or bad stuff happening.
But once in a while after shut down the whole stop-audio-block is missing:
D/audio_hw_primary( 179): out_standby: enter: usecase(1: low-latency-playback)
D/audio_hw_primary( 179): stop_output_stream: enter: usecase(1: low-latency-playback)
D/audio_hw_primary( 179): disable_audio_route: reset mixer path: low-latency-playback
D/audio_hw_primary( 179): disable_snd_device: snd_device(2: speaker)
D/audio_hw_primary( 179): stop_output_stream: exit: status(0)
D/audio_hw_primary( 179): out_standby: exit
So there might be a problem with the audio HAL implementation, because on exit sometimes these functions are not called?
Hope this helps,
best,
Andreas
You said earlier that you’re app is not receiving an “applicationSuspend” event, right?
If that’s the case, then that is the root cause of this issue, because Corona will automatically pause audio playback when it raises a suspend event.
If this is the issue, then we’re likely running into a multithreading issue. Trouble is, we still can’t reproduce it… even after testing with your app. So, if the problem is in fact in our code, we’re left guessing as to where it could be. We’ll keep looking.
One more question. Is your app using any plugins?
If you are, then we can double check them for multithreading issues.
Oh and one more question. Are you positive that your app is built with build #1202 or higher?
Would you mind double checking please?
I ask because we thought we fixed this issue months ago. Sometimes developers have a “build.settings” option or system setting set to force the Corona Simulator to build with a specific build number (or special beta version) and I want to make sure that hasn’t happened to you. It’s rare, but sometimes it happens and causes confusion.
Just add the following line to your “main.lua” file. It’ll print the Corona build number to the Android log.
print("@@@ Corona Build: " … tostring(system.getInfo(“build”)))
Thanks.
Hi Joshua,
I thought that it is normal that we don’t get the “applicationSuspend” event before the shutdown when the power of the Android device is shut manually off using the button?
I get the event after the device is turned on again, closely followed by the resume event.
To your questions:
>Is your app using any plugins?
“Freeze!” is using the Google Play Games plugin for Leaderboards & Achievements, but e.g. the “Little Rainbow Fish” doesn’t use any plugins, and the same bug happens on the NEXUS 7.
>Are you positive that your app is built with build #1202 or higher?
Yes, in both cases I used 1206. This is definite, because I needed 1206 for the xxhdpi icons demanded by the Google Review Team, and now they accepted the apps and the xxhdpi icons are in.
Hm, both apps not only have the problem with the manual hard power off, but they both have the issue that the bg music sometimes continues to play when you do not touch the device for a while and a soft shutdown happens. In these cases the applicationSuspend event should have been sent, but it wasn’t. So this really seems to be the problem.
But you cannot test this with my apps, because for that part of the problem I made updates for my apps with the shutdown on idle set to false.
Best,
Andreas