Allow external music

I have a lot of sound in my app, but offer the ability to turn it down with in-game volume controls. Is it possible to allow users to play music from another app?

Will you play files from other apps or let other apps play your files?

On Apple’s platform, It is possible in native Objective-C to access the itunes library even though the app is sanboxed. I have not seen this type of functionality in Corona.  

Hi @jensto,

Coincidentally, we just added iTunes library support via the iTunes plugin. Here’s the post about it:

http://www.coronalabs.com/blog/2013/10/28/daily-build-roundup-selectcapture-video-itunes-library-access/

@beernathan,

I’m not sure if this is what you mean by playing music from “another app”. If you mean, playing music from (say) Cut the Rope inside a Corona app, then no, this won’t do it.

Best regards,

Brent

I meant - if they already have music playing (from iTunes, a Podcast, or something), I don’t want my app to stop the other sound and play mine when I have the sound levels down to zero. Have seen this work with other games, but no specific examples spring to mind.

The iTunes plugin looks really cool - I’ll have a play with it - looks like a good compromise (for iOS at least).

Will you play files from other apps or let other apps play your files?

On Apple’s platform, It is possible in native Objective-C to access the itunes library even though the app is sanboxed. I have not seen this type of functionality in Corona.  

Hi @jensto,

Coincidentally, we just added iTunes library support via the iTunes plugin. Here’s the post about it:

http://www.coronalabs.com/blog/2013/10/28/daily-build-roundup-selectcapture-video-itunes-library-access/

@beernathan,

I’m not sure if this is what you mean by playing music from “another app”. If you mean, playing music from (say) Cut the Rope inside a Corona app, then no, this won’t do it.

Best regards,

Brent

I meant - if they already have music playing (from iTunes, a Podcast, or something), I don’t want my app to stop the other sound and play mine when I have the sound levels down to zero. Have seen this work with other games, but no specific examples spring to mind.

The iTunes plugin looks really cool - I’ll have a play with it - looks like a good compromise (for iOS at least).

Rob/Brent/others - I’m after the same direction/advice too - any update here?  

Basically same a beernathan, but to re-iterate:

a) iTunes Music/Podcasts - ability to have background music/audio to keep playing when you launch your app (i.e. corona sdk built)

b) Other Apps (e.g. audible.com app for audiobooks) - ability to have audio from such an app continuing when you launch your app (i.e. corona sdk built)

I’m guessing (b) may not be possible, but at least how do you implement (a)?   I know there are apps out there (well I’ve seen IOS ones at least) which offer the ability for your background music to keep playing, but need to find out how to do this with Corona SDK?  or if it’s not yet possible just to understand this.   

EDIT: Have just checked, and for example I note that Candy Crush satisfies both (a) and (b) from above.  That is music keeps playing in the background, but also my Audible Audiobook app keeps playing the audiobook so I can listen to this whilst in Candy Crush (which itself still produces sound effects).

Note, my app was intending to just play short audio clips (e.g. menu button pushes) on top of the background music/audio.  That is wasn’t planning to stream music in my app

Hello, I have the same question -
is it possible to to have background music/audio (from iTunes, Podcasts) to keep playing when you launch your app?

Thanks

@Rob/Brent - can I get some feedback from Coronalabs on this please?  

(I have a small app ready to go, but wanted to wait and see if I could incorporate something before releasing it to solve/implement this)

There are two answers here.

1.  Can you Corona based app play audio while it’s in the background.  On iOS you can set a background mode for audio that Apple allows, however Engineering has told me on many occasions that we (Corona Labs) do not officially support these background modes and they are “use at your own risk”.  We do not test these modes.  We may make changes in the future that may break it and if we do, you’ve been told it’s unsupported, so no complaining if we do.  On Android, this simply will not work.  You can search for UIBackgroundModes in the forums

  1. Can other App’s audio that has been backgrounded play while my Corona SDK app is in the Foreground.  Yes.  There is an audio flag that you have to set that allows the music to play.  I think this is part of the undocumented audio features:

        – 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.MixMode, audio.AmbientMixMode)
        end

Since this is part of the undocumented audio features, it’s subject to change without notice as well and probably should also be classified as unsupported. 

thanks Rob - your response 2 was exactly what I was interested in - can I clarify, re the approach you put forward in your dot point 2:

a) this would work for both using streaming and non-streaming audio in your Corona app?  (assume yes, but just checking)

b) re “may be subject to change” - ummm - I guess the question is what is the risk of it changing?  would you use the approach in one of your apps?  Actually is the risk here would I be correct in saying:

 - once your app is built and deployed there is no risk to that version right?

 - when you rebuild (on a later Corona release) for an upgrade would be where the risk is, but if you test before releasing the upgrade you can mitigate the risk (i.e. pull out the property worst case)

Update - Tested this Rob.  Unfortunately does not work when you launch your app, i.e. background musics drops off.  I do note if your app was already in the background and then you comeback from “sleep” mode (forget correct term) then it works in this case.

I’ll stick in a feature request as I think this is now a fairly important item to have.  My daughter won’t play games that don’t allow her to keep playing her music in the background :slight_smile:

Created a feature request here:

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

Are you using audio.* calls to play audio or the media.playEventSound()?

only using audio.* calls Rob

I have many requests from my app users too, asking why my app stops their background music they are listening to.

I also tested the code 

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

And it does NOT work.

My app is totally silent & there is no reason (from user’s perspective) to stop their music. I think this feature is very reasonable & should be added to Corona lib asap.

Just to be sure, you are using this with audio.* calls not media.* calls right?

Also have you verified that:  audio.supportsSessionProperty    is returning true??

Rob

I added following code in the start of main.lua:

if audio.supportsSessionProperty == true then print("\n\naudio.supportsSessionProperty == true\n\n") audio.setSessionProperty(audio.MixMode, audio.AmbientMixMode) end

When my app launches, the print statement is executed, so I am sure audio.supportsSessionProperty is true and the audio.setSessionProperty() is called.

And there are two testing results:

(1) When the background music is playing, launch my app, the background music stops.

(2) Launch my app first, press Home key to put my app in the background and start some background music. Launch my app again (from the background), the music continues.

I think the results above are consistent with “greg886” earlier post:

Update - Tested this Rob.  Unfortunately does not work when you launch your app, i.e. background musics drops off.  I do note if your app was already in the background and then you comeback from “sleep” mode (forget correct term) then it works in this case.

I know this works.  So I did a test and what I found is at least with iTunes and Pandora, when my Corona app launched, the music playing in the background paused.  I could go out, resume play and the audio is mixed as expected.  This is on iOS 7.  Perhaps Apple changed something with iOS 7.  But if I swipe up on the control panel, the music resumes without me having to do anything.

On Android it works as expected.

These modes are technically not supported. 

So I don’t know if we can advise you any further on this.

Rob