【问题标题】:Pause current playing music in Swift on Mac在 Mac 上的 Swift 中暂停当前正在播放的音乐
【发布时间】:2016-04-14 17:55:16
【问题描述】:

有没有办法能够访问 Apple 键盘上的 F7、F8 和 F9 键在 Mac OS X 的 Swift 中具有的相同功能,因为我希望能够创建一个按钮来暂停当前在 Spotify 或 iTunes 中播放曲目,然后再次播放。

【问题讨论】:

标签: swift macos audio itunes pause


【解决方案1】:

您可以使用 Applescript 来执行此操作,使用 NSAppleScript 从 swift 运行 applescript。这是一个快速而肮脏的示例,用于在 spotify 中切换当前曲目的播放/暂停状态:

let command = "if application \"Spotify\" is running then tell application \"Spotify\" to playpause"
let commandObject = NSAppleScript(source: command)
var error: NSDictionary?
commandObject!.executeAndReturnError(&error)

您可以在https://developer.spotify.com/applescript-api/阅读有关 Spotify 的 applescript API 的更多信息

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多