2013-08-07 2 views
2

.caf 오디오 파일을 재생하는 코드를 사용합니다. 동일한 코드가 iPhone 4s 및 iPad 2에서는 잘 작동하지만 iPhone 5에서는 전혀 재생되지 않습니다. . 오디오 파일이 iPhone 5에서 재생되지 않습니다.

코드입니다 :

-(IBAction)checkSound:(id)sender 
{ 
    NSURL *url = [NSURL fileURLWithPath:[NSString stringWithFormat:@"%@/Lunatic.caf", [[NSBundle mainBundle] resourcePath]]]; 

NSLog(@"%@",url); 

NSError *error; 

self.audioPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:url error:&error]; 

self.audioPlayer.numberOfLoops = 0; 

self.audioPlayer.volume = 1; 


NSLog(@"log audioplayer: %@",audioPlayer); 

if (audioPlayer != nil) 
{ 
    [self.audioPlayer prepareToPlay]; 
    [self.audioPlayer play]; 
} 


if (audioPlayer.playing == NO) 
{ 
    NSLog(@"not playing, error: %@",error); 
} 


if([[NSFileManager defaultManager] fileExistsAtPath:@"file://localhost/var/mobile/Applications/0D3F5169-8DB1-4398-A09A-DB2FBADF57EF/myApp.app/Lunatic.caf"]) 
{ 
    NSLog(@"file exist"); 
} 
else 
{ 
    NSLog(@"file doesn't exist"); 
} 


} 

이 로그 출력 :

2013-08-07 20:05:52.694 myApp[7006:907] file://localhost/var/mobile/Applications/0D3F5169-8DB1-4398-A09A-DB2FBADF57EF/myApp.app/Lunatic.caf 2013-08-07 20:05:52.697 myApp[7006:907] log audioplayer: (null) 2013-08-07 20:05:52.701 myApp[7006:907] not playing, error: Error Domain=NSOSStatusErrorDomain Code=-43 "The operation couldn’t be completed. (OSStatus error -43.)" 2013-08-07 20:05:52.703 myApp[7006:907] file doesn't exist

당신이 audioplayer 로그가 "널 (null)"제공 및 오류 로그에 오류가 -43라고 볼 수 있듯이 .... 하지만 반복 ... 아이폰과 함께 4s 다 잘 작동합니다 ....

실마리가 왜 이런 일이 발생합니까? iPhone 5에서 오디오로 무언가를 바꿨습니까? 내 iPhone 5의 사운드가 재생되는 것을 방해하는 설정 일 수 있습니까? 도움을 주시면 감사하겠습니다.

답변

1

재생을 시작하기 전에 [audioPlayer prepareToPlay]에 전화를 했습니까? 또한 적절한 채널에서 재생되는지 확인하기 위해 audioRoutes를 두 번 확인 했습니까?

1) [audioPlayer isPlaying]를 호출하고 예 반환하는 경우 또는 전혀 당신이 플레이 호출 한 후 참조 :에

두 좋은 정신 검사입니다.

2.) AVAudioPlayerDelegate을 설정하고 audioPlayerDidFinishPlaying:에 콜백을 기다리고 오디오 길이 이후에 호출되는지 확인합니다.

http://developer.apple.com/library/ios/#documentation/AVFoundation/Reference/AVAudioPlayerClassReference/Reference/Reference.html

편집 : 당신이 실제로 가장 가능성이 당신이 전화하는거야 경로에 문제가 의미, 재생되지 않는 파일을 것입니다. 또한 NSLog과와 경로 밖으로

인쇄 파일이 실제로 사용하여 존재하는지 확인합니다

if([[NSFileManager defaultManager] fileExistsAtPath:yourPath]) 
{ 

} 
+0

I 추가 tryed [audioPlayer prepareToPlay] audioplayer를 호출하기 전에 ...하지만 아무 일도 일어나지 않습니다 ... 또한 오디오 플레이어가 재생되는지 확인하기위한 체크를 추가하고 그것이 아니라고 말합니다 ... 새 코드를 보여주기 위해 질문을 업데이트했습니다 ... – Blue

+0

Okay check 내 새 편집. 당신의 경로가 엉망이 된 것처럼 들립니다 ... –

+0

코드를 업데이트했습니다 ... 여전히 작동하지 않지만 많은 오류가 있습니다 ... 질문의 코드를 확인하십시오 ... – Blue

관련 문제