簡體   English   中英

如何循環播放來自 Spotify 的曲目的無休止請求?

[英]How to loop an endless request to play a track from Spotify?

我已經在腳本編輯器中編寫了這段代碼。 程序循環一次或兩次,但很快就停止了。 該代碼的目的是在受害者的Mac電腦上無限播放“我的心將go on”。 相反,它只循環兩次並且很容易中斷。 我怎樣才能使這個萬無一失?

repeat
    set volume 10
    try
        using terms from application "Spotify"
            if player state of application "Spotify" is paused then
                tell application "Spotify" to play
                return "unpaused"
            end if
        end using terms from
        tell application "System Events" to (name of processes) contains "Spotify"
        if true then
            tell application "Spotify"
                play track "spotify:track:33LC84JgLvK2KuW43MfaNq" in context "spotify:playlist:2CLbqnKJirVefl8xdtMvEN"
            end tell
            
        else
            open application "Spotify"
        end if
    end try
end repeat

有些東西告訴我,您所指的“受害者的 Mac”屬於您的一位女士。 (順便說一句……您可能需要考慮編輯您的問題並重新使用“受害者的”)

如果是這種情況,並且本着“Guy Code”和“Bro's Before Ho's”的精神,我重新修改了您的代碼。 這應該會給你你正在尋找的結果。

我讓它變得更友好一點,這樣當代碼啟動時,它將激活 Spotify 並在repeat循環中繼續運行命令,只有在 Spotify 運行時。 它不會繼續重新激活 Spotify。 如果用戶退出 Spotify, AppleScript 也會停止。

這個AppleScript代碼適用於我使用最新版本的macOS Big Sur

use Spotify : application "Spotify" with importing
use scripting additions

if Spotify is not running then launch Spotify

repeat while Spotify is running
    set volume 10 -- System Volume
    try
        set sound volume to 100 -- Spotify Volume
        if Spotify is running and Spotify's player state is in {paused, stopped} ¬
            and Spotify's current track's spotify url ¬
            is in "spotify:track:33LC84JgLvK2KuW43MfaNq" then
            play
        else if Spotify is running and Spotify's current track's spotify url is not in ¬
            "spotify:track:33LC84JgLvK2KuW43MfaNq" then
            play track "spotify:track:33LC84JgLvK2KuW43MfaNq" in context ¬
                "spotify:playlist:2CLbqnKJirVefl8xdtMvEN"
        end if
        delay 5
    end try
end repeat

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM