2012-01-25 32 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

我很抱歉,我对此非常感兴趣。我不明白我如何将代码与我的代码示例相关联。 你能举个例子来说明我的例子吗? 非常感谢 –

相关问题