Reputation: 479
I'm trying to develop one app where i will be having Play and Stop buttons .Once i click on Play button it should stream the audio which is being played on a particular link
-(void)playMusic
{
mAudioPlayer=[[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL URLWithString:@"http://www.tuneindia.com"] error:nil];
mAudioPlayer.delegate = self;
mAudioPlayer.volume=mVolumeSlider.value;
NSLog(@"THEVOLUME:::: %f",mVolumeSlider.value);
[mAudioPlayer prepareToPlay];
[mAudioPlayer play];
}
Kindly help me to understand how this AVAudioPlayer gets attached to a link and stream the audio from there (as we have used www.tuneindia.com).
Upvotes: 3
Views: 3231
Reputation: 6342
AVAudioPlayer is not meant for streaming. Init with URL is only meant for local file urls. Use AVPlayer to stream.
https://developer.apple.com/library/ios/qa/qa1634/_index.html
Upvotes: 4
Reputation: 654
In case you are wondering why it doesn't play music as you have written it, then the reason is that www.tuneindia.com refers to a webpage and not the particular stream. The stream on that webpage is located somewhere else (check the HTML source, it is seemingly not allowed to post that link here on StackOverflow). However, it may well be that you still cannot play it, the first parameter looks like a session cookie.
If you want to test your code, upload an MP3 file to a server where you can store files and then reference the URL in the player initialization like this: http://www.yourserver.com/path/to/yourmusic.mp3.
Upvotes: 3