1

我正在通过 AppleScript 控制 iTunes,并且正在播放来自 HTTP 服务器的流。我正在使用的代码如下所示:

tell application "iTunes"
  open location "your_url_here"
  play
end tell

它工作正常,但我想避免这些 URL 出现在 iTunes 库或之后的任何播放列表中。有什么诀窍可以实现吗?

4

1 回答 1

1

您是否考虑过使用 QuickTimePlayer 来播放流?

tell application "QuickTime Player"
    open URL "http://www.a-1radio.com/listen.pls"
end tell

它应该打开所有的 iTunes 格式,它是 OsX 的默认设置,它更“最小”,不会保存曲目。

(我知道您指定要使用 iTunes,因此这可能不是解决方案,但作为预装软件值得一试)

编辑要隐藏它,这似乎有效:

tell application "QuickTime Player"
    -- don't use launch or activate
    -- on my mac with launch I see a flicker of the window
    set numberOfWindows to (count windows)
    repeat with i from 1 to numberOfWindows
        close front window
    end repeat
end tell

-- may add some delay here if it still flickers the window
    -- delay 1

tell application "QuickTime Player"
    open URL "http://www.a-1radio.com/listen.pls"
    set visible of every window to false
end tell

tell application "System Events"
    set visible of process "QuickTime Player" to false
end tell

-- must be called after the open URL command or won't work (no idea why)

要关闭流,请退出或关闭窗口(如果您打算重新打开,只需关闭):

tell application "QuickTime Player"

    -- here you can either:

    -- close all (will leave app open and hidden)
    set numberOfWindows to (count windows)
    repeat with i from 1 to numberOfWindows
        close front window
    end repeat

    -- or:

    quit -- or just quit (will close app so will need to hide again next time)
end tell

如果在打开 url 之前隐藏它,它就不起作用(不知道为什么)。当然,即使不可见,窗口仍然是打开的,所以如果有人点击停靠图标,它将显示所有打开的窗口。如果您不想停止以前的流,请删除repeat -- end repeat顶部的第一部分,但保留该set numberOfWindows to (count windows)部分无用,但无需激活/启动命令即可激活应用程序

于 2012-12-06T11:53:55.797 回答