我使用下面的代码从网络下载 AMR 文件并播放,AVAudioPlayer
但我总是收到unrecongnize selector sent to instance
错误。
这是开始下载和播放的方法:
- (IBAction)DisplayAudioPlayView:(id)sender
{
[self InitializePlayer];
}
-(void) InitializePlayer
{
// Get the file path to the doa audio to play.
NSString *filePath = [[ServerInteraction instance] getAudio:audioData.ID];
// Convert the file path to a URL.
NSURL *fileURL = [[NSURL alloc] initFileURLWithPath: filePath];
//Initialize the AVAudioPlayer.
audioPlayer= [AVPlayer playerWithURL:fileURL] ;
audioPlayer.delegate= self; //THIS LINE CAUSE ERROR//
// Preloads the buffer and prepares the audio for playing.
[audioPlayer prepareToPlay];
audioPlayer.currentTime = 0;
[audioPlayer play]
}
编辑
基于@Michael建议我更改了我的代码,这篇文章我将我的代码更改为:
NSURL *fileURL = [[NSURL alloc] initWithString: @"http://www.domain1.com/mysound.mp3"];
//Initialize the AVAudioPlayer.
audioPlayer= [AVPlayer playerWithURL:fileURL];
[audioPlayer play];
现在它播放了声音,但是当我使用http://maindomain.com/mysound.amr
它时它没有播放声音。