아래 코드를 사용하여 웹에서 AMR 파일을 다운로드하고 재생하는 경우 AVAudioPlayer
번이지만 unrecongnize selector sent to instance
오류가 발생합니다. 내가 코드를 변경 @Michael의 조언을 바탕으로AVAudioPlayer가 AMR 파일을 재생하지 않습니다.
- (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]
}
편집
이에 내 코드를 변경이 post :
이
다운로드와 재생을 시작하는 방법입니다NSURL *fileURL = [[NSURL alloc] initWithString: @"http://www.domain1.com/mysound.mp3"];
//Initialize the AVAudioPlayer.
audioPlayer= [AVPlayer playerWithURL:fileURL];
[audioPlayer play];
이제는 사운드를 재생했지만 을 사용하면 사운드가 재생되지 않습니다.
는 AVPlayer''와'AVAudioPlayer'을 혼동하지 마십시오! 후자는'delegate'에 대한 setter 메소드가 없습니다. –