【发布时间】:2014-06-08 07:02:13
【问题描述】:
我使用以下代码从网络下载 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 的建议,我更改了我的代码,而post 我将我的代码更改为:
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 时它没有播放声音。
【问题讨论】:
-
不要将
AVAudioPlayer与AVPlayer混淆!后者没有delegate的setter 方法。
标签: ios objective-c avaudioplayer amr