How to play a music file using URL link in iPhone?

后端 未结 5 728
无人共我
无人共我 2020-12-13 05:12

I want to play a music file using URL Link in the iPhone. But when I use the below code I am getting error I am not getting where I am going wrong. Can anyone Correct me?

5条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-13 05:59

    Current Answer:

    Now consider Why does AVAudioPlayer initWithContentsOfURL always fail with error code=-43 link. its solution is avplayer link

    Earlier Answer

    //You have to pass NSURL not NSData
     NSString* resourcePath = @"http://192.167.1.104:8888/SHREYA.mp3"; //your url
     NSURL *url = [NSURL alloc]initWithString:resourcePath];
     audioPlayer = [[AVAudioPlayer alloc] initWithURL:url error:&error];
    
     audioPlayer.delegate = self;
     [url release];
    
     [audioPlayer prepareToPlay];
     [audioPlayer play];
    

提交回复
热议问题