2012-01-25 2 views
1

오디오 파일을 재생하고 싶지만 하나씩 재생하고 싶습니다. 나는 어떤 것을 보았지만 실제로는 효과가 없습니다. 예를 들어 소리가 계속 울리면 "켄"이 "lo"다음에 재생되기를 원합니다.오디오 파일을 차례로 재생 하시겠습니까?

-(IBAction)LO:(id)sender{ 


    CFBundleRef mainBundle = CFBundleGetMainBundle(); 
    CFURLRef soundFileURLRef; 

    soundFileURLRef = CFBundleCopyResourceURL(mainBundle, (CFStringRef) @"LO", CFSTR ("wav"), NULL); 

    UInt32 soundID; 
    AudioServicesCreateSystemSoundID(soundFileURLRef, &soundID); 
    AudioServicesPlaySystemSound(soundID); 

    } 

-(IBAction)KEN:(id)sender { 
    CFBundleRef mainBundle = CFBundleGetMainBundle(); 
    CFURLRef soundFileURLRef; 
    soundFileURLRef = CFBundleCopyResourceURL(mainBundle, (CFStringRef) @"KEN", CFSTR ("wav"), NULL); 

    UInt32 soundID; 
    AudioServicesCreateSystemSoundID(soundFileURLRef, &soundID); 
    AudioServicesPlaySystemSound(soundID); 
} 

답변

2

시스템 사운드보다 낮은 레벨로 이동해야합니다. 간단하면 AVAudioPlayer을 사용하고 사운드가 끝난 대리자 콜백을받을 때마다 다음 소리를 끕니다. 예를 들어

#pragma mark - AVAudioPlayerDelegate 

– (void)audioPlayerDidFinishPlaying:(AVAudioPlayer *)player successfully:(BOOL)success { 
    if (success) { 
     // last sound finished successfully, play the next sound 
     [self playNextSound]; 
    } else { 
     // something went wrong, show an error? 
    } 
} 

/* 
* Play the next sound 
*/ 
- (void)playNextSound { 
    // get the file location of the next sound using whatever logic 
    // is appropriate 
    NSURL *soundURL = getNextSoundURL(); 
    NSError *error = nil; 
    // declare an AVAudioPlayer property on your class 
    self.audioPlayer = [[AVAudioPlayer alloc] initWithURL:soundURL error:&error]; 
    if (nil != error) { 
     // something went wrong... handle the error 
     return; 
    } 
    self.audioPlayer.delegate = self; 
    // start the audio playing back 
    if(![self.audioPlayer play]) { 
     // something went wrong... handle the error 
    } 
} 
+0

매우 유감 스럽습니다. 코드 예제와 관련하여 코드를 배치하는 방법을 이해하지 못했습니다. 예제에 대한 예를 들어 주시겠습니까? 감사합니다. –

관련 문제