play URL audio using AVAudioPlayer

AVAudioPlayer is used to play audio file in iPhone. However, according to the document, it only support playing local audio file:

http://developer.apple.com/iphone/library/qa/qa2009/qa1634.html

To solve this problem, we can create a NSData using the NSURL and play the data using AVAudioPlayer


NSData *soundData = [NSData dataWithContentsOfURL:url];
AVAudioPlayer *avPlayer = [[AVAudioPlayer alloc] initWithData:soundData error: nil];
[avPlayer play];