将 HEX iTunes 持久 ID 转换为高位和低位 32 位形式
在 Mac 上,我可以从“iTunes Music Library.xml”文件中提取特定歌曲的“持久 ID”,然后使用 Applescript 播放该歌曲,如下所示:
tell application "iTunes"
set thePersistentId to "F040658A7687B12D"
set theSong to (some track of playlist "Music" whose persistent ID is thePersistentId)
play theSong with once
end tell
在 PC 上,我可以从以下位置提取“持久 ID” : XML 文件以同样的方式。 iTunes COM 接口的文档称函数“ItemByPercientId”有两个参数:“highID”(64 位持久 ID 的高 32 位)和“lowID”(64 位持久 ID 的低 32 位) 。但我不知道如何将基于十六进制的值转换为 ItemByPersistentId 函数所需的高位和低位 32 位值。
var thePersistentId = "F040658A7687B12D";
var iTunes = WScript.CreateObject("iTunes.Application");
var n = parseInt(thePersistentId);
var high = (do something with n?);
var low = (do something else with n?);
iTunes.LibraryPlaylist.tracks.ItemByPersistentId(high,low).play();
On a Mac, I can extract the "Persistent ID" for a particular song from the "iTunes Music Library.xml" file and then use Applescript to play that song like so:
tell application "iTunes"
set thePersistentId to "F040658A7687B12D"
set theSong to (some track of playlist "Music" whose persistent ID is thePersistentId)
play theSong with once
end tell
On a PC, I can extract the "Persistent ID" from the XML file in the same way. The documentation for the iTunes COM interface says the function "ItemByPersistentId" has two parameters: "highID" (The high 32 bits of the 64-bit persistent ID) and "lowID" (The low 32 bits of the 64-bit persistent ID). but I can't figure out how to convert the hex-based value to the high and low 32-bit values the ItemByPersistentId function wants.
var thePersistentId = "F040658A7687B12D";
var iTunes = WScript.CreateObject("iTunes.Application");
var n = parseInt(thePersistentId);
var high = (do something with n?);
var low = (do something else with n?);
iTunes.LibraryPlaylist.tracks.ItemByPersistentId(high,low).play();
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我不知道windows脚本主机上的情况是什么,但是有些JS客户端有32位int,所以你的
var n = parseInt(thePercientId);
就加倍麻烦了。使用 parseInt 时应始终包含基数(例如parseInt(hexValue, 16)
、parseInt(octValue, 8)
)。为了避免 32 位脚本解释器的限制,您可以分别提取低 32 位和高 32 位。每个十六进制数字都是 4 位,因此低 32 位是持久 ID 的最后 8 个字符,高 32 位是剩余的 8 个字符(除非它具有
0x
前缀,那么它是下一个最右边的 8 个字符块)。编辑:从我在 iTuner源代码,看起来
highID
实际上是高4个字节,而lowID
是低4个字节,而不是8个字节(因此丢弃了中间的8个字节)persistentID
的字节...)。这是一个修改后的尝试:I don't know what the situation is on the windows script host, but some JS clients have a 32 bit int, so your
var n = parseInt(thePersistentId);
is doubly troublesome. You should always include the base when using parseInt (e.g.parseInt(hexValue, 16)
,parseInt(octValue, 8)
).To avoid 32 bit script interpreter limitations, you can extract the lower 32 bits and upper 32 bits seperately. Each hex digit is 4 bits, so the lower 32 bits are the last 8 characters of your persistent ID, and the upper 32 bits are the remaining 8 (unless it has the
0x
prefix, then it's the next rightmost chunk of 8 characters).Edit: From what I've read in the iTuner source code, it looks like
highID
is actually the upper 4 bytes, andlowID
the lower 4 bytes, not 8 bytes (thus discarding the middle 8 bytes of thepersistentID
...). Here's a modified attempt: