Background Music from Other Apps (again...)

Hello people,

I need help with allowing playback of music from other apps when my game is playing. In the past, this used to work with the following function:

[lua]

local function keepPlayingAudio()
  print(“keepPlaying is true”)
   – Set the audio mix mode to allow sounds from the app to mix with other sounds from the device
   
   if audio.supportsSessionProperty == true then
      print(“supportsSessionProperty is true”)
      audio.setSessionProperty(audio.OverrideMixWithOthers, audio.MediaPlaybackMixMode)   
   end
   
      – Store whether other audio is playing. It’s important to do this once and store the result now,
      – as referring to audio.OtherAudioIsPlaying later gives misleading results, since at that point
      – the app itself may be playing audio
   isOtherAudioPlaying = false
   if audio.supportsSessionProperty == true then
         – print(“supportsSessionProperty is true”)
      if not(audio.getSessionProperty(audio.OtherAudioIsPlaying) == 0) then
              print(“OtherAudioIsPlaying is true”)

         isOtherAudioPlaying = true
      end
   end
end

[/lua]

The debug print lines are all firing on device, yet the music from the other app (iTunes) is interrupted. I found this:

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

And it seems there was no follow-up from the devs.

Thanks.

To the unfortunate having issues with this, it looks like in the current build you will need to use these options instead:

[lua]

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

[/lua]

To have the music from other apps playing while users are using your app.

Important: add this at the top of your main.lua file, before you start playing any audio file.

Just to clarify for people finding this post later.

audio.setSessionProperty() is an iOS only feature and is part of the “hidden” undocumented audio properties. These are not supported and may change in the future. Use at your own risk. 

Rob

Yes, Rob, this is the thing we have been hearing until 2012, and we understand it. I worked also with XCode and directly in Objective-C for years, and these are not easy things to include in a framework.

This said, do keep in mind that you had many people voting to have this included in the official release, and that this is a high priority feature in these days (it has always been, to be honest), where half of the games in the store have little or irrelevant music because people prefer to play them with iTunes running in the background.

In the case of our app, lack of this feature would have forced us to not use Corona or switch to Enterprise, which is too expensive for the volume of users we have.

The API’s have been there since 2011, but because we can’t make it cross-platform, it stays undocumented and unsupported. 

Enterprise is now free to everyone, for what it’s worth.

Rob

It’s worth a lot! :wink:

I believe that adding a small section in the documentation with a giant warning on top of it might be helpful to those developing only on iOS. I keep coming to Corona and recommending it to my clients that target also only iOS because, simply put, on the long term, even if you work only on iOS, an app made with Corona, over the years, requires half the changes than an app developed using only Apple’s frameworks directly does.

This is is because you guys do a nice job at creating an abstraction layer that has been very consistent over the years.

I had to change maybe less than 60 lines of code to update an app I originally developed in 2012.

Why isn’t that the default behavior (like on Android), that the background music keeps playing? Other engines also behave this way.

I also find it quite poor - especially for a 2D engine which you would use for e.g. puzzles - that there is no official way on iOS to enable users to listen to their own music while playing your game.

Anyway, at least thanks for providing this “hidden” way.

Best regards!

Gave this a try and it doesn’t work. Did I miss anything? Where exactly do I call audio.setSessionProperty(audio.MixMode, audio.AmbientMixMode)?

@egarayblas, audio.setSessionProperty() is an iOS only option. It will not work on Android at all. You can call it in main.lua as soon as possible before you start playing any audio.

Keep in mind these are not supported.

Rob

@Rob why can this not be cross platform?  I have plenty Android games on my phone that allow music to continue playing so clearly this is not an Android issue.

Noted Rob, thanks! It works great on my iOS device now. :slight_smile:

Agree, it would be great if Android can have this too.

@SGS: Have you tried submitting a feature request to Corona yet?

How is this handled for Android?

And I have now tested this on iOS with adding

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

to the start of the main.lua

First it works fine, but when an ad is loaded and shown the background music (like a podcast for example) is turned off until the ad has finished, then the podcast continues BUT all the sounds inside the app are still silenced and audio.play is no longer working. What can I do to make this work also? Call audio.setSessionProperty(audio.MixMode, audio.AmbientMixMode) again maybe after the ad is finished?

To the unfortunate having issues with this, it looks like in the current build you will need to use these options instead:

[lua]

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

[/lua]

To have the music from other apps playing while users are using your app.

Important: add this at the top of your main.lua file, before you start playing any audio file.

Just to clarify for people finding this post later.

audio.setSessionProperty() is an iOS only feature and is part of the “hidden” undocumented audio properties. These are not supported and may change in the future. Use at your own risk. 

Rob

Yes, Rob, this is the thing we have been hearing until 2012, and we understand it. I worked also with XCode and directly in Objective-C for years, and these are not easy things to include in a framework.

This said, do keep in mind that you had many people voting to have this included in the official release, and that this is a high priority feature in these days (it has always been, to be honest), where half of the games in the store have little or irrelevant music because people prefer to play them with iTunes running in the background.

In the case of our app, lack of this feature would have forced us to not use Corona or switch to Enterprise, which is too expensive for the volume of users we have.

The API’s have been there since 2011, but because we can’t make it cross-platform, it stays undocumented and unsupported. 

Enterprise is now free to everyone, for what it’s worth.

Rob

It’s worth a lot! :wink:

I believe that adding a small section in the documentation with a giant warning on top of it might be helpful to those developing only on iOS. I keep coming to Corona and recommending it to my clients that target also only iOS because, simply put, on the long term, even if you work only on iOS, an app made with Corona, over the years, requires half the changes than an app developed using only Apple’s frameworks directly does.

This is is because you guys do a nice job at creating an abstraction layer that has been very consistent over the years.

I had to change maybe less than 60 lines of code to update an app I originally developed in 2012.

Why isn’t that the default behavior (like on Android), that the background music keeps playing? Other engines also behave this way.

I also find it quite poor - especially for a 2D engine which you would use for e.g. puzzles - that there is no official way on iOS to enable users to listen to their own music while playing your game.

Anyway, at least thanks for providing this “hidden” way.

Best regards!

Gave this a try and it doesn’t work. Did I miss anything? Where exactly do I call audio.setSessionProperty(audio.MixMode, audio.AmbientMixMode)?

@egarayblas, audio.setSessionProperty() is an iOS only option. It will not work on Android at all. You can call it in main.lua as soon as possible before you start playing any audio.

Keep in mind these are not supported.

Rob