play a stream in iTunes without adding it to the library / playlist

一个人想着一个人 提交于 2019-12-13 01:00:38

问题


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

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?


回答1:


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

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

(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

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



来源:https://stackoverflow.com/questions/12060827/play-a-stream-in-itunes-without-adding-it-to-the-library-playlist

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!