Tony
Tony

Reputation: 10208

Play remote mp3 using iOS

I have a remote mp3 (small file, just a few seconds) which I have the URL. I need to play it on an App that uses iOS 4.

The URL is not exactly a .mp3 file, but it is a dynamic .php url that requests the .mp3 file. If I put that php route in the browser it downloads the mp3 file.

I am trying to use this project (https://github.com/mattgallagher/AudioStreamer) but it isn't working. The audio starts but it only plays a part of it.

How can I do it?

Upvotes: 3

Views: 2967

Answers (1)

Michael Dautermann
Michael Dautermann

Reputation: 89509

If it's truly just a small (and static, non-streaming) mp3 file, why not consider doing something like:

NSError * error = nil;
AVAudioPlayer * avPlayerObject =
    [[AVAudioPlayer alloc] initWithContentsOfURL: yourRemoteURL error:&error];
if(avPlayerObject)
{
    [avPlayerObject play];
}

Check out Apple's AVAudioPlayer class (documentation linked for you).

Upvotes: 5

Related Questions