Hi,
The code below plays music on a Raspberry pi.
Instead of selecting music files, I'd like to listen to music from an url.
Can that be possible and if so, how?
TIA
The code below plays music on a Raspberry pi.
Instead of selecting music files, I'd like to listen to music from an url.
Can that be possible and if so, how?
TIA
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
import os, random from subprocess import check_output, Popen from shlex import split # needed for Popen MPL_COMMAND = 'mplayer -softvol -volume {vol} {file}' def popen( file , vol): command = MPL_COMMAND. format ( file = file , vol = vol) proc = Popen(split(command), stdout = None , stderr = None ) return proc.wait() def play (vol = 10 ) : path = "/home/pi/music/" # load files into a list songs = os.listdir ( path ) '''if random is chosen''' # choose a rdm number between 0 and tot of files -1 number = random.randint ( 0 , len ( songs ) - 1 ) # assign file to rdm number file = songs[number] file = path + file popen ( file , vol ) play() |