Wednesday, October 14, 2009

Using mplayer, find & play mp3 files from command line in Ubuntu Linux

Save precious CPU and memory by using mplayer to play mp3s, also keep your playlist file up to date with all your mp3 media files.
First and foremost we need to have mplayer installed, if your on a ubuntu-debian based system use the following commandto install mplayer, if not then you can download the appropriate packages and install them.

apt-get install mplayer

Lets make a home for our script file, and set the appropiate permissions

mkdir ~/scripts; touch ~/scripts/playme.sh; chmod +x ~/scripts/playme.sh; gedit ~/scripts/playme.sh

Paste the following code into your new script file, if you keep your Music files in a different location then change the variable musdir to match your setup.

#/bin/bash
#VARS###################################
tmpdir='/tmp'
musdir='/home/osamad/Music'
filename='playlist.m3u'
# CODE ##########################################
find $musdir -name '*.mp3' -o -name '*.ogg' 2>/dev/null >> $tmpdir/$filenamemplayer -playlist $tmpdir/$filename -shuffle -loop 0 -radio volume=80






Using find we build a list of all our mp3s, in this case we have multiple types of media files we want to play so we can specify that by adding the -o -name flags and add them in.
-playlist ;flag we set the playlist file we just created
-shuffle ; enables shuffle mode
-loop 0 ; enables loop 0=forever
-radio volume=80 ; set the default volume to 80% (use * or / to adjust when playing)

RunTime
Push ALT+F2 or launch from a terminal

./scripts/playme.sh





MORE
To find out more information, or to customize your mplayer settings
man mplayer
Create a custom launcher and run your script from the gnome-panel

.

No comments:

Post a Comment