Amir Peivandi
Amir Peivandi

Reputation: 369

Playing mp3 files over http in IOS

Forgive me if this is already answered, believe me I've seen too many answers but can't find the one I can get to match exactly what I need. I have a bunch of mp3 files on my web server. I want to have an IOS application that connects to my server and streams the mp3 files. I do not need live streaming, I do not want to download the file and play it locally. I created a m3u file and I can point to it from my browser and it plays the files but when I used Apple's MovePlayer sample code it fails playing the file!

Any help as usual is appreciated.

Upvotes: 2

Views: 2731

Answers (2)

Mick MacCallum
Mick MacCallum

Reputation: 130193

I personally don't know how to set up MPMoviePlayer to play .m3u files, however if you can accomplish the same task with an mp3, that can easily be done using AVAudioFoundation.

-(IBAction)playStreamMP3:(id)sender
{
    NSData *fetchedData = [[NSData alloc] initWithContentsOfURL:[NSURL URLWithString:@"http://mysite.com/mysounds.mp3"]];
    if (data)
    {
        [data stop]; //data is an iVar holding any existing playing music
        data = nil;
    }
    data = [[AVAudioPlayer alloc] initWithData:fetchedData error:nil];
    data.delegate = self;
    [data play];
}

Upvotes: 6

overboming
overboming

Reputation: 1542

I don't think Apple's MPMoviePlayerController handle .m3u file format, but it's not a complicated format, you can always parse the playlist and feed actual mp3 url to it.

Upvotes: 1

Related Questions