AudioServicesPlaySystemSoundを使用して一度に1つのサウンドを再生する方法については、この記事をスタックオーバーフローで読んでいました。AudioServicesPlaySystemSoundで一度に1つのサウンドを再生する
私は次のコードを、あなたは他の停止を再生する前に、一つのボタンを押すと、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
を使用したいと思います。
他に誰も同じ問題があったのですか?
ありがとうございます。