【问题标题】:How do I get the current time of an iTunes track via Objective-C?如何通过 Objective-C 获取 iTunes 曲目的当前时间?
【发布时间】:2012-07-24 18:28:58
【问题描述】:

我目前正在使用一些脚本接口事物(ScriptingBridge?)为 iTunes 生成的标头。我可以得到当前正在播放的歌曲的名称

[[iTunes currentTrack] name];

但我似乎无法获得歌曲播放的当前时间。我目前没有使用 Applescript。

编辑:肯定是通过 ScriptingBridge 生成的。我用

生成了标题
sdef /Applications/iTunes.app | sdp -fh --basename iTunes

【问题讨论】:

  • 这个问题需要更多信息,拜托。
  • 您对更多信息的请求需要更多信息。

标签: objective-c cocoa itunes


【解决方案1】:

找到它: [iTunes播放器位置]

【讨论】:

  • 这是因为player position 是应用程序的属性,而不是轨道的属性。如果您在 AppleScript Editor 中查看 iTunes 的字典,您会看到相同的结果。
【解决方案2】:

这是 AppleScript;我知道您没有使用它,但我不知道如何使用 Scripting Bridge 来做到这一点。据我所知,该方法应该类似但更接近于objective-c语法。

tell application "iTunes"
set this_time to time of current track as string
set elapsed_seconds to player position
set this_elapsed_minutes to round elapsed_seconds / 60 rounding down
set this_elapsed_seconds to elapsed_seconds mod 60
if {1, 2, 3, 4, 5, 6, 7, 8, 9, 0} contains this_elapsed_seconds then
set this_elapsed_seconds to "0" & (this_elapsed_seconds as string)
end if
end tell    

return (this_elapsed_minutes & ":" & this_elapsed_seconds & " of " & this_time) as text --

【讨论】:

    猜你喜欢
    • 2011-05-08
    • 1970-01-01
    • 1970-01-01
    • 2016-04-22
    • 1970-01-01
    • 2011-12-30
    • 1970-01-01
    • 1970-01-01
    • 2018-07-13
    相关资源
    最近更新 更多