0

first of all, Thank you for all the help I've gotten from this place so far! Keep up the good work!

This is my first programming project so forgive me if this is a stupid question but I've come to a complete stop and can't find the answer anywhere!

I've created a playlist and I can run it from the terminal with mplayer. But I want to make a Python script that does it for me including shuffling the list.

I've managed to find a script that play a single song but not from a playlist.

import commands
import os

SOUND = 'music.mp3'

command = 'mplayer %s 1>/dev/null 2>&1' % SOUND
os.system(command)

Ohyeah, I should probably mention that this is on a Debian system if that makes any difference.

Thanks again!

1 Answers1

2

This works..

import subprocess
myplaylist = "/path/to/playlist/somePlaylist.txt"
subprocess.call(['mplayer', '-vo', 'null', '-ao', 'alsa', '-playlist', myplaylist, '-shuffle'])

Actually, after trying, your way is heaps better because I can use it to log mplayers output.

I create a pipe

pi@raspberrypi$ mkfifo /tmp/pipe

then use the following command in my python script

command = "mplayer -vo null -ao alsa -playlist /home/pi/music/HelensFaves.txt -slave -input file=/tmp/pipe -quiet -loop 0 > /tmp/mlog.txt"
os.system(command)

and then control mplayer by sending commands to the pipe

echo "pt_step 1" > /tmp/pipe
john
  • 21
  • 3