Sound Stream not stopping on screen time outs

As the title suggests, the sound is continuing to play when my app is suspended via screen time out. 

Build 2015.2646

On my nexus 5 and 7 it will not stop playing on a screen time out only. The power button will stop the audio stream.

It is a significant issue as Google Play will not release your app if it break the lifestyle guide lines… the the sound issue breaks those.

How do I fix this? Ideas?

Thanks,

Gullie

You can use the system.applicationSuspend API to detect when the system goes to sleep due to inactivity and then pause your audio.

https://docs.coronalabs.com/api/event/system/type.html

Tried it. Doesn’t work… Suspend isn’t called on a screen timeout.

I can’t believe no one else has had this issue with background music.

Any other thoughts?

Fuse?

-------More--------

In Fact, a screen time out totally messes with the streaming sounds and additional adjustments to audio.setVolme() via the suspend function. audio.pause() seems to work better.

Also, the suspend function is completely undependable if you expect it to be called before actually being suspended… sometimes it does, others it doesn’t. I’m sure it’s fine for game updates to timers and things not not for this. But screen timeouts… it is never called.

Bump!

Hi Gullie,

What version of Android do you have on those phones? I’ve just tested with one of my apps that allows the phone to suspend, and when it happens, the audio stops, and when i resume it, the audio keeps its normal flow.

Just tested it on 5.0, but as far as i know, this was not a problem with 4.4.4 or even 2.1 (i think thats the OS version i was using when the game was released), and i’m not using anything special.

Sorry if this was not what you mean by “screen time out”

Both the Nexus 5 and 7 have Android 5.1.1

For clarity, the correct nomenclature is “sleep,” not “screen time out.”  --From the Android interface’s title.

Also of note: the power button works correctly w/ sound stopping on the device being manually put to sleep via the button and with no special code required to handle this.

However, on previous Android versions I did have this issue… Sound failing to be stopped on the power button presses. Additionally, My Nexus 4 with Android Jelly bean… All works as expected without additional code needed.  

So my guess is this may be platform specific?

Hey Rob Miracle? Time to live up to your name! :wink:

The relevant code is:

function setVolumeMute( isMute ) if isMute then print("Mute Audio") audio.pause( sound.channels.music1 ) audio.pause( sound.channels.music2 ) elseif not isMute then print("Unmute Audio") audio.resume( sound.channels.music1 ) audio.resume( sound.channels.music2 ) end end local function playMusic() audio.setVolume( sound.channels.musicVolume, { channel = sound.channels.music1 } ) audio.setVolume( sound.channels.musicVolume, { channel = sound.channels.music2 } ) clipDuration[1] = audio.getDuration( sound.fx[soundToPlay .. "01"] ) local function playAfterDelay() audio.play( sound.fx[soundToPlay .. "02"], { channel = sound.channels.music2, loops = -1 } ) end audio.play( sound.fx[soundToPlay .. "01"], { channel = sound.channels.music1 } ) sound.soundTimer = timer.performWithDelay( clipDuration[1], playAfterDelay ) end

You can use the system.applicationSuspend API to detect when the system goes to sleep due to inactivity and then pause your audio.

https://docs.coronalabs.com/api/event/system/type.html

Tried it. Doesn’t work… Suspend isn’t called on a screen timeout.

I can’t believe no one else has had this issue with background music.

Any other thoughts?

Fuse?

-------More--------

In Fact, a screen time out totally messes with the streaming sounds and additional adjustments to audio.setVolme() via the suspend function. audio.pause() seems to work better.

Also, the suspend function is completely undependable if you expect it to be called before actually being suspended… sometimes it does, others it doesn’t. I’m sure it’s fine for game updates to timers and things not not for this. But screen timeouts… it is never called.

Bump!

Hi Gullie,

What version of Android do you have on those phones? I’ve just tested with one of my apps that allows the phone to suspend, and when it happens, the audio stops, and when i resume it, the audio keeps its normal flow.

Just tested it on 5.0, but as far as i know, this was not a problem with 4.4.4 or even 2.1 (i think thats the OS version i was using when the game was released), and i’m not using anything special.

Sorry if this was not what you mean by “screen time out”

Both the Nexus 5 and 7 have Android 5.1.1

For clarity, the correct nomenclature is “sleep,” not “screen time out.”  --From the Android interface’s title.

Also of note: the power button works correctly w/ sound stopping on the device being manually put to sleep via the button and with no special code required to handle this.

However, on previous Android versions I did have this issue… Sound failing to be stopped on the power button presses. Additionally, My Nexus 4 with Android Jelly bean… All works as expected without additional code needed.  

So my guess is this may be platform specific?

Hey Rob Miracle? Time to live up to your name! :wink:

The relevant code is:

function setVolumeMute( isMute ) if isMute then print("Mute Audio") audio.pause( sound.channels.music1 ) audio.pause( sound.channels.music2 ) elseif not isMute then print("Unmute Audio") audio.resume( sound.channels.music1 ) audio.resume( sound.channels.music2 ) end end local function playMusic() audio.setVolume( sound.channels.musicVolume, { channel = sound.channels.music1 } ) audio.setVolume( sound.channels.musicVolume, { channel = sound.channels.music2 } ) clipDuration[1] = audio.getDuration( sound.fx[soundToPlay .. "01"] ) local function playAfterDelay() audio.play( sound.fx[soundToPlay .. "02"], { channel = sound.channels.music2, loops = -1 } ) end audio.play( sound.fx[soundToPlay .. "01"], { channel = sound.channels.music1 } ) sound.soundTimer = timer.performWithDelay( clipDuration[1], playAfterDelay ) end