Topic: Howto: MPD
just noticed this thread,http://crunchbanglinux.org/forums/topic -use/page/ and it seems a lot of people were having trouble with mpd, just set it up myself so ive written this how to.
first of all install mpd:
sudo apt-get install mpdthen because its a daemon (Music Player Daemon) you need something to control it with:
sudo apt-get install mpcnext you need to sort out a configuration file:
sudo cp /usr/share/doc/mpd/examples/mpd.conf.gz ~next ownership permissions, at the moment the file is still owned by root so:
sudo chown 'user':'group' ~/mpd.conf.gzreplace 'user' and 'group' with your own, they should by default both be your username you use to login.
now extract:
gunzip ~/mpd.conf.gzand rename:
mv ~/mpd.conf ~/.mpdconf also create a file for later:
mkdir ~/.mpdand now to edit:
nano ~/.mpdconf(or your prefered editor)
in the 'required paths' section
change 'music_directory' from /var/lib/mpd/music to point to where your music is
change other '/var/lib/mpd' lines to ~/.mpd so '/var/lib/mpd/tag_cache' would be '~/.mpd/tag_cache'.
do the same for the 'optional paths'
in 'daemon options' comment out user (add a # to the start of the line)
and finally in audio output uncomment the alsa audio driver.
this bit:
audio_output {
type "alsa"
name "My ALSA Device"
device "hw:0,0" # optional
format "44100:16:2" # optional
}now it should work so start mpd
mpdmpc lsshould show your albums, this can be piped like so:
mpc ls | mpc addand then:
mpc play by this point you should hear sound (hopefully)
last thing is to have it start automatically,
add:
mpd to your ~/.config/openbox/autostart.sh
(you can add an & suffix it you want, its a daemon so doesnt really matter.)
UPDATE:
a few people have been reporting problems with mpd running as root automatically at startup, errors such as "problem opening log file "/root/.mpd/mpd.log" (config line 11) for writing",or "unable to bind port 6600: Address already in use" or not finding your music folder
if you have this problem modify /etc/default/mpd.conf
sudo nano /etc/default/mpdand change the START_MPD option to false
START_MPD=falsethen
sudo mpd --killto end the mpd currently running as root
now one of the great things about mpd is you can control it from anywhere, console, desktop, internet.
there are a whole host of front ends, ive heard good things about sonata, but ill cover standard crunchbang integration.
keyboard shortcuts
############
keybindings are kept in
'~/.config/openbox/rc.xml' accessible through the menu in preferences-->openbox
and add something like this to the keyboard section (around about line 160)
<!-- mpd bindings -->
<keybind key="W-Up">
<action name="Execute">
<command>mpc toggle</command>
</action>
</keybind>
<keybind key="W-Down">
<action name="Execute">
<command>mpc stop</command>
</action>
</keybind>
<keybind key="W-Left">
<action name="Execute">
<command>mpc prev</command>
</action>
</keybind>
<keybind key="W-Right">
<action name="Execute">
<command>mpc next</command>
</action>
</keybind>'keybind key' is the keybinging so <keybind key="W-Up"> is windows key plus up.
'<command>mpc toggle</command>' is the command in this case toggle (play pause).
check out the manpage for mpc
man mpcfor a full list of commands.
* See this post for XFCE keybindings http://crunchbanglinux.org/forums/post/78771/#p78771
conky integration
###########
conky has a list of options for displaying output from mpd.
the conkyrc is by default at '~/.conky' (i think) also in the menu under preferences.
this is my setup, although for a full list http://conky.sourceforge.net/variables.html
${if_mpd_playing} ${hr}
$mpd_artist
$mpd_album
${mpd_title 15}
$mpd_elapsed/$mpd_length
$mpd_status
${mpd_bar 5,180}
${execi 2 ~/.config/conky/mpd-albumart.py}
${image /tmp/mpd.jpg -s 80x80 -p 100,349 }
$endif
NB. at the moment ${if_mpd_playing} isn't working properly, it should hide when mpd is stopped but doesn't, its fixed in conky v1.8 so hopefully in karmic ![]()
the eagle eyed may have noticed:
${execi 2 ~/.config/conky/mpd-albumart.py}
${image /tmp/mpd.jpg -s 80x80 -p 100,349 }
its for displaying album art.
heres mpd-albumart.py
#! /usr/bin/env python
import sys,mpd,os,socket
musiclocation = '~/music' #location of music
artlocation = '~/.mpd/covers' #where you want albumart storing
tmp_path = '/tmp/mpd.jpg' #location for temporary file so conky can find it
musiclocation = os.path.expanduser(musiclocation)
artlocation = os.path.expanduser(artlocation)
client = mpd.MPDClient()
try:
client.connect("localhost", 6600)
except socket.error:
sys.exit(1)
song = client.currentsong()
artist = song['artist']
album = song['album']
covername = os.path.join( artlocation, artist+'-'+album+'.jpg')
covername = covername.replace(' ','_')
if covername == os.path.realpath(tmp_path): # already have correct album cover
sys.exit(0)
try:
os.remove(tmp_path)
except OSError: pass
if os.path.basename(covername) in os.listdir(artlocation):
os.symlink(covername, tmp_path)
else:
from urllib import FancyURLopener
class MyOpener(FancyURLopener): version = ''
try:
s = MyOpener().open('http://www.amazon.com/gp/search/keywords=%s+%s'%
(artist.replace(' ','+'),album.replace(' ','+'))).read()
import re
link = re.findall('http://ecx.images-amazon.com\S*.jpg',s)[0]
pic = MyOpener().open(link).read()
open(covername ,'w').write(pic)
os.symlink(covername, tmp_path)
except IOError:
passsave it some where, change the paths (line 7,8 (9 if you really want to)).
make it executable:
chmod +x mpd-albumart.py
install python-mpd (needed to get track info):
sudo apt-get install python-mpdadd this to your conkyrc:
imlib_cache_size 0 some where before TEXT (this ensures the picture will actually change)
the script will load, the picture, if there isnt one, will get one from the internet
${execi 2 /path/to/mpd-albumart.py} #change to correct path (the will run every 2 seconds)
${image /tmp/mpd.jpg -s 80x80 -p 100,349 }# this will load the image from /tmp/mpd.jpg, ( -s is size, -p is placement)
pipemenu
######
you can control mpd fully from your main menu
i wrote a script for a menu option which i started this thread with
http://crunchbanglinux.org/forums/topic
nu-thread/
and thats it, a fully integrated mpd setup ![]()
Last edited by benj1 (2010-08-05 19:57:30)
#! install guide *autostart programs, modify the menu & keybindings
configuring Conky *installing scripts