【发布时间】:2017-08-17 21:30:41
【问题描述】:
当我尝试添加音频文件时,我正在快速编写计算器应用程序,我将其放在 calc 编程之上:
var player:AVAudioPlayer = AVAudioPlayer()
@IBAction func play(_ sender: UIButton)
{
player.play()
}
在视图下方确实加载了我把这个。拜托,任何帮助都会很棒!
override func viewDidLoad() {
super.viewDidLoad()
//Do any additional setup after loading the view, typically from a nib.
do
{
let audioPath = Bundle.main.path(forResource: "song", ofType: "mp4")
try player = AVAudioPlayer(contentsOf: NSURL(fileURLWithPath: audioPath!) as URL)
}
catch
{
// error
abort()
}
}
【问题讨论】:
-
auudioPath 为零吗?如果是这样,则 mp4 文件实际上不在您的应用程序包中。
-
try player =是否编译?顺便说一句,为什么不Bundle.main.url(forResource: "song", withExtension: "mp4")? -
audiopath 等于 nil,但 mp4 是我的文件类型
标签: swift error-handling