2012-01-25 9 views
1

私はオーディオファイルを再生したいが、それらを次々に再生したい。私はいくつかのものを見ましたが、実際には機能しません。たとえば、音が継続するようにするには、 "lo"の後に "ken"が表示されます。オーディオファイルを1つずつ再生しますか?

-(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

私は非常にこれで非常に新しいです。私は自分のコードの例に関連してコードを配置する方法を理解していませんでした。 私の例についての例を教えてもらえますか? ありがとう –

関連する問題