2011-12-10 4 views
2

한 번에 하나의 사운드를 재생하기 위해 AudioServicesPlaySystemSound를 사용하는 것에 대한 스택 오버플로에 대해이 게시물을 읽었습니다. AudioServicesPlaySystemSound를 사용하여 한 번에 한 사운드 재생

stop sound in iPhone

난 당신이 다른 정지가 재생하기 전에 하나 개의 버튼을 누르면, 2 소리가이 소리가 겹치도록 첫 번째의 상단에 재생, 다음 코드로 설명 같은 문제가 있었다. 사과의 documentation에 따르면

-(IBAction)button1:(id)sender{ 
SystemSoundID soundID; 
NSString *soundFile = [[NSBundle mainBundle]  
         pathForResource:@"sound1" 
         ofType:@"wav"]; 
AudioServicesCreateSystemSoundID((CFURLRef)[NSURL fileURLWithPath:soundFile], &soundID); 
AudioServicesPlaySystemSound(soundID); 
[soundFile release]; 
} 

-(IBAction)button2:(id)sender{ 
SystemSoundID soundID; 
NSString *soundFile = [[NSBundle mainBundle]  
         pathForResource:@"sound2" 
         ofType:@"wav"]; 
AudioServicesCreateSystemSoundID((CFURLRef)[NSURL fileURLWithPath:soundFile], &soundID); 
AudioServicesPlaySystemSound(soundID); 
[soundFile release]; 
} 

:

AudioServicesPlaySystemSound은 한 번에 하나의 사운드를 재생하기로되어있다.

  • 사운드가 즉시
  • 루핑 및 스테레오 위치를 사용할 수없는 플레이

    • 사운드를 사용할 수없는 프로그램 볼륨 컨트롤과 함께, 현재의 시스템 오디오 음량으로 재생 : 당신이 AudioServicesPlaySystemSound 기능을 사용 또한

      ,

    • 동시 재생을 사용할 수 없음 : 한 번에 하나의 사운드 만 재생할 수 있습니다.

    그래서 두 개 이상의 사운드가 동시에 재생 될 수 있는지 이해할 수 없습니다.

    AudioServicesDisposeSystemSoundID을 사용해 보았지만 소리가 여전히 겹칩니다. 잘못 했나요?

    -(IBAction)sound2:(id)sender{ 
    AudioServicesDisposeSystemSoundID 
    SystemSoundID soundID; 
    NSString *soundFile = [[NSBundle mainBundle]  
             pathForResource:@"sound2" 
             ofType:@"wav"]; 
    AudioServicesCreateSystemSoundID((CFURLRef)[NSURL fileURLWithPath:soundFile], &soundID); 
    AudioServicesPlaySystemSound(soundID); 
    [soundFile release]; 
    } 
    

    현재, 내가 대신 AVAudioPlayer를 사용하고 있지만, 사운드 시작 지연이 발생하고, 즉시 소리가 재생 될 때 나는 가능하면 AudioServicesPlaySystemSound를 사용하고 싶습니다.

    다른 사람에게도 동일한 문제가 있습니까?

    감사합니다.

  • 답변

    4

    AudioServicesDisposeSystemSoundID으로 시도해보십시오.

    문제 해결에 도움이되는 해결책 일뿐입니다. 다시 재생해야하는 경우 사운드를 다시 만들어야합니다.

    관련 문제