当我的应用在 Apple TV 上打开时,我想播放一段小视频(20 秒)。但我找不到如何从本地文件实现 URL。
这是我到目前为止所得到的,但不幸的是它不起作用:
override func viewDidLoad() {
super.viewDidLoad()
// I know this is how to play a file from a webserver:
// player = AVPlayer(URL: NSURL(string: "http://clips.vorwaerts-gmbh.de/big_buck_bunny.mp4")!)
// But I can't find how to set the URL to a local file in the app
let path = NSBundle.mainBundle().pathForResource("bunny", ofType:"mp4")
let url = NSURL.fileURLWithPath(path!)
player = AVPlayer(URL: url)
player?.play()
}