- Java 双重比较
- java - 比较器与 Apache BeanComparator
- Objective-C 完成 block 导致额外的方法调用?
- database - RESTful URI 是否应该公开数据库主键?
我可以使用自定义录像机获取输出文件 URL
,如下所示。
file:///var/mobile/Containers/Data/Application/5EB769B8-193F-4C9F-982A-48892333A8F0/Documents/2018-Oct-31%2012:16:54output.mov
我需要使用 AVPlayerViewController
播放该视频。我正在使用以下代码在我的 viewcontroller
中播放视频。但它不起作用。谁能指导我完成这项任务?
func pathVideo()
{
if let path = Bundle.main.path(forResource: "file:///var/mobile/Containers/Data/Application/5EB769B8-193F-4C9F-982A-48892333A8F0/Documents/2018-Oct-31%2012:16:54output.mov", ofType: "mov", inDirectory: "file:///var/mobile/Containers/Data/Application/5EB769B8-193F-4C9F-982A-48892333A8F0/Documents/2018-Oct-31%2012:16:54output.mov")
{
let video = AVPlayer(url: URL(fileURLWithPath: path))
let playerViewController = AVPlayerViewController()
playerViewController.player = video
present(playerViewController, animated: true, completion:
{
video.play()
})
}
}
最佳答案
您的代码有几处错误。正如您提到的,您将视频放置在您的应用程序文档目录中(通过查看您的视频文件路径),因此您无法通过调用 Bundle.main.path
方法来获取路径。它用于检索应用程序本地捆绑资源的路径(您放置在构建应用程序之前的文件)。有关 bundle 的更多信息类
所以你必须像那样访问文档目录。
let documentsPath = FileManager.default.urls(for: .cachesDirectory, in: .userDomainMask).first! //This piece of code will return path of document directory."
let videoPath = documentsPath.appendPathComponent("2018-Oct-31%2012:16:54output.mov").path //Append your video name so that complete path could be prepared and access path property.
现在您可以使用此视频路径并传递给 URL
let video = AVPlayer(url: URL(fileURLWithPath: videoPath))
我想你已经明白我的意思了,我希望它可以帮助你修复代码。
注意:我编写的代码片段与 Swift 4.0 兼容,因此您可能需要对前两行进行一些更改。
关于ios - 如何使用 fileURL 播放视频,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53078949/
我正在尝试以通常的方式在文件路径的 NSURL 中传递参数: (fileURL)?arg1=val1&arg2=val2 问题是我不断从 UIWebView 收到以下错误。 : Failed to l
我正在保存我正在使用的应用程序中录制的视频和音频文件。以下是 URL 部分的示例: @"file:///var/mobile/Containers/Data/Application/1AADB360-
我可以使用自定义录像机获取输出文件 URL,如下所示。 file:///var/mobile/Containers/Data/Application/5EB769B8-193F-4C9F-982A-4
我想创建一个像 FileURL 这样的 rails 模型,而不必命名文件 file_u_r_l.rb。如何去做这样的事情?我知道您可以显式设置表名,但是如何将默认文件名覆盖到类名映射? 谢谢 普拉提克
我想使用 [pasteboard writeObjects:pasteboardArray]; 将一些 fileURL 写入通用粘贴板,其中 pasteboard 是通用粘贴板和 pasteboard
将 pathArray 作为 fileURLWithPath 传递时出现错误。 func downloadImageForPhoto(_ photo: Photo, completionHandler
我也在 CKAsset 的客户端和 fileUrl 上缓存 CKRecord。 fileUrl 可以不时更改吗? Assets /数据本身没有变化。 最佳答案 Assets 的 fileURL 不会改
使用video react库播放本地mp4视频,我看到有人用这个功能将选定的视频文件设置为url,他们说可以。我可以选择视频文件,但它似乎不起作用,我的播放器仍然黑屏且无法播放。 输入是你选择文件的地
我不确定如何在 Xcode 6.4 中修复此错误 override init?(fileURL url: NSURL) { super.init(fileURL: url) let c
在我的 Swift 测试文件中;当我尝试通过控制台输出 fileURL 时发生崩溃。 我想在设置测试期间在控制台日志上打印出 realm 的 fileURL; 我尝试: print(Realm.Con
当我使用 CKModifyRecordsOperation 保存包含 CKAsset 的记录(只是一个 JPG 图像)时,我正在测试同步冲突,保存策略为 .IfServerRecordUnchange
在 Swift 2 中,我使用了以下代码: let path = NSBundle.mainBundle().pathForResource("Document", ofType: "pdf")! l
您好,我正在尝试找到一种使用 iOS SDK 将本地生成的图像发布/上传到 pinterest 的方法。 鉴于没有公共(public) API,我正在与 UIWebView 进行 pinterest
我最近刚刚更新到 Swift 3.0 语法和 XCode 8.0。 我在更新后恢复一切正常时遇到了一些麻烦,但我无法解决的一件事是在编写时数据(特别是图像)到数据库我收到以下错误: Terminati
我正在尝试在 Word.app 中创建一个新文档并通过 FileProvider 扩展保存到我的应用程序。我的适当方法的实现是: override func importDocument(at
我是一名优秀的程序员,十分优秀!