[英]How do I get the current time of an iTunes track via Objective-C?
我目前正在使用某些脚本界面(ScriptingBridge?)为iTunes使用一些生成的标头。 我可以得到当前正在播放的歌曲的名称
[[iTunes currentTrack] name];
但我似乎无法获取歌曲的当前播放时间。 我目前不在使用Applescript。
编辑:绝对通过ScriptingBridge生成。 我生成了标头
sdef /Applications/iTunes.app | sdp -fh --basename iTunes
找到了:[iTunes playerPosition]
这是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 --
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.