在 iTunes 中播放流而不将其添加到库/播放列表 [英] play a stream in iTunes without adding it to the library / playlist

查看:16
本文介绍了在 iTunes 中播放流而不将其添加到库/播放列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I am controlling iTunes via AppleScript and I am playing streams from an HTTP server. The code I'm using looks like this:

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

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

It works fine, but I would like to avoid those URLs to show up in the iTunes library or any playlist afterwards. Is there a trick to achieve that?

推荐答案

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

Have you considered using QuickTimePlayer to play the stream instead?

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

它应该可以打开所有 iTunes 格式,它是 OsX 的默认格式,它更最小",不会保存曲目.

It should open all the iTunes formats, it comes as a default on OsX, it is more "minimal", won't save tracks.

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

(I know you specified you want to use iTunes so this might not be a solution, but being preinstalled software it was worth a try)

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

EDIT To have it hidden, this seems to work:

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)

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

To close the stream either quit or close windows (just close if you plan to reopen):

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)但无需激活/启动命令即可激活应用

If you hide it before opening the url, it doesn't work (no idea why). Of course the window, even if invisible, is still open so if someone clicks on the dock icon it will show all the open windows. If you don't want to stop previous streams remove the first repeat -- end repeat part at the top, but leave the set numberOfWindows to (count windows) that is useless but activates the app without needing a activate/launch command

这篇关于在 iTunes 中播放流而不将其添加到库/播放列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆