简体   繁体   中英

Audio streaming using AVAudioPlayer

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).

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

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 .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM