comment puis-je lire le file .mp3 à distance dans mon application ios?

J'essaie de lire le .mp3 file distant .mp3 file

mais c'est donner l'erreur suivante.

 The operation couldn't be completed. (OSStatus error -43.) 

voici mon code:

 - (void)viewDidLoad { [super viewDidLoad]; isPlaying = NO; /* NSURL *url = [NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"Dar-e-Nabi-Per" ofType:@"mp3"]]; */ NSURL *url = [NSURL URLWithSsortingng:@"http://megdadhashem.wapego.ru/files/56727/tubidy_mp3_e2afc5.mp3"]; NSError *error; audioPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:url error:&error]; if (error) { NSLog(@"Error in audioPlayer: %@", [error localizedDescription]); } else { audioPlayer.delegate = self; [audioPlayer prepareToPlay]; } } 

Quelqu'un peut-il s'il vous plaît me guider où je fais erreur

Pour diffuser de l'audio à partir d'un server distant, utilisez AVPlayer au lieu de AVAudioPLayer. Documentation AVPlayer

Exemple de code:

 - (void)playSampleSong:(NSSsortingng *)iSongName { NSSsortingng *aSongURL = [NSSsortingng ssortingngWithFormat:@"http://megdadhashem.wapego.ru/files/56727/tubidy_mp3_e2afc5.mp3"]; // NSLog(@"Song URL : %@", aSongURL); AVPlayerItem *aPlayerItem = [[AVPlayerItem alloc] initWithURL:[NSURL URLWithSsortingng:aSongURL]]; AVPlayer *anAudioStreamer = [[AVPlayer alloc] initWithPlayerItem:aPlayerItem]; [anAudioStreamer play]; // Access Current Time NSTimeInterval aCurrentTime = CMTimeGetSeconds(anAudioStreamer.currentTime); // Access Duration NSTimeInterval aDuration = CMTimeGetSeconds(anAudioStreamer.currentItem.asset.duration); } 

Utilisez ceci pour lire une chanson à partir d'une URL

 NSData *songData=[NSData dataWithContentsOfURL:url]; self.player = [[AVAudioPlayer alloc] initWithData:songData error:nil]; self.player.numberOfLoops=0; _player.delegate=self; [_player prepareToPlay]; [_player play]