2011-12-10 17 views
2

AudioServicesPlaySystemSoundを使用して一度に1つのサウンドを再生する方法については、この記事をスタックオーバーフローで読んでいました。AudioServicesPlaySystemSoundで一度に1つのサウンドを再生する

stop sound in iPhone

私は次のコードを、あなたは他の停止を再生する前に、一つのボタンを押すと、2つの音が重なるように、第二の音は最初のものの上に再生されて、説明したのと同じ問題を抱えていました。 Appleの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機能を使うに加えて

    • 同時再生は利用できません。一度に再生できるサウンドは1つだけです

    なぜ、複数のサウンドが同時に再生できるのか理解できません。

    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とお試しください。

    これは、問題を解決するための単なる解決策です。 もう一度再生する必要がある場合は、サウンドを再度作成する必要があります。

    関連する問題