안녕하세요 저는 UINavigationController를 사용하는 HomeViewController라는 UIView가 있습니다. 사운드 물건을 처리 할 //보기가 표시되기 전에 AVAudioPlayer가 재생되지 않도록하는 방법
: GameViewController의의 viewDidLoad에서
gameView = [[GameViewControler alloc] init];
[[self navigationController] pushViewController:gameView animated:YES];
[gameView release];
, 나는 또 다른 후 2 개 오디오 파일을 재생하려면 다음 코드를 사용 버튼 클릭에, 나는 다음과 같은 코드를 사용하여 다른보기를 밀어 첫 번째 오디오 파일이 화면이 GameViewController의 viewDidLoad에에서 호출되는 경우에도 HomeViewController에있는 동안 연주하기 시작하는 이유
if([[GameStore defaultStore] currentIndex] == 0)
{
if(![audioPlayer isPlaying])
{
NSString *findPath = [[NSBundle mainBundle] pathForResource:@"findtheword" ofType:@"aiff"];
if(findPath)
{
NSURL *findURL = [NSURL fileURLWithPath:findPath];
NSError *findError;
audioPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:findURL error:&findError];
if(audioPlayer == nil)
{
NSLog([findError description]);
}
else{
[audioPlayer play];
}
}
}
}
while ([audioPlayer isPlaying]) {
//do nothing and wait so the sound is not overlap
}
if(![audioPlayer isPlaying] || ([audioPlayer isPlaying] && override)){
Word *currentWord = [[GameStore defaultStore] currentWord];
NSString *soundPath = [[NSBundle mainBundle] pathForResource:[currentWord fileName]
ofType:[currentWord fileType]];
// If this file is actually in the bundle...
if (soundPath) {
// Create a file URL with this path
NSURL *soundURL = [NSURL fileURLWithPath:soundPath];
NSError *error;
audioPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:soundURL error:&error];
if (audioPlayer == nil)
NSLog([error description]);
else
[audioPlayer play];
}
[FlurryAnalytics logEvent:@"GameViewController - playSound"];
}
else{
[FlurryAnalytics logEvent:@"GameViewController - playSound is still playing"];
}
나는 알아낼 수 없습니다.
나는 다음과 같은 코드를 제거 할 경우 : 첫 번째 오디오 파일이 GameViewController로드하지만 2 오디오 파일 중복 될 때 재생하기 시작
while ([audioPlayer isPlaying]) {
//do nothing and wait so the sound is not overlap
}
합니다.
대단히 감사합니다.
정확히 무엇이 일어 났는지 설명했습니다. 코드를 -viewDidAppear로 옮겼습니다. 문제가 해결 된 것 같습니다. – atbebtg