Is this the default behavior for Corona to turn off device background music?

My users have been complaining about this:

They have some music playing in the background. And when my app starts, their music stops. They want to listen to their music while using my app because my app is actually a “silent” business app.

Is this the default behavior for Corona to turn off device background music?

Is there something I can do about this?

Have a look at this thread. I think it has the solution you need. 

Hi ksan :slight_smile:

It looks like the link to the thread you had in mind got lost when posting…

Oops. Sorry about that. I think it was this : 

http://forums.coronalabs.com/topic/38238-continue-separate-apps-music-playing/

Thanks, ksan

However, after I tried it, it does not work.

I found another thread: http://forums.coronalabs.com/topic/40837-allow-external-music

They are asking what I am asking too and they also found the suggested code does not work

audio.setSessionProperty(audio.MixMode, audio.AmbientMixMode)

The background music is stopped when the app launches.

And someone has filed a feature request for this:

http://feedback.coronalabs.com/forums/188732-corona-sdk-feature-requests-feedback/suggestions/5416670-allow-external-music-audio-to-keep-playing-in-back

It’s really weird (& unfriendly) to stop user’s background music especially if your app is actually silent. Please give it some votes. Already got several complaints about this.

For this to work I think you must also specify UIBackgroundModes in build.settings.

An example:

iphone = { plist = { UIStatusBarHidden = true, UIPrerenderedIcon = true,    UIApplicationExitsOnSuspend = false, UIBackgroundModes = { "audio" } } } 

Here’s a link to the official Apple docs:

https://developer.apple.com/library/mac/documentation/General/Reference/InfoPlistKeyReference/Articles/iPhoneOSKeys.html

I think this works OK for me. I have that UIBackgroundModes setting Ingemar pasted along with this code in my sound module:

[lua]

if audio.supportsSessionProperty then

    audio.setSessionProperty(audio.OverrideMixWithOthers, audio.MediaPlaybackMixMode)

end

[/lua]

I completely kill my app, start playing some music, launch app and music is not affected. 

@ingemar @jonjonsson

I added

UIBackgroundModes = { “audio” },

in my build.setting file, but the result is the same.

When my app launches, the background music is stopped.

How could you make it work?!   

ps. I tested it with iPhone 5S

Did you try replacing the audio.setSessionProperty(audio.MixMode, audio.AmbientMixMode) you have with what I pasted? 

Yes, I tried both. Both are not working for me.

If you like you can make a minimized demo project I can try it on my side and maybe we can figure out something conclusive.

@jonjonsson

Thanks a lot for the help.

I made a minimized demo project and it’s attached.

I use an app to play some music in the background and when the demo project starts, the music stops from my testing. Please give it a try.

Thanks.

I tested with latest daily and as you said it does not work.

I tried building with the Corona version I used to build my app with last time (Daily 2115) and it works. So Corona has changed something causing this not to work anymore.

I wish this would be officially supported by Corona, its a very important imho. 

Thanks a lot for the testing.

I guess we can only vote on this request

http://feedback.coronalabs.com/forums/188732-corona-sdk-feature-requests-feedback/suggestions/5416670-allow-external-music-audio-to-keep-playing-in-back

and then hope & wait.

But I have already got several complaints from users. I really hope Corona can do something about this at the earlist convenience. There is really no reason to stop users music. There are many apps that provide muting feature so users can listen to their music while using these apps. It’s really a nice & basic feature to have.

It’s a regression bug.

I did some testing myself and I can confirm that it works with build 2115.

After reading the change logs I saw that they did some substantial changes to the audio API in build 2130 and it looks like this functionality broke then.

Builds up to and including 2126 work fine, but with build 2130 and after it’s broken.

It would be a good idea if you could submit a bug report with the test project and also mention the fact that background audio mode broke in build 2130.

Filed a bug repot, Case 30208

Hope Corona can fix this regression bug asap. Already got several user complaints for the same case that my app turns off their music (There was none before this month)

I have an upcoming app that will be dependent on this too, so I also hope it’s fixed quickly.

This bug has been fixed in the latest build 2179

  • Core/iOS/Audio: Fixes casenum: 30208. Background music from other apps were being stopped when a Corona app launches.

I have tested it and verified I can listen to the background music while my app is launched initially or from the sleeping mode.

I have commented out this block of code, by the way.

--[[if audio.supportsSessionProperty == true then print("\n\naudio.supportsSessionProperty == true\n\n") audio.setSessionProperty(audio.OverrideMixWithOthers, audio.MediaPlaybackMixMode) end]]--

You may want to give it a try to see if you need any additional code to make it work for your case.

Woohoo!!! Great news… now if they can just fix this tableView/scrollView performance… lol

The problem is that Corona seems not thinking the problem exists. They have never responded tableView/scrollView performance problem in the forum. I am not really sure how they think about it.