How to keep the audio playing even when the screen goes off?

I am trying to build an audio player from the files residing in the device. The audio goes off when the screen is locked or it goes off. Please help!!

Cheers,

Akshay

No can do, if your app is suspended by the screen off, etc.

When your app suspends, everything it is doing suspends.

Corona does not continue to ‘run in the backdround’ it sleeps.

It certainly used to possible, at least on iOS, and I used the capability in a series of published apps about 3 or 4 years ago. However, it did use an API subject to change so may not still be supported, and I have not tried the technique with the current version of Corona.

Here’s what you need to do:

Add this to your build.settings …

iphone = { plist = { UIBackgroundModes =  { "audio", }, UIApplicationExitsOnSuspend = false, }, }

Then in main.lua …

-- set this propoerty to allow audio to continue playing when app suspended/screen locked or silent switch on -- N.B. this API is subject to change -- need to do this before any other audio calls -- N.B. this does not work in the Corona simulator only in iOS simulator or device if audio.supportsSessionProperty then print("setting audio to allow play to continue on suspend") audio.setSessionProperty(audio.OverrideMixWithOthers, audio.MediaPlaybackMixMode) end

Obviously this is iOS only and I don’t know if there is a similar technique for Android.

Here’s a reference to the unsupported/undocumented audio features …

https://forums.coronalabs.com/topic/51812-stopping-external-music/

Good luck!

Stefan

There is not a similar feature for Android. And while on iOS it may work today, it’s also unsupported and using undocumented features and isn’t guaranteed to work in future releases.

Rob

No can do, if your app is suspended by the screen off, etc.

When your app suspends, everything it is doing suspends.

Corona does not continue to ‘run in the backdround’ it sleeps.

It certainly used to possible, at least on iOS, and I used the capability in a series of published apps about 3 or 4 years ago. However, it did use an API subject to change so may not still be supported, and I have not tried the technique with the current version of Corona.

Here’s what you need to do:

Add this to your build.settings …

iphone = { plist = { UIBackgroundModes =  { "audio", }, UIApplicationExitsOnSuspend = false, }, }

Then in main.lua …

-- set this propoerty to allow audio to continue playing when app suspended/screen locked or silent switch on -- N.B. this API is subject to change -- need to do this before any other audio calls -- N.B. this does not work in the Corona simulator only in iOS simulator or device if audio.supportsSessionProperty then print("setting audio to allow play to continue on suspend") audio.setSessionProperty(audio.OverrideMixWithOthers, audio.MediaPlaybackMixMode) end

Obviously this is iOS only and I don’t know if there is a similar technique for Android.

Here’s a reference to the unsupported/undocumented audio features …

https://forums.coronalabs.com/topic/51812-stopping-external-music/

Good luck!

Stefan

There is not a similar feature for Android. And while on iOS it may work today, it’s also unsupported and using undocumented features and isn’t guaranteed to work in future releases.

Rob

BUMP. 

Is there still no way to do this on android and a limitation of Corona?

So how can one workaround this. 

Im guessing theres no way to tell the os to disable screen timeout

Is there a possible hack? could you simulate touch events maybe at some interval to make android think the user is still interacting?

any ideas?

You can do system.setIdleTimer() to cause the app to not go to sleep, but this is not an acceptable solution for playing audio.

Corona SDK makes an assumption that there will always be a UI present. If your backgrounded app attempts to do anything (update the screen in some way), we enter untested territory.

Corona SDK is not a good choice for building background music playing apps. Now you probably could use Corona Enterprise, play the background audio from the native side and as long as you don’t need to talk to the Corona/Lua side, you might get it to work.

Rob

BUMP. 

Is there still no way to do this on android and a limitation of Corona?

So how can one workaround this. 

Im guessing theres no way to tell the os to disable screen timeout

Is there a possible hack? could you simulate touch events maybe at some interval to make android think the user is still interacting?

any ideas?

You can do system.setIdleTimer() to cause the app to not go to sleep, but this is not an acceptable solution for playing audio.

Corona SDK makes an assumption that there will always be a UI present. If your backgrounded app attempts to do anything (update the screen in some way), we enter untested territory.

Corona SDK is not a good choice for building background music playing apps. Now you probably could use Corona Enterprise, play the background audio from the native side and as long as you don’t need to talk to the Corona/Lua side, you might get it to work.

Rob