作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试创建一个 Soundboard 应用程序,但我很难找到一种方法来播放声音并在按下另一个声音按钮时让声音停止。我想防止声音相互重叠。每个声音都会循环。有没有办法防止同时播放多个声音?我没有在任何教程中找到方法。我用于音板的代码看起来有点像这样:
-(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);
}
最佳答案
你应该使用 AVAudioPlayer所以你可以随时播放或停止声音,并使用委托(delegate)方法来确定声音是被中断还是已经结束。
关于objective-c - Xcode 4.2 音板,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8246635/
我正在尝试用 swift 制作一个音板应用程序,四个按钮中的 3 个按钮使应用程序崩溃,另一个按钮不执行任何操作。我究竟做错了什么?我是编程新手,我试图按照教程进行操作,但它不起作用。 import
我正在创建一个音板应用程序,我想添加一个按钮,当触摸它时将停止播放声音,到操作栏。我搜索了解决方案,但找到了使用 soundpool 的示例,并且我使用 MediaPlayer 创建了所有声音。请帮帮
我正在尝试创建一个 Soundboard 应用程序,但我很难找到一种方法来播放声音并在按下另一个声音按钮时让声音停止。我想防止声音相互重叠。每个声音都会循环。有没有办法防止同时播放多个声音?我没有在任
我是一名优秀的程序员,十分优秀!