2012-05-16 4 views
0

AVQueuePlayer을 사용하여 사운드를 재생할 수없는 것 같습니다. 응용 프로그램을 컴파일하고 잘 실행되지만`imageTouched '메서드가 호출 될 때 오디오가 표시되지 않습니다. 누구든지 도와 줄 수 있습니까?AVQueuePlayer가 사운드를 재생하지 않습니다.

-(void) imageTouched 
{ 
    NSString * path1 = [[NSBundle mainBundle] pathForResource:@"sound1" ofType:@"wav"]; 
    NSString * path2 = [[NSBundle mainBundle] pathForResource:@"sound2" ofType:@"wav"]; 
    NSURL *url1 = [NSURL fileURLWithPath:path1]; 
    NSURL *url2 = [NSURL fileURLWithPath:path2]; 

    AVPlayerItem *firstSound = [AVPlayerItem playerItemWithURL:url1]; 
    AVPlayerItem *secondSound = [AVPlayerItem playerItemWithURL:url2]; 

    NSArray *sounds = [NSArray arrayWithObjects:firstSound, secondSound, nil]; 
    AVQueuePlayer *player = [AVQueuePlayer queuePlayerWithItems:sounds]; 

    [player play]; 
    NSLog(@"%d",player.status); 

} 

편집 1 : 나는 파일 이름 (대소 문자, 철자, 등)에 문제가 있었고이있을 것 같지 않습니다 있는지 확인했습니다. 다음 코드를 사용하여 사운드를 재생할 수 있었지만 실제로는 AVQueuePlayer이 필요합니다. 도와주세요!

NSString *path; 
SystemSoundID soundId; 
path = [[NSBundle mainBundle] pathForResource:@"sound1" ofType:@"wav"]; 
NSURL *url = [NSURL fileURLWithPath:path]; 
AudioServicesCreateSystemSoundID((CFURLRef)objc_unretainedPointer(url), &soundId); 
AudioServicesPlaySystemSound(soundId); 
+0

사운드 파일이 실제로 앱 번들에 포함되어 있고 파일 이름의 철자가 올바른지 (대소 문자 포함) 확인하십시오. – hotpaw2

+0

소리가 내 리소스 폴더에 복사되고 맞춤법이 정확합니다. 불행히도 그것은 문제가 아닙니다. 내 nslog는 어떤 도움이 있다면 0을 출력하고 있습니다. – garethdn

+0

'AudioServicesPlaySystemSound (soundId);를 사용하여 사운드를 잘 재생할 수 있다고 언급해야하지만'AVQueuePlayer'를 사용하고 싶습니다. 아마 내가 .h 파일에서 누락 된 것이 있습니까? – garethdn

답변

0

는 내가 지금까지 너무 늦게 당신을 위해있을 수 있습니다 실현,하지만 난 그 이유는 AVQueuePlayer 그래서 사운드가 재생되지 않는, 바로 오토 릴리즈되고 있음을 의심. 대신 [[AVQueuePlayer alloc] initWithItems:sounds]을 시도하십시오.

0

거의 비슷하게 생각했지만 기능에서는 AVQueuePlayer *player을 선언하는 대신 interface으로 선언했습니다.

관련 문제