new audioSession properties

I think the key is supposed to be audio.OverrideMixWithOthers (no MixMode suffix). The value should be 1 or 0 (maybe true or false will work; I don’t know).

audio.setSessionProperty(audio.OverrideMixWithOthers, 1)
Set this before you actually start recording.

[import]uid: 7563 topic_id: 10882 reply_id: 92901[/import]

OK, I got internal sound playback and recording working at the very least. Playing the iPod music seems to switch to the phone speaker for playback for some reason, but that feature isn’t really necessary for now, anyway.

Thanks for your help. [import]uid: 115248 topic_id: 10882 reply_id: 92927[/import]

Thanks ewing,
I would love to know can I record multiple sound at a time.
Because when I’m recording my voice on device then the background music(which is playing in my app) is stop. And I don’t want this, I want to record both sounds. [import]uid: 75428 topic_id: 10882 reply_id: 103283[/import]

sabir.ahmed59: If you are asking if you can simultaneously record a sound while playing back another sound, you must set the Audio Session category to the audio.PlayAndRecordMixMode.

[import]uid: 7563 topic_id: 10882 reply_id: 103350[/import]

Awesome post, great info.
Thanx for sharing! [import]uid: 123238 topic_id: 10882 reply_id: 114389[/import]

I hate to be the dense programmer here but reading all that gave me headache.

I want to have my app run, play sounds and such while the iPhone music player is playing music (or it could be Pandora or anything playing background audio).

Can someone digest this down to the minimum code I need to do to enable this?

Thanks
Rob
[import]uid: 19626 topic_id: 10882 reply_id: 128013[/import]

Hi Rob,

Yes, this is a tricky problem. Here’s what has worked for me.

First, at or very near the top of your main.lua file, put something like the following. I’ve found it’s necessary to run this before you make any audio API calls (even loading sounds or streams), or it won’t work.
[blockcode]
– Set the audio mix mode to allow sounds from the app to mix with other sounds from the device
if audio.supportsSessionProperty == true then
audio.setSessionProperty(audio.MixMode, audio.AmbientMixMode)
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
local isOtherAudioPlaying = false

if audio.supportsSessionProperty == true then
if not(audio.getSessionProperty(audio.OtherAudioIsPlaying) == 0) then
isOtherAudioPlaying = true
end
end
[/blockcode]

As a result of the mix mode, if the app is launched while the device is playing music, the music will continue to play. Moreover, when you play audio in your own app, it will mix with the audio that the device is already playing, which is typically what you would want to happen for sound effects. If your app has background music, you should play it only if isOtherAudioPlaying is false (otherwise your music will play at the same time as the music already playing on the device).

But that’s not all. To get this to work on suspend and resume events, you need to do a bit more.

In your appSuspend event, call audio.stop on your music channel and audio.dispose on your music handle. This ensures that when the app is resumed, audio.OtherAudioIsPlaying does not give the wrong result.

Then, in your appResume event, use the same exact code as above, and reload your music file (since it was disposed of when the app was suspended).

Hope this helps.

  • Andrew [import]uid: 109711 topic_id: 10882 reply_id: 128035[/import]

Thanks that helps quite a bit. I’m glad I’m not trying to make it work in my previous app since the current storyboard scene is responsible for its audio. This app only have a hand full of sounds that I load in main.lua, so I think I can implement this.

I have a question though… where do I use the isOtherAudioPlaying variable?

I think I hear some of my interface sounds, but I don’t hear the chime that plays at the beginning, so I’m not quite sure if it’s working or not.

Rob
[import]uid: 19626 topic_id: 10882 reply_id: 128036[/import]

For my purposes, I use the isOtherAudioPlaying variable when I’m deciding whether to play my background music or not, i.e., I enclose the audio.play call for my music within an if statement testing whether isOtherAudioPlaying is false. For sound effects, I play them regardless.

  • Andrew [import]uid: 109711 topic_id: 10882 reply_id: 128043[/import]

I hate to be the dense programmer here but reading all that gave me headache.

I want to have my app run, play sounds and such while the iPhone music player is playing music (or it could be Pandora or anything playing background audio).

Can someone digest this down to the minimum code I need to do to enable this?

Thanks
Rob
[import]uid: 19626 topic_id: 10882 reply_id: 128013[/import]

Hi Rob,

Yes, this is a tricky problem. Here’s what has worked for me.

First, at or very near the top of your main.lua file, put something like the following. I’ve found it’s necessary to run this before you make any audio API calls (even loading sounds or streams), or it won’t work.
[blockcode]
– Set the audio mix mode to allow sounds from the app to mix with other sounds from the device
if audio.supportsSessionProperty == true then
audio.setSessionProperty(audio.MixMode, audio.AmbientMixMode)
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
local isOtherAudioPlaying = false

if audio.supportsSessionProperty == true then
if not(audio.getSessionProperty(audio.OtherAudioIsPlaying) == 0) then
isOtherAudioPlaying = true
end
end
[/blockcode]

As a result of the mix mode, if the app is launched while the device is playing music, the music will continue to play. Moreover, when you play audio in your own app, it will mix with the audio that the device is already playing, which is typically what you would want to happen for sound effects. If your app has background music, you should play it only if isOtherAudioPlaying is false (otherwise your music will play at the same time as the music already playing on the device).

But that’s not all. To get this to work on suspend and resume events, you need to do a bit more.

In your appSuspend event, call audio.stop on your music channel and audio.dispose on your music handle. This ensures that when the app is resumed, audio.OtherAudioIsPlaying does not give the wrong result.

Then, in your appResume event, use the same exact code as above, and reload your music file (since it was disposed of when the app was suspended).

Hope this helps.

  • Andrew [import]uid: 109711 topic_id: 10882 reply_id: 128035[/import]

Thanks that helps quite a bit. I’m glad I’m not trying to make it work in my previous app since the current storyboard scene is responsible for its audio. This app only have a hand full of sounds that I load in main.lua, so I think I can implement this.

I have a question though… where do I use the isOtherAudioPlaying variable?

I think I hear some of my interface sounds, but I don’t hear the chime that plays at the beginning, so I’m not quite sure if it’s working or not.

Rob
[import]uid: 19626 topic_id: 10882 reply_id: 128036[/import]

For my purposes, I use the isOtherAudioPlaying variable when I’m deciding whether to play my background music or not, i.e., I enclose the audio.play call for my music within an if statement testing whether isOtherAudioPlaying is false. For sound effects, I play them regardless.

  • Andrew [import]uid: 109711 topic_id: 10882 reply_id: 128043[/import]

Hello Ewing. A quick question regarding all this. I am reading up on all the mix modes. It looks like I can record at the same time as play. All I would like to do is play a sound and while that is playing, record that sound or whatever is currently playing . Is this possible? Ideally I would also have the option of disabling the microphone so it only uses the sounds playing if I wanted to. The cherry on the top would be able to monitor the audio level of the internal sounds played.

I am not having much luck so far this is what I have

   audio.setSessionProperty(audio.MixMode, audio.PlayAndRecordMixMode)

    –  audio.setSessionProperty(audio.OverrideAudioRoute, true)–just something to test out

   audio.setSessionProperty(audio.OverrideMixWithOthers, true) --set before recording

The bottom line perhaps I need to play with but perhaps I am missing something?

ah I’m getting close. Is is possible that instead of the audio.play sounds going out to the speaker and then back into the microphone, to route directly to the record first and then hear/monitor the sound, and then adjusting or muting the microphone record volume? 

.

Hi @BeatsnBobs.

The API features you are looking at are undocumented, test options.  What you are trying to do is beyond the scope of our currently supported API.  They are also very likely incompatible between devices.

Hello Ewing. A quick question regarding all this. I am reading up on all the mix modes. It looks like I can record at the same time as play. All I would like to do is play a sound and while that is playing, record that sound or whatever is currently playing . Is this possible? Ideally I would also have the option of disabling the microphone so it only uses the sounds playing if I wanted to. The cherry on the top would be able to monitor the audio level of the internal sounds played.

I am not having much luck so far this is what I have

   audio.setSessionProperty(audio.MixMode, audio.PlayAndRecordMixMode)

    –  audio.setSessionProperty(audio.OverrideAudioRoute, true)–just something to test out

   audio.setSessionProperty(audio.OverrideMixWithOthers, true) --set before recording

The bottom line perhaps I need to play with but perhaps I am missing something?

ah I’m getting close. Is is possible that instead of the audio.play sounds going out to the speaker and then back into the microphone, to route directly to the record first and then hear/monitor the sound, and then adjusting or muting the microphone record volume? 

.