tags:

views:

66

answers:

3

I am creating an iphone application and would like to download an audio file from the web (which I should be able to do without any assistance) but I am not familiar with any method to play that file on the device. Any assistance would be greatly appreciated, thank you :)

A: 

Use

AVAudioPlayer* player = [[AVAudioPlayer alloc] initWithContentsOfURL:... error:NULL];
...
[player play];
KennyTM
Ideally the file needs to be downloaded separately, since there will be some modifications to it.
Nippysaurus
@Nippysaurus: The "URL" can be a file URL.
KennyTM
A: 

Why don't you check the the MPMoviePlayerController class?

iPhone Dev Center: MPMoviePlayerController Class Reference http://bit.ly/aJ8tNI

tomute
I might be wrong ... but that looks like a movie player type control ... I just want to play some audio (there will be come controls and other stuff on the screen that the user will be interacting with).
Nippysaurus
You can play not only a movie but also an audio such as AAC-LC, MP3, etc.In addition, this class can play a audio file located in your app or a remote server.
tomute
+2  A: 

Check out Apress's book "Cool iPhone Projects" which has a chapter on Pandora's audio code. The source is also available http://apress.com/book/downloadfile/4453

The way they do it is to use the audio queue API which allows for concurrent download and playback of audio files over HTTP.

It's a good example and pretty much should illustrate one way of doing this.

One caveat with audio queues is that they can have high latency and are imprecise. For network based audio this doesn't come into play but AQs are pretty worthless for making musical instruments or doing any kind of real time behavior.

John Fricker