【问题标题】:play a stream in iTunes without adding it to the library / playlist在 iTunes 中播放流而不将其添加到库/播放列表
【发布时间】:2012-08-21 18:23:53
【问题描述】:

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

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

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

【问题讨论】:

    标签: streaming applescript itunes


    【解决方案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)

    【讨论】:

    • 有趣的想法,我愿意接受 QuickTime。但是,每次我打开一个 URL 时,它总是会打开一个新窗口。你知道如何避免吗?理想情况下,根本不会显示任何可见的 UI,但可以接受 Dock 中的 QuickTime 符号。永远歌的新窗口不是。
    • @Daniel 编辑代码。它现在似乎可以根据您的需要在我的 Mac 上工作,但执行时间可能会稍微改变行为,因此在更快的 Mac 上,它可能会显示窗口一秒钟或不隐藏它(不确定)考虑测试或在评论处添加延迟说(减慢执行速度)。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-08
    • 1970-01-01
    相关资源
    最近更新 更多