我目前正在尝试制作一个应用程序来获取 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/