【发布时间】:2016-03-25 16:06:54
【问题描述】:
每次尝试运行时都会出现错误提示
致命错误:在展开可选值 (lldb) 时意外发现 nil。
有人能解释一下为什么吗?这是代码
import UIKit
import AVFoundation
class ViewController: UIViewController {
var player: AVAudioPlayer = AVAudioPlayer()
override func viewDidLoad() {
super.viewDidLoad()
let audioPath = NSBundle.mainBundle().pathForResource("Belly - Might Not", ofType: "mp3")!
do {
try player = AVAudioPlayer(contentsOfURL: NSURL(fileURLWithPath: audioPath))
player.play()
} catch {
// Process error here
}
}
}
【问题讨论】:
-
您的 nil 很可能来自分配给 audioPath 时 pathForResource 的展开。您是否仔细检查了 audioPath 的路径。您的 mp3 是否包含在您的项目中?
-
是的,包括 Mp3。它只是找不到路径
标签: swift