applescript - Spotify 给出当前轨道的错误值 (AppleScript)

标签 applescript spotify

我目前正在尝试制作一个应用程序来获取 Spotify 中当前播放歌曲的持续时间。为此,我使用 AppleScript。

这是我的代码:

tell application "Spotify"
    return the duration of the current track
end tell

歌曲的长度是 2.52 分钟,代码告诉我 172026 秒。

通过查看返回值,看起来它返回的是毫秒而不是轨道长度的秒。我可以通过毫秒*1000 轻松解决这个问题。问题是 172026ms 不是 2.52 分钟,而是 2.8671 分钟。

我该如何获得歌曲持续时间的真实值?

这里是 Spotify AppleScript 文档:

track n : A Spotify track.
duration (integer, r/o) : The length of the track in seconds.

最佳答案

刚刚发现我需要做一点数学。

这是代码:

tell application "Spotify"
    set tM to round (((duration of current track) / 1000) / 60) rounding down
    set tS to round (((duration of current track) / 1000) mod 60) rounding down
    set myTime to ((tM as text) & "," & tS as text)
    return myTime
end tell

感谢 dronir 在 https://github.com/dronir/SpotifyControl 提供的代码

关于applescript - Spotify 给出当前轨道的错误值 (AppleScript),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38360656/

相关文章:

macos - 你如何在 mac preview 10.7 中重新加载文件?

excel - 如何使用 AppleScript 保存为 excel 文件

macos - Firefox 中的 Mac 服务已弃用?

javascript - require.js POST 请求 spotify web api 返回 "Error parsing json"

applescript - 在 Applescript 中,从 Spotify 检索播放列表信息,并启用/禁用随机播放

macos - Applescript 播放轨道 Spotify

javascript - 向 Spotify API 发送请求

bluetooth - 如何查找某个蓝牙设备是否已连接?

macos - Applescript 中的磁盘事件

html - 从 Spotify 应用程序访问播放列表文件夹结构?