Jump to content

[TOPIC: topicViewTemplate]
[GLOBAL: userSmallPhoto]
Photo

Background Music from Other Apps (again...)
Started by MagnetiCat Mar 26 2018 02:36 PM

11 replies to this topic

Best Answer MagnetiCat , 26 March 2018 - 03:09 PM

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

 

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

 

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.

[TOPIC CONTROLS]
[/TOPIC CONTROLS]
[modOptionsDropdown]
[/modOptionsDropdown]
[reputationFilter]
[TOPIC: post.html]
#1

MagnetiCat

[GLOBAL: userInfoPane.html]
MagnetiCat
  • Enthusiast

  • 35 posts
  • Enterprise

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:

 

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

 

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.



[TOPIC: post.html]
#2

MagnetiCat

[GLOBAL: userInfoPane.html]
MagnetiCat
  • Enthusiast

  • 35 posts
  • Enterprise

  Best Answer

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

 

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

 

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.



[TOPIC: post.html]
#3

Rob Miracle

[GLOBAL: userInfoPane.html]
Rob Miracle
  • Moderator

  • 24,102 posts
  • Corona Staff

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



[TOPIC: post.html]
#4

MagnetiCat

[GLOBAL: userInfoPane.html]
MagnetiCat
  • Enthusiast

  • 35 posts
  • Enterprise

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.



[TOPIC: post.html]
#5

Rob Miracle

[GLOBAL: userInfoPane.html]
Rob Miracle
  • Moderator

  • 24,102 posts
  • Corona Staff

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



[TOPIC: post.html]
#6

MagnetiCat

[GLOBAL: userInfoPane.html]
MagnetiCat
  • Enthusiast

  • 35 posts
  • Enterprise

It's worth a lot! ;)

 

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.



[TOPIC: post.html]
#7

bjoern

[GLOBAL: userInfoPane.html]
bjoern
  • Enthusiast

  • 55 posts
  • Corona SDK

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!



[TOPIC: post.html]
#8

egarayblas

[GLOBAL: userInfoPane.html]
egarayblas
  • Contributor

  • 105 posts
  • Corona SDK

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



[TOPIC: post.html]
#9

Rob Miracle

[GLOBAL: userInfoPane.html]
Rob Miracle
  • Moderator

  • 24,102 posts
  • Corona Staff

@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



[TOPIC: post.html]
#10

SGS

[GLOBAL: userInfoPane.html]
SGS
  • Corona Geek

  • 1,819 posts
  • Corona SDK

@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.



[TOPIC: post.html]
#11

egarayblas

[GLOBAL: userInfoPane.html]
egarayblas
  • Contributor

  • 105 posts
  • Corona SDK

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

 

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

 

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



[TOPIC: post.html]
#12

d.mach

[GLOBAL: userInfoPane.html]
d.mach
  • Contributor

  • 633 posts
  • Corona SDK

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?




[topic_controls]
[/topic_controls]