我想用我的无头树莓派 4 作为在线广播播放器。如果我从终端运行 python 脚本并且树莓派输出音频,但我尝试从 /etc/rc.local 并在启动后使用 crontab 运行它,它似乎可以工作,但是没有声音。你知道如何在开机后运行它来输出声音吗?
谢谢!
import vlc
import time
url = 'http://www.icast.connectmedia.hu/4748/mr7.mp3'
#define VLC instance
instance = vlc.Instance()
#Define VLC player
player=instance.media_player_new()
#Define VLC media
media=instance.media_new(url)
#Set player media
player.set_media(media)
#Play the media
player.play()
#Sleep for 5 sec for VLC to complete retries.
time.sleep(5)
#Get current state.
state = str(player.get_state())
while state == 'State.Playing':
state = str(player.get_state())
time.sleep(1)