swift5 - 使用 QuickTime Player 打开一个短视频
问题描述
我的本地机器上有一个简短的视频。我正在尝试NSWorkspace
在 QuickTime Player 上打开它。
let stringUrl = "~/Desktop/myrec.mov"
let url = URL(string: stringUrl)!
let config = NSWorkspace.OpenConfiguration()
config.activates = true
NSWorkspace.shared.open(
[url],
withApplicationAt: URL(string: "~/Applications/QuickTime Player")!,
configuration: config
)
我得到的错误是:
Fatal error: Unexpectedly found nil while unwrapping an Optional value: file cap/cap.swift
这与withApplicationAt
错误的 URL 和返回有关nil
。
我确定withApplicationAtURL
是错的,但我不知道如何找到快速播放器应用程序的网址。
我对 Swift 很陌生,并且在阅读文档时遇到了麻烦,尤其是因为它们似乎不是最新的(例如,我的编译器说openFile
已弃用并导致我使用open
)。
我也不确定这是否是完成我想做的事情的正确/最佳方式(在 quicktime 播放器上打开一个小型本地视频)。
任何建议、提示、建议或答案将不胜感激!
解决方案
尝试这个。在我的 Mac 上工作:
let stringUrl = "/Users/whoever/Desktop/myrec.mov"
let url = URL(fileURLWithPath: stringUrl)
let config = NSWorkspace.OpenConfiguration()
config.activates = true
NSWorkspace.shared.open(
[url],
withApplicationAt: URL(fileURLWithPath: "/System/Applications/QuickTime Player.app"),
configuration: config
)
请注意,我将 URL 的初始化程序替换为正确的初始化程序。另请注意,我已将 QuickTime Player 路径与 Finder 提供的路径进行了交换(按住选项键时单击鼠标右键)。
推荐阅读
- python - 不断获得 Class 方法的“None”值,我不明白为什么?
- python-3.x - ElasticSearch中的地理距离排序?
- python - 如何将集合附加到数据库?
- haskell - Haskell中异构列表的序列
- python - 离散轴圆图的软件推荐
- python - Pandas:排序是否保证函数在列表中执行的顺序?
- angular - 如何在 ngFor 中以角度应用条件?
- java - 是否可以通过 DB 或 Rest 通过 Tasklist 使 Camunda Webapps(独立 Spring-boot)更新 .bpmn
- codeigniter - 如何向我的 EMAIL CLASS 添加进度条
- docker - 条件volumes_from路径