我希望在我的Swift应用程序中播放两个声音文件,它们分别是"C1_bip.aif"和"false.aif"。它们都在项目的同一个文件夹中。
但是当我启动应用程序时,只会播放C1_bip声音,而false声音没有播放,并且在控制台上打印了错误信息。
这两个声音文件都是相同的文件类型,并且我可以在Xcode的项目资源管理器中播放它们。
但是当我启动应用程序时,只会播放C1_bip声音,而false声音没有播放,并且在控制台上打印了错误信息。
这两个声音文件都是相同的文件类型,并且我可以在Xcode的项目资源管理器中播放它们。
if let path = NSBundle.mainBundle().pathForResource("C1_bip", ofType: "aif") {
audioPlayer = AVAudioPlayer(contentsOfURL: NSURL(fileURLWithPath: path),
fileTypeHint: "aif", error: nil)
if let sound = audioPlayer {
sound.prepareToPlay()
sound.play()
}
}
else {
println("Error")
}
if let path = NSBundle.mainBundle().pathForResource("false", ofType: "aif") {
audioPlayer = AVAudioPlayer(contentsOfURL: NSURL(fileURLWithPath: path),
fileTypeHint: "aif", error: nil)
if let sound = audioPlayer {
sound.prepareToPlay()
sound.play()
}
}
else {
println("Error")
}