1
我正在嘗試創建一個Soundboard應用程序,但我很難找到播放聲音的方法,並在按下其他聲音按鈕時使聲音停止。我想防止聲音相互重疊。每個聲音都會循環播放。有沒有辦法阻止同時播放多個聲音?我在任何教程中都找不到方法。我使用的音板的代碼看起來有點像這樣:Xcode 4.2音板
-(IBAction)sound1 {
CFBundleRef mainBundle = CFBundleGetMainBundle();
CFURLRef soundFileURLRef;
soundFileURLRef = CFBundleCopyResourceURL(mainBundle, (CFStringRef) @"sound1", CFSTR ("wav"), NULL);
UInt32 soundID;
AudioServicesCreateSystemSoundID(soundFileURLRef, &soundID);
AudioServicesPlaySystemSound(soundID);
}
-(IBAction)sound2 {
CFBundleRef mainBundle = CFBundleGetMainBundle();
CFURLRef soundFileURLRef;
soundFileURLRef = CFBundleCopyResourceURL(mainBundle, (CFStringRef) @"sound2", CFSTR ("wav"), NULL);
UInt32 soundID;
AudioServicesCreateSystemSoundID(soundFileURLRef, &soundID);
AudioServicesPlaySystemSound(soundID);
}
[此答案可能會對您有所幫助。](http://stackoverflow.com/a/9244552/927947) – NJones
[停止聲音在播放另一個聲音之前]可能的重複(http://stackoverflow.com/questions/9244087/stop-a-sound-before-playing-another) –