在iTunes中播放流,而不将其添加到库/播放列表中



我通过AppleScript控制iTunes,并从HTTP服务器播放流。我使用的代码如下:

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

它工作得很好,但我希望避免这些URL出现在iTunes库或任何播放列表中。有什么诀窍可以做到这一点吗?

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

最新更新