audo.fadeOut() on applicationExit?

Hi, I have music playing in the background and I'd like to have it fade out when the user exits the app on iOS. I see many games do this so would like to do the same with Corona. I've tried the following but it just cuts off instead of fading out:

-- Handle system events
local function onSystemEvent(event)
if event.type == "applicationExit" then
audio.fadeOut() -- fade out all audio channels
end
end

Runtime:addEventListener( "system", onSystemEvent );

Has anyone tried this and gotten it to work or is this the wrong approach? I'm using the defaults to fadeOut() here but I've tried decreasing the delay from the default 1 second to 250ms but no difference. Any ideas?

Corona tries to be very good about cleaning up after itself on shutdown. This means the audio engine is explicitly shutdown which probably explains why the music is stopped.

You might be able to work-around this (and I don't know if this will actually work for your case), but don't consider this as 'supported' and we are free to break this. Also be aware that this will expose you to another can of worms and should only be used by 'advanced' users.

First, you will want to make your app support fast suspend and resume so your application doesn't hard exit. Second, if that is not sufficient and you if you want to proceed, look at Audio Sessions:

http://developer.anscamobile.com/forum/2011/06/05/new-audiosession-properties

And you may need to set the MixMode to MediaPlaybackMixMode. And I think this has to be set before you get the suspend notification, otherwise it is already too late.

Thanks, I'll give this a try. Are there plans to support automatic audio fade out for applications that don't need/want to be multitasking? I'm not sure if this is normal behavior for iOS apps but that's what it seems with the apps I've tried.

views:1691 update:2011/9/28 21:38:26
corona forums © 2003-2011