Still kind of new to Python, but I thought I better start with a project to learn it.
I wanted to make a combined internet radio with the possibility to stream with airplay (got that working) and to have easy selection of internet radio stations with buttons (not yet working). I have a RPi 0 with a button shim and a pHAT DAC.
With inspiration from another project involving thet button shim, I tried with the python code below.
When I run the script and presses button A, the stream starts playing. When I press button B, the other stream plays simultaneously. How to make the previous stream stop and player the other instead?
import time import signal import buttonshim import os import vlc def flash_led(interval, times, r, g, b): for i in range(times): buttonshim.set_pixel(r, g, b) time.sleep(interval) buttonshim.set_pixel(0, 0, 0) time.sleep(interval) def buttonflash(): flash_led(0.025, 3, 255, 255, 255) # Button A @buttonshim.on_release(buttonshim.BUTTON_A) def button_a(button, pressed): buttonflash() os.system('cvlc http://live-icy.gss.dr.dk/A/A03H.mp3.m3u') # Button B @buttonshim.on_release(buttonshim.BUTTON_B) def button_a(button, pressed): buttonflash() os.system('cvlc http://live-icy.gss.dr.dk/A/A04H.mp3.m3u')