2010-06-25 5 views
0

AVAudioPlayer 클래스에 이상한 문제가 있습니다. 속성 중 하나에 액세스하려고 할 때마다 null입니다.AVAudioPlayer isPlaying은 항상 null을 반환합니다.

// Get the file path to the song to play. 
NSString *filePath = [[[NSBundle mainBundle] pathForResource:pSound.fileName 
       ofType:pSound.fileType] retain]; 

// Convert the file path to a URL. 
NSURL *fileURL = [[NSURL alloc] initFileURLWithPath:filePath]; 

NSError* err; 
//Initialize the AVAudioPlayer 
self.audioPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:fileURL error:&err]; 

    if(err){ 
    NSLog(@"Initializing failed with reason: %@", [err localizedDescription]); 
} 
else{ 
    [self.audioPlayer setDelegate:self]; 
    [self.audioPlayer prepareToPlay]; 
    self.playCount = self.playCount + 1; 
     NSLog(@"%@", [self.audioPlayer isPlaying]); //this displays null; also if I call it at a later time 
}; 

[filePath release]; 
[fileURL release]; 

어떤 아이디어?

편집 :

+0

혹시이 문제를 해결하기 위해 관리나요 대신 [audioPlayer isPlaying]의)을 (audioPlay.playing를 사용할 수 있습니까? 나는 똑같은 문제를 안고있다. – Neeku

답변

2
NSLog(@"%@", [self.audioPlayer isPlaying]); 

%의 @ ... 내가 부울에 isPlaying 내가 값을 얻을 부울을 인쇄, 저장 할 때 이상하게도 - 당신이 그렇게 [yourObject의 toString] 의 결과를 인쇄 할 것을 의미 [self.audioPlayer isPlaying]에서 반환 된 bool 값을 확인하려면 % d를 사용해야합니다.

p.s. 전화를 겁내지 말라 [audioPlayer play]; )

+0

오, 감사합니다. 하지만 어쨌든 나는 항상 null도 반환하는 경우에 값을 액세스합니다. 나는 그것을 확인하는 playOrPause 메소드를 가지고있다. 변수에 값을 처음 할당 한 다음 변수를 쿼리하면 문제가되지 않으므로 작동합니다. – Daniel

0

당신은

if (audioPlayer.playing) { 
     [audioPlayer stop]; 
} else { 
     [audioPlayer play]; 
} 
관련 문제