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

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.

Related

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

iPhone iOS5 what are my options for playing audio I do not have bundled in?

I currently have 3 ways to play audio within my app:
Using AudioServicesPlaySystemSound for vibration and simple
sounds
Using Audio Toolbox for bundled files (3rd party class)
Using AudioServices with AudioFX
What I'm currently investigating is, if I can play other kinds of audio that are already present on the iPhone. I would like to reduce my app's download size, as well as offer more flexibility in terms of the kind of sound that the user can play.
Can I play from within my app:
Audio recordings from the Voice Memos app, or do I have to
create my own recordings? Items from an iPod playlist or Music app?
Items from youtube by pre-loading them, or will I have to stream them every time?
Existing ringtone for the phone?
I am a complete beginner when it comes down to playing audio on an iPhone and am already using two 3rd party classes for audio tasks.
Is there an easy way to accomplish some of the tasks listed above?
1) Audio recordings from the Voice Memos app
It's been asked before and I don't believe it's possible from your app sandbox.
iPhone: Access voice memos programmatically
2) Items from an iPod playlist or Music app
There's an API for that, the iPod Access Library:
http://developer.apple.com/library/ios/#documentation/Audio/Conceptual/iPodLibraryAccess_Guide/Introduction/Introduction.html
3) Items from youtube
Should be possible, using a UIWebView.
http://iphoneincubator.com/blog/audio-video/how-to-play-youtube-videos-within-an-application
4) Existing ringtone for the phone
No, you can't access the current ringtone programatically.
How can I programmatically determine the default ringtone on an iPhone?
You can download sound files on first start (not in your didFinishLaunchingWithOptions method or your app will likely be killed) and save them locally, then you can just play them when needed. You can play files in their iTunes library, but won't know what they have in the library.
To play from their library, this is a handy example:
http://mobile.tutsplus.com/tutorials/iphone/ios-sdk-music-library-access/
You can also record user input from your app with AVAudioRecorder, save that and then play it whenever.

Using MediaPlayer and AVFoundation Framework simultaniously in XCode

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.

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.

First "Simple" Audio Player Application

Can anybody please tell me how to implement an audio player application in an iPhone? I am pretty new to iPhone development and I am just starting to learn the tricks of the trade.
PS: I need sample code!
If you want to play your own sounds, the AVAudioPlayer class. If you want to play media from the iPod library, see MPMusicPlayerController.