Reputation: 2729
I looking for sample code for iOS (I guess, using AVMediaPlayer or AVPlayer) to play streaming audio, from URL (our current server URL is http://server.local:8008/ourradio.aac.m3u).
Audio stream also should be played, when application in background mode.
Upvotes: 1
Views: 4852
Reputation: 12085
M3U is a playlist format. It is a plain text file containing the locations of music files, most notably MP3 files. Read the Wikipedia Article about M3U. Then play each MP3 using this if you really want it on an iPhone:
AVPlayer *musicPlayer = [AVPlayer playerWithURL:musicLinkFromM3uFile];
[musicPlayer play];
where musicLinkFromM3uFile
is the location of the MP3 file read from the m3u file.
EDIT: And to be able to continue playing in background you will need to setup an audio session with category kAudioSessionCategory_MediaPlayback
. To do that add the following lines of codes to your applicationDidLoad in the app delegate:
UInt32 sessionCategory = kAudioSessionCategory_MediaPlayback;
AudioSessionSetProperty(kAudioSessionProperty_AudioCategory, sizeof(sessionCategory), &sessionCategory);
You will also need to set UIBackgroundModes
in your Info.plist to audio
.
Upvotes: 6
Reputation: 928
NSString *urlAddress = @"http://www.mysite.com/test.mp3";
urlStream = [NSURL URLWithString:urlAddress];
self.player = [AVPlayer playerWithURL:urlStream];
[player play];
Upvotes: 1