SEARCH

Enter your search query in the box above ^, or use the forum search tool.

You are not logged in.

#1 2009-09-18 18:00:46

benj1
Wiki Wizard
From: Yorkshire, England
Registered: 2009-09-05
Posts: 1,084

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 mpd

then because its a daemon (Music Player Daemon) you need something to control it with:

sudo apt-get install mpc

next you need to sort out a configuration file:

zcat /usr/share/doc/mpd/examples/mpd.conf.gz > ~/.mpdconf

also create a file for later:

mkdir ~/.mpd

and now to edit:

nano ~/.mpdconf

(or your prefered editor)

in the 'Files and directories' 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 'General music daemon options' comment out 'user' (add a # to the start of the line) and uncomment
'#auto_update    "yes"'
and
'#auto_update_depth "3"'      (remove the leading #).


and finally in 'Audio Output' make sure the alsa audio driver is uncommented.
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

mpd
mpc ls

should show your albums, this can be piped like so:

mpc ls | mpc add

and 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/mpd

and change the START_MPD option to false

 START_MPD=false

then

sudo mpd --kill

to 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 mpc

for 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 smile

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:
        pass

save 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-mpd

add 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 cool

EDIT: 25/4/11 simplified config file setup, and modified to reflect newer config file

Last edited by benj1 (2011-04-25 20:40:21)


- - - - - - - - Wiki Pages - - - - - - -
#! install guide           *autostart programs, modify the menu & keybindings
configuring Conky       *installing scripts

Offline

Be excellent to each other!

#2 2009-09-30 18:14:28

uberbdon
#! CrunchBanger
Registered: 2009-09-13
Posts: 135

Re: Howto: MPD

i get this error: brandon@brandon-laptop:~$ mpd

** ERROR **: problems opening file /etc/mpd.conf for reading: Permission denied

aborting...
Aborted

Offline

#3 2009-09-30 19:39:32

benj1
Wiki Wizard
From: Yorkshire, England
Registered: 2009-09-05
Posts: 1,084

Re: Howto: MPD

uberbdon wrote:

i get this error: brandon@brandon-laptop:~$ mpd

** ERROR **: problems opening file /etc/mpd.conf for reading: Permission denied

aborting...
Aborted

are you sure youve got the .mpdconf in your home directory, mpd will search there first if it cant find that it will then try to use /etc/mpd.conf


- - - - - - - - Wiki Pages - - - - - - -
#! install guide           *autostart programs, modify the menu & keybindings
configuring Conky       *installing scripts

Offline

#4 2009-10-02 17:27:57

benj1
Wiki Wizard
From: Yorkshire, England
Registered: 2009-09-05
Posts: 1,084

Re: Howto: MPD

glad to be of service smile


- - - - - - - - Wiki Pages - - - - - - -
#! install guide           *autostart programs, modify the menu & keybindings
configuring Conky       *installing scripts

Offline

#5 2009-10-19 11:30:16

machinebacon
#! unstable
From: China
Registered: 2009-07-02
Posts: 6,619
Website

Re: Howto: MPD

thanks a lot, great post! i have additionally installed the ncmpc as frontend. 

greetings!

Offline

#6 2009-10-19 14:35:25

Raffles10
#! Member
From: London, UK
Registered: 2009-08-27
Posts: 73

Re: Howto: MPD

For some extra functionality you might try ncmpcpp:

tag editor * playlists editor * easy to use search screen * media library screen * lyrics screen * possibility of going to any position in currently playing track without rewinding/fastforwarding * multi colored main window (if you want) * songs can be added to playlist more than once * and a lot of minor useful functions. smile

Offline

#7 2009-10-20 14:08:31

wildebos
New Member
Registered: 2009-08-16
Posts: 5

Re: Howto: MPD

Awesome post, thanks !! smile

Offline

#8 2009-10-30 19:00:49

pvsage
Internal Affairs
From: North Carolina
Registered: 2009-10-18
Posts: 11,975

Re: Howto: MPD

OK benj1, so I followed your instructions to the letter, and I get this when I try to run MPD:

unable to bind port 6600: Address already in use
maybe MPD is still running?
Aborted

Do I just tell it to use a different port?  What else might be bound to this port?


I'm a moderator here.  How are we doing?  Feedback is encouraged.

Offline

#9 2009-10-30 19:52:51

benj1
Wiki Wizard
From: Yorkshire, England
Registered: 2009-09-05
Posts: 1,084

Re: Howto: MPD

if 'pgrep mpd' gives you anything, its running

mpd --kill will kill mpd

it is possible that something else is using the port, i dont know how to check definitively though

if you need to you can change the port in .mpdconf


- - - - - - - - Wiki Pages - - - - - - -
#! install guide           *autostart programs, modify the menu & keybindings
configuring Conky       *installing scripts

Offline

#10 2009-10-30 20:07:18

pvsage
Internal Affairs
From: North Carolina
Registered: 2009-10-18
Posts: 11,975

Re: Howto: MPD

pgrep mpd returns 3087.

mpd --kill returns
** ERROR **: unable to open pid_file "/home/peter/.mpd/pid": No such file or directory;;aborting;aborted
(semicolons are newlines)

Any ideas?


I'm a moderator here.  How are we doing?  Feedback is encouraged.

Offline

#11 2009-10-30 20:15:45

benj1
Wiki Wizard
From: Yorkshire, England
Registered: 2009-09-05
Posts: 1,084

Re: Howto: MPD

first off have you made an ~/.mpd directory? if not do that

if not try 'killall mpd' and then restart it

failing that im guessing youve started it and then changed the pid file?
try changing the conf file to point to '/var/run/mpd/pid'

see if that works

Last edited by benj1 (2009-10-30 20:18:18)


- - - - - - - - Wiki Pages - - - - - - -
#! install guide           *autostart programs, modify the menu & keybindings
configuring Conky       *installing scripts

Offline

#12 2009-10-30 20:31:24

pvsage
Internal Affairs
From: North Carolina
Registered: 2009-10-18
Posts: 11,975

Re: Howto: MPD

sudo killall mpd did the trick. smile


I'm a moderator here.  How are we doing?  Feedback is encouraged.

Offline

#13 2009-10-30 23:17:42

pvsage
Internal Affairs
From: North Carolina
Registered: 2009-10-18
Posts: 11,975

Re: Howto: MPD

Something is starting mpd as root at startup.  It isn't in autostart.sh or the autorun directory.  Where could it be?  I've looked everywhere I can think of, and many places I couldn't think of.  I hate having to sudo killall mpd just to run it again with luser rights.

Last edited by pvsage (2009-10-30 23:18:41)


I'm a moderator here.  How are we doing?  Feedback is encouraged.

Offline

#14 2009-10-31 01:09:31

pvsage
Internal Affairs
From: North Carolina
Registered: 2009-10-18
Posts: 11,975

Re: Howto: MPD

Ya know what?  I'm not gettin' *any* album art in Sonata!  Nuttin!  Even the Yes album 90125, which shows up with every other media player I've tried that shows album art, isn't coming up.  WTF?

Going back to MoC for music play & Banshee just to cache album art.  Bash script to show MoC in Conky, and another to grab album art from Banshee's cache (based on MoC) and throw that to Conky.  It's a kludge, but it took a lot less headache to get this kludge set up than setting up a proper Sonata + mpd.


I'm a moderator here.  How are we doing?  Feedback is encouraged.

Offline

#15 2009-10-31 10:32:57

UkDkDe
Member
Registered: 2009-05-08
Posts: 47

Re: Howto: MPD

@ pvsage

After following this post, I had the problem of mpd running at start. Could only kill from sudo. Fixed as follows:
Make sure you have user as "your user name" in both the ~/.mpdconf AND the etc/mpd.conf files.
Then start mpd at openbox start by adding   mpd &

Offline

#16 2009-10-31 22:12:59

pvsage
Internal Affairs
From: North Carolina
Registered: 2009-10-18
Posts: 11,975

Re: Howto: MPD

Since I can't imagine my Mini running as an actual server, I fixed my mpd problem by going back to MoC. MoC is uglier than a Fender Tweed amp, and sounds just as beautiful. cool


I'm a moderator here.  How are we doing?  Feedback is encouraged.

Offline

#17 2009-11-02 13:16:30

MacAnkka
New Member
Registered: 2009-11-02
Posts: 2

Re: Howto: MPD

Thanks for this nice guide! I've used mpd once before on a ubuntu box and it was a real pain to set up via trial and error.

About the mpd running as root on startup: you can disable that from the file /etc/default/mpd

like this, for example: "sudo nano /etc/default/mpd" and change the line

START_MPD=true

to

START_MPD=false

Offline

#18 2009-11-02 14:09:33

benj1
Wiki Wizard
From: Yorkshire, England
Registered: 2009-09-05
Posts: 1,084

Re: Howto: MPD

MacAnkka wrote:

Thanks for this nice guide! I've used mpd once before on a ubuntu box and it was a real pain to set up via trial and error.

About the mpd running as root on startup: you can disable that from the file /etc/default/mpd

like this, for example: "sudo nano /etc/default/mpd" and change the line

START_MPD=true

to

START_MPD=false

hmm i wonder why its a problem for some and not others, what problems/error messages were you getting, so i can update the guide


- - - - - - - - Wiki Pages - - - - - - -
#! install guide           *autostart programs, modify the menu & keybindings
configuring Conky       *installing scripts

Offline

#19 2009-11-02 15:17:27

pvsage
Internal Affairs
From: North Carolina
Registered: 2009-10-18
Posts: 11,975

Re: Howto: MPD

I'll wager his problems were the same as mine - mpd starting either at boot or at login, forcing a sudo killall to release port 6600.  I think the update should be to add his bit about editing /etc/default/mpd.

I wonder if simply deleting /etc/default/mpd would also fix the problem?

Maybe another option would be to simply let mpd run as root, and have a symlink in /var/lib/mpd/music that points to ~/music, so if you have multiple accounts on the computer they can all use their own music folders?

EDIT:  Incidentally, mpd started automatically as root the moment I installed it.

Last edited by pvsage (2009-11-02 15:18:42)


I'm a moderator here.  How are we doing?  Feedback is encouraged.

Offline

#20 2009-11-02 15:46:47

MacAnkka
New Member
Registered: 2009-11-02
Posts: 2

Re: Howto: MPD

pvsage wrote:

I'll wager his problems were the same as mine - mpd starting either at boot or at login, forcing a sudo killall to release port 6600.  I think the update should be to add his bit about editing /etc/default/mpd.

Yep. That was it.

pvsage wrote:

Maybe another option would be to simply let mpd run as root, and have a symlink in /var/lib/mpd/music that points to ~/music, so if you have multiple accounts on the computer they can all use their own music folders?

Running it as root and pointing to ~/music would make it search for music from root's home folder (mpd doesn't know what user is controlling it through mpc/sonata/etc). If you run it as root or as mpd's own user (default is a user named "mpd"), you should use the full path to the music and make sure that the user mpd is being run under has permissions for that folder. This is the way mpd is usually run. It's quite cool in a way, you can log out, switch users or do pretty much anything other than turning the computer off and the music just keeps playing.

That's the way I ran it the last time, but especially making sure the "mpd" user had the rights and privlidges to access the music was a little confusing. Unlike when you run it under your own user, where if you can access the music yourself, so can mpd.

Last edited by MacAnkka (2009-11-02 15:47:25)

Offline

#21 2009-11-02 16:08:14

benj1
Wiki Wizard
From: Yorkshire, England
Registered: 2009-09-05
Posts: 1,084

Re: Howto: MPD

well ive added an update section saying if you get errors such as
"problem opening log file "/root/.mpd/mpd.log" (config line 11) for writing"
or mpd not finding music files, im guessing those would be the symptoms?


- - - - - - - - Wiki Pages - - - - - - -
#! install guide           *autostart programs, modify the menu & keybindings
configuring Conky       *installing scripts

Offline

#22 2009-11-02 16:10:31

pvsage
Internal Affairs
From: North Carolina
Registered: 2009-10-18
Posts: 11,975

Re: Howto: MPD

MacAnkka wrote:

If you run it as root or as mpd's own user (default is a user named "mpd"), you should use the full path to the music and make sure that the user mpd is being run under has permissions for that folder.

IOW, dump all music in e.g. /music and set that directory's owner as mpd, but give all users permissions to that folder so they can add music to it?  That sounds like it could become an even bigger quagmire if you have luser accounts on your system. hmm Giggity giggity!

I suppose it might be best to just go through the trouble of setting up mpd for the individual client first, then copy .mpdconf to the individual user and luser home directories as needed. roll


I'm a moderator here.  How are we doing?  Feedback is encouraged.

Offline

#23 2009-11-02 16:16:53

pvsage
Internal Affairs
From: North Carolina
Registered: 2009-10-18
Posts: 11,975

Re: Howto: MPD

The specific error I found due to mpd autostart (assuming I had edited .mpdconf properly) was

unable to bind port 6600: Address already in use
maybe MPD is still running?
Aborted

when I tried to run mpd as a regular user.


I'm a moderator here.  How are we doing?  Feedback is encouraged.

Offline

#24 2009-11-02 16:47:39

benj1
Wiki Wizard
From: Yorkshire, England
Registered: 2009-09-05
Posts: 1,084

Re: Howto: MPD

ok ive added that bit as well


- - - - - - - - Wiki Pages - - - - - - -
#! install guide           *autostart programs, modify the menu & keybindings
configuring Conky       *installing scripts

Offline

Help fund CrunchBang, donate to the project!

#25 2009-11-03 18:48:16

pvsage
Internal Affairs
From: North Carolina
Registered: 2009-10-18
Posts: 11,975

Re: Howto: MPD

The file in /etc/default is mpd, not mpd.conf.  But thanks for updating the instructions!


I'm a moderator here.  How are we doing?  Feedback is encouraged.

Offline

Board footer

Powered by FluxBB

Copyright © 2012 CrunchBang Linux.
Proudly powered by Debian. Hosted by Linode.
Debian is a registered trademark of Software in the Public Interest, Inc.

Debian Logo