gpt4 book ai didi

swift - 使用 tvOS 从本地文件播放视频

转载 作者:可可西里 更新时间:2023-11-01 02:18:59 29 4
gpt4 key购买 nike

当我的应用程序在 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()

}

最佳答案

您的代码看起来不错。也许,你应该试试这个:

In the Project Navigator select your Project Root > Your Target > Build Phases > Copy Bundle Resources. Check to see that your video is there, if not click the plus sign to add it.

来源:http://www.brianjcoleman.com/tutorial-play-video-swift/

关于swift - 使用 tvOS 从本地文件播放视频,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32788910/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com