iosobjective-ccaf

How to play .caf audio file from server url in ios


I try to play audio from server url but nothing play, But i try to play audio from document directory path url and it play fine.

NSData *songData=[NSData dataWithContentsOfURL:[NSURL URLWithString:
[NSString stringWithFormat:@"%@",aSongURL]]];
AVAudioPlayer *abc = [[AVAudioPlayer alloc] initWithData:songData error:nil];
abc.numberOfLoops=0;
[abc prepareToPlay];
[abc play];

Solution

  • You can try this. Hope it helps.

    AVPlayer *objAVPlayer = [[AVPlayer alloc] initWithURL:url];
    [objAVPlayer play];