2014-06-08 5 views
1

아래 코드를 사용하여 웹에서 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]; 

이제는 사운드를 재생했지만 을 사용하면 사운드가 재생되지 않습니다.

+1

는 AVPlayer''와'AVAudioPlayer'을 혼동하지 마십시오! 후자는'delegate'에 대한 setter 메소드가 없습니다. –

답변

0

확인 다음 사항 :

  • AMR은 더 이상 (≥ 아이폰 OS 4.3, supported audio formats in the Apple iOS SDK Documentation 참조) 지원됩니다.
  • AVPlayer (오디오 및 비디오)을 사용하겠습니까, 아니면 오디오 만 사용 하시겠습니까? 오디오 용으로는 AVAudioPlayer 만 사용하십시오. 다음 코드 스니 j은이를 처리하는 f}을 보여줍니다.
  • AVAudioPlayer을 사용하려면 자체 인스턴스가 AVAudioPlayerDelegate Protocol을 구현합니까?
  • 귀하의 자체 인스턴스가 AVAudioPlayerDelegate Protocol을 구현합니까?
  • AVAudioFoundation 프레임 워크 (#import <AVFoundation/AVFoundation.h>)를 올바르게 추가하고 연결 했습니까?

    - (void)viewDidLoad 
    { 
        [super viewDidLoad]; 
        NSURL *url = [NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"audio" ofType:@"m4a"]]; 
    
        NSError *error = noErr; 
        self.audioPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:url error:&error]; 
        if (error) 
        { 
         NSLog(@"Error in audioPlayer: %@", [error localizedDescription]); 
        } 
        else 
        { 
         self.audioPlayer.delegate = self; 
         [self.audioPlayer prepareToPlay]; 
        } 
    } 
    
    - (void)playAudio 
    { 
        [self.audioPlayer play]; 
    } 
    
+0

그들을 추가했지만 여전히 동일한 오류가 표시됩니다. –

+0

내 편집을 참조하십시오 –

+2

AMR은 더 이상 (≥iOS 4.3)을 지원하지 않습니다. –