Using MediaPlayer and AVFoundation Framework simultaniously in XCode - iphone

I'm an inexperienced XCode use and programmer in general so keep that in mind. I'm trying to use the microphone on the iPhone while at the same time allowing the user to play audio while using the "iPod music picker", but when the user selects music and plays it the recorder stops working? I have no idea what is going on here? Also, on a side note, how do you implement forward and back iPod buttons?
Thanks so much!

Sounds like this is an Audio Session issue - you're probably in a mode where you can either play or record, but not both at the same time.
Check out the Audio Session Programming Guide which should explain how to configure your session.
AVAudioSessionCategoryPlayAndRecord — Use this category for an application that inputs and outputs audio. The input and output need not occur simultaneously, but can if needed. This is the category to use for audio chat applications.
AVAudioSessionCategoryAmbient - This category allows audio from the iPod, Safari, and other built-in applications to play while your application is playing audio. You could, for example, use this category for an application that provides a virtual musical instrument that a user plays along to iPod audio.

Related

Recording from radio streaming xcode 4

I'm building an iPhone app which play some radio over internet ..
I want to make user able to record audio from my application to the radio channel he wants ..
what framework I must use .. and what code for implementation please ?
all Regards
Unfortunately, there is no way to directly capture from the "audio bus". You can either capture the audio via the internal microphone or headset microphone, but that's it. If you are rendering the audio, you could obviously also write that audio out to a file as well at the same time. That's pretty much your only option.

On iPhone, how do you allow another app to keep running in the background while your app is running?

For example, if I start a song in Pandora and then open Safari to browse the web the Pandora song will keep playing. However, if I start a song in Pandora and then open my app it kills the Pandora song. How do I let Pandora keep playing while my app is running?
You need to tell the iOS system what behavior it should use to integrate the two audio sessions. By default it cancels the background audio when you use audio. But this behavior can be modified as described in the AVAudioSession docs here.
To quote:
Working with Music Players
To play audio from a user’s iPod library along with your own sounds
(as described in iPod Library Access Programming Guide), you must use
a so-called mixable category configuration for your audio session.
There are two, alternative ways to configure an audio session as
mixable:
Use the AVAudioSessionCategoryAmbient (or the equivalent
kAudioSessionCategory_AmbientSound) category—which is always mixable.
Use the mixable category override property
kAudioSessionProperty_OverrideCategoryMixWithOthers, as described in
“Fine-Tuning the Category,” to make an otherwise nonmixable playback
category mixable. Having used one of these options, your sounds will
not interrupt a music player—and neither will a music player’s sounds
interrupt yours.
There are two reasons why your app might "kill" the background app:
It starts to play music of its own
You use too much memory for it to keep playing and the OS closes the background app
There is no special option you need to select; you just need to be a "good citizen."

How to allow ipod music to play while my app is running?

I'm using SimpleAudioEngine to play my sounds and I was wondering if there is anyway to check if iPod music is playing when the app is launched. If so, I want it to continue playing. I'm starting to think it may be called the simple engine for a reason as it doesn't allow features like this, where AVAudioEngine does...
Thanks :)
You should check out the official Audio Session Programming Guide and make sure that you are setting the correct session category. You will want to pick the category that allows your audio to mix with the iPod audio.

Listening to the iPhone mic with SCListener and playing music at the same time: how?

I am using Stephen Celis' SCListener class (for iPhone) to "listen" from the microphone, but I also need to be playing music at the same time using the MediaPlayer framework. However, when I start listening with SCListener, the music fades out and stops. I have set the kAudioSessionCategory_PlayAndRecord property on the audio session in SCListener, which should allow me to play audio and record audio at the same time, but as far as I can tell it has no effect. I'm confused, because according to other developers' results, this works just fine, but not for me. I'm thinking maybe the kAudioSessionCategory_PlayAndRecord property allows you to play sound and record if you're using the AVAudioPlayer framework or something to play the sound, but maybe not the MediaPlayer framework? This would be a problem for me because I need to play music from the user's iPod library, which, as far as I know is only possible to do using the MediaPlayer framework.
Does anyone know how I can get around this problem? Thanks in advance!
Unfortunately I still haven't found a solution to this problem. But after lots of testing, I'm pretty sure it's not possible to record sound while playing music with the MediaPlayer API, although if you use a different API to play sound, i.e. AVAudioPlayer, it usually does work. MediaPlayer is the only API that can play iPod music though.

iPhone: how to let the music play for an application using OpenAL?

I'm writing an iPhone app that uses OpenAL. When the application starts, the music playing in background stops.
The music actually stops playing when I initialize the OpenAL library.
My question is, is there any way to use OpenAL while letting the background music play?
You need to change the Audio Session Category to kAudioSessionCategory_AmbientSound instead of kAudioSessionCategory_SoloAmbientSound which is the default.
You can find out more about it in the Audio Session Programming Guide. Here's a link to the relevant part of the documentation.