controlling background audio

Is there any way to adjust or mute the audio from other apss? Like spotify, wimp or itunes?

I got the music running in the background along with my own sounds, but would like to be able to control the volume or mute other audio on occasions where its important that the user hears the sound being played in my app.

I have tried the itunes plugin but not liking that one much. For one you cant use it to control the itunes already playing on the phone, you have to set it up in the app and make the user choose songs etc. And when choosing songs you cant deselect a chosen song without clicking done and then open the list again. And you have to choose all the songs all over again.

no possible way to control volume of the audio that other apps are playing? 

Not that I’m aware of.

Rob

is there anyone that would know for sure? There seems to be so much undocumented and unsupported audio functions out there, so would be nice to know since its a very nice thing to be able to do. At least in apps that lets you play music from other apps but does have the options of sounding out alerts that the user should hear clearly.

Well I’ve never seen an IOS app that lets me do that.  It’s not possible with Corona SDK but if you know of other apps that are not from Apple that do it, then its probably doable in Enterprise.

Rob

I did some digging to try and see how others do it and it seems they use something called Duck. It lowers the volume of the audio from other apps when the running app is playing audio. And I did find that corona “supports” this mode for the audio sessions.

So by setting:

audio.setSessionProperty(audio.OtherMixableAudioShouldDuck, 1)

the music in the background will now automatically fade down abit when my app plays any soud, so that is working good. What does not happen is that it turns the volume back up after the audio from my app is done. So not automatic on that half. Seems there is something you have to do when your audio is done playing. And I dont know if “1” is the correct thing to pass as the value for that matter, but that worked. 

I found a page that explains the function of doing this in iOS:

http://www.annacallahan.com/blog/2010/01/21/duck-and-resume-a-little-love-from-the-iphone-music-player/

it refers to two other things at least that I can see that you need to do something about and that is:

AudioSessionSetActive and audioPlayerBeginInterruption/audioPlayerEndInterruption

I found that info for sessions in corona here:

http://developer.coronalabs.com/forum/2011/06/05/new-audiosession-properties

it does mention audio.ActiveMode (corresponds to Apple’s AudioSessionSetActive), but I have no idea how to actually use it like the other page say yet, and not sure about the begin and end interruption functions. So thats kind of where I am stuck right now… so it seems Corona at least half way supports what I want, just not sure if also can get the other half done without Enterprise.

Any help would be awesome!

ok, accoring to the page about ducking doing:

audio.setSessionProperty(audio.OtherMixableAudioShouldDuck, audio.AmbientMixMode)

and passing “AmbientMixMode” instead of “1” is probably more correct, but still works the same so not sure if maybe corona does something under the hood there and selects that when I did pass one, or one of the other mixmodes that works.

What happens if you pass a 0 in instead of a one, or maybe a nil?

Rob

passing 0 completely pauses the background music. nil does not work

I have also tried setting it to 

audio.setSessionProperty(audio.OverrideMixWithOthers, audio.AmbientMixMode)

after I have played a sound, but once it has ducked it stays ducked until I completely exit the app, then it fades the audio back up.

So what I need is a way to unduck it. I notice there was a function called audio.quit() before but it dosent work anymore so guessing that was removed. Not sure how this audio.ActiveMode is supposed to be used, maybe that is the key. If any of the programmers resposnible for the audio bit could take a quick look at this ducking function it would be nice.

actually, if I set audio.setSessionProperty(audio.OverrideMixWithOthers, audio.AmbientMixMode) after the sound has been played and ducking happens and then press the home button the audio will fade up after a short while.

so, ducking works with corona, just need to know how to make it fade up while still in the app? 

soI have been experimenting abit more. If I set it to duck and then play my sound it will duck. setting it back to overridemix will not do anything until I leave the app, either by terminating it completely or pushing the home button. It will fade back up if I exit. Now, if I set it back to ducking after setting it to override mix, nothing will happen as usual, but if I click the home button it fades the sound up, and when I go back to the app the sound fades down again.

Not sure if I am explaining all this in a good way but as far as I can see, setting these modes work as it should. The only problem is that the audio needs to be “reset”/stopped or something. I am guessing that the audio.ActiveMode is what could do this, but I dont know if this is actually working anymore in corona since the forumpost I found it in is so old. I have tried useing it like this:

audio.setSessionProperty(audio.ActiveMode, 0)

but I only get the error: "Error with AudioSessionSetProperty UInt32: ‘pty?’ "

giving it “false” or something just give the error that it was expecting a number. So anyone know the secret number to make it work? :slight_smile:

bump, still looking for answeres :slight_smile:

I’ll ask Engineering if they know any thing, but because you are using the undocumented API calls, that means there is little if any support for them.  I’m not sure I’ll get any answers.

You’ve pushed the use of these further than any one in the community that I know of and I don’t know how much help we can be answer your question, but I’ll ask.

Rob

Thanks Rob, that would be great :slight_smile:

Engineering has reported back and there isn’t much we can do about it.  It’s never been something we supported nor can we realistically support it. 

Rob

so for iOS there is now way to “reset” the audio so the sound will fade back up automatically? because everything else is working so you pretty much support it as is. Its just that it wont fade back up unless one does something like push the home button or exit the app. And the functions seems to be implemented at some point but not documented or explained how to work. I understand that you wont have support for it, but would be nice if worked. Its a function that alot of apps will benefit from.

The audio for other apps (iTunes, Tune-In Radio) stops as soon as my app starts.    How do you get it to continue playing?

in build.settings under iphone - plist - I have:

UIBackgroundModes = {“audio”, },

and then I set  audio.setSessionProperty(audio.MixMode, audio.AmbientMixMode) in my main.lua, music keeps playing in the background then. 

for my app I would like the ducking to work though. Its to bad it only seems to be able to duck down but you cant make it duck up again unless you hit the home button and go back into the app… unless there is another undocumented way hidden in there. Apple supports it so I wish corona would. Im sure there is something similar for android as well.

no possible way to control volume of the audio that other apps are playing? 

Not that I’m aware of.

Rob