如何通过Objective-C获取iTunes曲目的当前时间?
问题描述:
我目前使用一些生成的标题为iTunes从一些脚本界面的东西(ScriptingBridge?)。我可以得到当前正在播放的歌曲的名字与如何通过Objective-C获取iTunes曲目的当前时间?
[[iTunes currentTrack] name];
,但我似乎无法能够得到乐曲播放的当前时间。目前我没有使用Applescript。
编辑:绝对通过ScriptingBridge生成。我生成了标头
sdef /Applications/iTunes.app | sdp -fh --basename iTunes
答
发现: [iTunes的playerPosition]
+0
这是因为'玩家位置'是应用程序的属性,而不是轨道。如果您在AppleScript Editor中查看iTunes的词典,您会看到相同的结果。 – 2012-07-24 22:49:36
答
这是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 --
这个问题需要一些更多的信息,请。 – 2012-07-24 18:46:17
您的要求提供更多信息需要更多信息。 – Greg 2012-07-24 19:33:53