First "Simple" Audio Player Application - iphone

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.

Related

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.

Playing Audio on the iPhone

I want to play prerecorded audio for users in an iPhone application. Is the best way to play this audio to use openAL? Is there any other way that might be beneficial for what I want to accomplish?
Thanks!
Joe
For most needs, I've found AVAudioPlayer to be an excellent choice for audio playback.
OpenAL covers most audio cases nicely and it is tied to the Core Audio so playback speed is never lagged. Based on what details you gave, OpenAL will take of your needs

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.