我正在尝试在AVAudioPlayer实例上播放多个声音文件,但是当播放一个声音时,另一个声音停止播放.我不能一次播放多个声音.这是我的代码:
import AVFoundation
class GSAudio{
static var instance: GSAudio!
var soundFileNameURL: NSURL = NSURL()
var soundFileName = ""
var soundPlay = AVAudioPlayer()
func playSound (soundFile: String){
GSAudio.instance = self
soundFileName = soundFile
soundFileNameURL = NSURL(fileURLWithPath: NSBundle.mainBundle().pathForResource(soundFileName, ofType: "aif", inDirectory:"Sounds")!)
do{
try soundPlay = AVAudioPlayer(contentsOfURL: soundFileNameURL)
} catch {
print("Could not play sound file!")
}
soundPlay.prepareToPlay()
soundPlay.play ()
}
}
Run Code Online (Sandbox Code Playgroud)
任何人都可以通过告诉我如何一次播放多个声音文件来帮助我吗?任何帮助深表感谢.
非常感谢,凯
我正在开展一个项目,允许孩子们向圣诞老人发送信息.不幸的是,如果他们在AGE字段中输入字符串而不是整数,程序崩溃并返回从字符串"[exampleString]"到"Double"类型的转换无效.有没有办法检查他们是否输入了整数?这是代码.
If childAge > 0 And childAge < 150 Then
fmSecA2 = "Wow! You are already " & childAge & " years old? You're growing to be a big " & childGender & " now! "
Else
fmSecA2 = "Erm, I couldn't really understand your age. Are you making this up? Ho ho ho!"
End If
Run Code Online (Sandbox Code Playgroud)
谢谢,凯:)