Audio keeps playing on Android in sleep mode (2013.1225)

Howdy!

When I start my app which plays a background music and then turn off the device (sleep mode) the audio keeps playing. I don’t set anything regarding audio in build.settings nor config.lua.

Is this behavior default now? Can it be changed?

Thanks!

This is definitely not normal behavior.  Can you post your build.settings file and any audio calls that would be setting flags or calling any settings parameters.

build.settings

-- Supported values for orientation: -- portrait, portraitUpsideDown, landscapeLeft, landscapeRight settings = { orientation = { default = "landscapeRight", supported = { "landscapeRight", } }, iphone = { plist = { UIStatusBarHidden = false, UIPrerenderedIcon = true, -- set to false for "shine" overlay UIApplicationExitsOnSuspend = true, UIAppFonts = { "happy\_sans.ttf" }, } }, --[[For Android: androidPermissions = { "android.permission.INTERNET", },]]-- }

the code for playing the background music

function init()     handles = { }     musicStream = nil     musicVolume = 0.75     soundVolume = 0.75     audio.reserveChannels(25)     -- load sounds     handles["bark1"] = audio.loadSound("audio/bark1.mp3") ... more sound effects } function playMusic() if musicStream==nil then musicStream = audio.loadStream("audio/whatever.mp3") end if audio.isChannelPlaying(1)==false then stopMusic() audio.setVolume(musicVolume, {channel=1}) audio.play(musicStream, {channel=1, loops=-1}) end end function fadeOutMusic() audio.fadeOut({channel=1, time=200}) end function stopMusic() audio.stop(1) end

audiolib.init() is called in scene:createScene(event) of the first scene of the app.

audiolib.playMusic() is called in the same method a few lines below.

during the game sometimes fadeOutMusic() is called, then playMusic() again.

hope that helps

Are you building for Android or iOS and what version of Corona SDK are you using?

If you’re building for iOS your app is set to exit hard on suspend and there is no way it should continue playing.  You don’t have the background mode set, nor do I see you using some of the hidden properties to affect it either.

You could trap your system events and when you see a suspend event, stop your audio and on a resume event start it back up as a work around.

I build for Android using Corona SDK 2013.1225

Thanks for the tip about catching the system events. I’ll keep that in mind.

I cannot reproduce it anymore with the build I made today. It works as expected again. So I close this topic for now.

This is definitely not normal behavior.  Can you post your build.settings file and any audio calls that would be setting flags or calling any settings parameters.

build.settings

-- Supported values for orientation: -- portrait, portraitUpsideDown, landscapeLeft, landscapeRight settings = { orientation = { default = "landscapeRight", supported = { "landscapeRight", } }, iphone = { plist = { UIStatusBarHidden = false, UIPrerenderedIcon = true, -- set to false for "shine" overlay UIApplicationExitsOnSuspend = true, UIAppFonts = { "happy\_sans.ttf" }, } }, --[[For Android: androidPermissions = { "android.permission.INTERNET", },]]-- }

the code for playing the background music

function init()     handles = { }     musicStream = nil     musicVolume = 0.75     soundVolume = 0.75     audio.reserveChannels(25)     -- load sounds     handles["bark1"] = audio.loadSound("audio/bark1.mp3") ... more sound effects } function playMusic() if musicStream==nil then musicStream = audio.loadStream("audio/whatever.mp3") end if audio.isChannelPlaying(1)==false then stopMusic() audio.setVolume(musicVolume, {channel=1}) audio.play(musicStream, {channel=1, loops=-1}) end end function fadeOutMusic() audio.fadeOut({channel=1, time=200}) end function stopMusic() audio.stop(1) end

audiolib.init() is called in scene:createScene(event) of the first scene of the app.

audiolib.playMusic() is called in the same method a few lines below.

during the game sometimes fadeOutMusic() is called, then playMusic() again.

hope that helps

Are you building for Android or iOS and what version of Corona SDK are you using?

If you’re building for iOS your app is set to exit hard on suspend and there is no way it should continue playing.  You don’t have the background mode set, nor do I see you using some of the hidden properties to affect it either.

You could trap your system events and when you see a suspend event, stop your audio and on a resume event start it back up as a work around.

I build for Android using Corona SDK 2013.1225

Thanks for the tip about catching the system events. I’ll keep that in mind.

I cannot reproduce it anymore with the build I made today. It works as expected again. So I close this topic for now.