使用 QuickTime Player 打开短视频 [英] Open a short video using QuickTime Player

查看:49
本文介绍了使用 QuickTime Player 打开短视频的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的本​​地机器上有一个短视频.我正在尝试使用 QuickTime Player 上的 NSWorkspace 打开它.

I have a short video on my local machine. I am trying to open it using NSWorkspace on 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 相关.

Which has to do with withApplicationAt being the incorrect URL and returning nil.

我确定 withApplicationAtURL 是错误的,但我不知道如何找到 quicktime 播放器应用的网址.

I'm sure withApplicationAtURL is wrong, but I have no idea how to find the url for the quicktime player app.

我对 Swift 很陌生,在阅读文档时遇到了麻烦,尤其是因为它们似乎不是最新的(例如,我的编译器说 openFile 已被弃用并导致我 open).

I am very new to Swift and am having trouble reading the docs, especially since they don't seem up to date (e.g. my compiler says openFile is deprecated and led me to open).

我也不确定这是否是完成我想要做的事情的正确/最佳方式(在 quicktime 播放器上打开一个小的本地视频).

I'm also not sure if this is the correct/best way to go about accomplishing what I am trying to do (open a small local video on quicktime player).

任何建议、技巧、建议或答案将不胜感激!

Any recommendations, tips, advice, or answers would be greatly appreciated!

推荐答案

试试这个.适用于我的 Mac:

Try this. Works on my 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 提供的路径交换(按住选项键的同时右键单击).

Please note that that I replaced the initializer of URL with the correct one. Also note, that I've swapped the QuickTime Player path with the one that Finder gives me (right-click while holding option key).

这篇关于使用 QuickTime Player 打开短视频的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆