https://wiki.archlinux.org/api.php?action=feedcontributions&user=Ne&feedformat=atomArchWiki - User contributions [en]2024-03-19T03:34:51ZUser contributionsMediaWiki 1.41.0https://wiki.archlinux.org/index.php?title=Music_Player_Daemon&diff=222244Music Player Daemon2012-09-09T14:07:59Z<p>Ne: grammar</p>
<hr />
<div>[[Category:Player]]<br />
[[Category:Daemons and system services]]<br />
[[de:Music Player Daemon]]<br />
[[es:Music Player Daemon]]<br />
[[fr:MPD]]<br />
[[it:Music Player Daemon]]<br />
[[nl:Music Player Daemon]]<br />
[[pl:Music Player Daemon]]<br />
[[ru:Music Player Daemon]]<br />
[[sr:Music Player Daemon]]<br />
[[tr:Music_Player_Daemon]]<br />
[[zh-CN:Music Player Daemon]]<br />
{{Article summary start}}<br />
{{Article summary text|Installation, configuration and basic troubleshooting of MPD.}}<br />
{{Article summary heading|Required software}}<br />
{{Article summary link|Music Player Daemon|http://mpd.wikia.com}}<br />
{{Article summary heading|Related Articles}}<br />
{{Article summary wiki|MPD/Tips and Tricks}}<br />
{{Article summary wiki|MPD/Troubleshooting}}<br />
{{Article summary heading|Other sources}}<br />
{{Article summary text|[[Wikipedia:MPD|Wikipedia article]]}}<br />
{{Article summary end}}<br />
<br />
'''MPD''' ('''m'''usic '''p'''layer '''d'''aemon) is an audio player that has a server-client architecture. It plays audio files, organizes playlists and maintains a music database all while using very few resources. In order to interface with it, a separate [[#Clients|client]] is needed.<br />
<br />
== Installation ==<br />
=== Stable version ===<br />
The latest stable version of {{Pkg|mpd}} is available in the [[official repositories]].<br />
=== Git version ===<br />
Should users wish to run an experimental version, the [[AUR]] offers several from which to choose. For example, {{AUR|mpd-git}}.<br />
<br />
== Setup ==<br />
MPD is able to run globally (settings apply to all users), locally (per user settings), and in multiple instances.<br />
The way of setting up mpd depends on the way it is supposed to be used.<br />
A local configuration may prove more useful on a desktop system than on a system that is used by several people simultaneously.<br />
<br />
For a comfortable use, it is sensible to provide MPD access to the following files and directories:<br />
mpd.db # The music database<br />
mpd.pid # The file where mpd stores its process ID<br />
mpd.log # mpd logs here<br />
mpdstate # mpd's current state is noted here<br />
playlists # the folder where playlists are saved into<br />
<br />
In order for MPD to be able to play back audio, [[ALSA]], [[PulseAudio]] or [[OSS]] needs to be setup and working.<br />
<br />
=== Global Configuration ===<br />
{{Note|For a user-specific permissions, change the "user" line above to reflect one of the system users.}}<br />
{{Warning|Users of PulseAudio with a local mpd have to implement a [[Music Player Daemon/Tips and Tricks#Local (with separate mpd user)|workaround]] in order to run mpd as its own user!}}<br />
<br />
MPD comes with an example configuration file, available at {{ic|/usr/share/doc/mpd/mpdconf.example}}. This file holds an abundance of information on MPD configuration, and holds default mixer values.<br />
<br />
Normally,{{ic|/etc/mpd.conf}} have been created when installing mpd. If not, copy the included example file to {{ic|/etc/mpd.conf}}.<br />
# cp /usr/share/doc/mpd/mpdconf.example /etc/mpd.conf<br />
<br />
==== Editing mpd.conf ====<br />
The default Arch install keeps the setup in {{ic|/var/lib/mpd}} and uses "mpd" as default user.<br />
<br />
Edit {{ic|/etc/mpd.conf}} to reflect as such:<br />
{{hc|/etc/mpd.conf|<br />
music_directory "/home/user/music"<br />
playlist_directory "/var/lib/mpd/playlists"<br />
db_file "/var/lib/mpd/mpd.db"<br />
log_file "/var/log/mpd/mpd.log"<br />
pid_file "/run/mpd/mpd.pid"<br />
state_file "/var/lib/mpd/mpdstate"<br />
user "mpd"<br />
# bind_to_address "127.0.0.1"<br />
# port "6600"<br />
}}<br />
Now change permissions for mpd to write to {{ic|/var/log/mpd/mpd.log}}, otherwise mpd will returns an error when started. Best is to make the {{ic|/var/log/mpd/mpd.log}} belongs to mpd [[Users and Groups#Group management|user]].<br />
# chown -R mpd /var/log/mpd <br />
also, run this to create the /run/mpd dir:<br />
# systemd-tmpfiles --create<br />
To change the volume of audio from mpd independent of other programs, uncomment or add the switch in mpd.conf:<br />
<br />
{{hc|/etc/mpd.conf|<br />
mixer_type "software"<br />
}}<br />
<br />
Users of [[PulseAudio]] will need to make the following modification:<br />
{{hc|/etc/mpd.conf|2=<br />
audio_output {<br />
type "pulse"<br />
name "pulse audio"<br />
}<br />
}}<br />
<br />
Users of [[ALSA]] will want to have the following device definition, which allows software volume control in the MPD client to control the volume separately from other applications.<br />
{{hc|/etc/mpd.conf|2=<br />
audio_output {<br />
type "alsa"<br />
name "My Sound Card"<br />
mixer_type "software" # optional<br />
}<br />
}}<br />
<br />
Changing the group that MPD runs as may result in errors like "output: Failed to open "My ALSA Device"" "[alsa]: Failed to open ALSA device "default": No such file or directory" "player_thread: problems opening audio device while playing "Song Name.mp3""<br />
<br />
This is because by default MPD runs as member of '''audio''' group and the sound devices under {{Ic|/dev/snd/}} are owned by this group.<br />
<br />
===== Music directory =====<br />
MPD needs to have {{ic|+x}} permissions on ''all'' parent directories to the music collection (ie. if it's located outside of "mpd" home directory {{ic|/var/lib/mpd}}). By default useradd sets permissions on home directories to {{ic|1700 drwx------}}. Thus users will most likely need to remount the music directory under a directory that mpd has access to -- this only applies if running as the 'mpd' user.<br />
<br />
# mkdir /var/lib/mpd/music<br />
# echo "/home/$USER/music /var/lib/mpd/music none bind" >> /etc/fstab<br />
# mount -a<br />
# rc.d restart mpd<br />
See also [https://bbs.archlinux.org/viewtopic.php?id=86449 the forum thread.]<br />
<br />
An additional solution would be to just create a symbolic link into {{ic|/var/lib/mpd/music}}.<br />
# mkdir /var/lib/mpd/music<br />
# ln -s MUSIC_FOLDER /var/lib/mpd/music/<br />
# rc.d restart mpd<br />
<br />
If the music collection is contained under multiple directories, create symbolic links under the main music directory in {{ic|/var/lib/mpd}}. Remember to set permissions accordingly on the directories being linked.<br />
<br />
==== Creating the required files ====<br />
Now, having finished configuring MPD, the files and directories for MPD to write in need to be created:<br />
<br />
Create the directories and files specified in {{ic|/etc/mpd.conf}}:<br />
# mkdir -p /var/lib/mpd/playlists <br />
# touch /var/lib/mpd/{mpd.db,mpdstate} <br />
<br />
Usually the init-script should properly create {{ic|/run/mpd/}} when starting. The deamon will use this directory to create {{ic|mpd.pid}} in it. However, when running mpd as a different user, requires an update to the tmpfiles.d: In {{ic|/usr/lib/tmpfiles.d/mpd.conf}}:<br />
Change:<br />
d /run/mpd 0755 mpd mpd<br />
to:<br />
d /run/mpd 0755 ''username'' ''groupname''<br />
<br />
Change the file's permissions so that the daemon can modify them.<br />
# chown -R mpd /var/lib/mpd<br />
<br />
==== Create database ====<br />
Creating the database is now accomplished via the update feature of the client, for example {{ic|mpc update}}. <br />
{{Box RED | Note: | Creating the MPD database as root using {{ic|# mpd --create-db}} is deprecated.}}<br />
<br />
==== Timeline of MPD startup ====<br />
To depict when MPD drops its superuser privileges and assumes those of the user set in the configuration, the timeline of a normal MPD startup is listed here:<br />
<br />
# MPD is started on boot by {{ic|/etc/rc.conf}}, by including it in the {{ic|DAEMONS}} array. (Or, this can be done manually each session by running {{ic|rc.d start mpd}} with root privileges).<br />
# Since MPD is now started as root, it first reads the {{ic|/etc/mpd.conf}} file.<br />
# MPD reads the user variable in the {{ic|/etc/mpd.conf}} file, and changes from root to this user.<br />
# MPD then reads the contents of the {{ic|/etc/mpd.conf}} file and configures itself accordingly.<br />
<br />
Notice that MPD changes the running user from root to the one named in the {{ic|/etc/mpd.conf}} file. <br />
This way, uses of {{ic|~}} in the configuration file point correctly to the home user's directory, and not root's directory. <br />
It may be worthwhile to change all uses of {{ic|~}} to {{ic|/home/username}} to avoid any confusion over this aspect of MPD's behavior.<br />
<br />
=== Local Configuration (per user) ===<br />
MPD does not need to be run globally as a daemon and can rather work per user. The usual method to configure MPD globally is because the listed files and folders in the default configuration file point to directories owned by root (the {{ic|/var}} directory).<br />
<br />
A less used (but perhaps more sensible) method is to make MPD work with files and directories owned by a normal user. Running MPD as a normal user has the benefits of:<br />
<br />
* A single directory {{ic|~/.mpd}} (or any other directory under {{ic|/home/username}}) that will contain all the MPD configuration files.<br />
* Easier to avoid unforeseen read/write permission errors.<br />
<br />
{{Note|This approach will not work with multiple users to having access to MPD at the same time.}}<br />
<br />
Begin the setup by creating a directory for the required files and the playlists:<br />
<br />
{{bc|mkdir -p ~/.mpd/playlists}}<br />
<br />
Copy the contents of the default MPD configuration file in {{ic|/usr/share/mpd/mpd.conf.example}} to the target user's home directory:<br />
<br />
{{bc|cp /usr/share/doc/mpd/mpdconf.example ~/.mpdconf}}<br />
<br />
Create all of the requisite files:<br />
<br />
{{bc|<nowiki>touch ~/.mpd/{mpd.db,mpd.log,mpd.pid,mpdstate}</nowiki>}}<br />
<br />
Edit {{ic|~/.mpdconf}} to specify these files:<br />
<br />
{{hc|~/.mpdconf|<br />
music_directory "/home/USER/music" # Keep commented if your XDG directory already points to it<br />
playlist_directory "/home/USER/.mpd/playlists"<br />
db_file "/home/USER/.mpd/mpd.db"<br />
log_file "/home/USER/.mpd/mpd.log"<br />
pid_file "/home/USER/.mpd/mpd.pid"<br />
state_file "/home/USER/.mpd/mpdstate"<br />
}}<br />
<br />
MPD can now be started by typing {{ic|mpd}} on the command line.<br />
<br />
To have MPD start with the X server add it to [[xprofile]].<br />
<br />
==== Scripted Configuration ====<br />
Rasi has written a script that will create the proper directory structure, configuration files and prompt for the location of the user's Music directory; it can be downloaded [http://karif.server-speed.net/~carnager/mpdsetup.tar here].<br />
<br />
=== Multi-mpd setup ===<br />
'''Useful if running an icecast server.'''<br />
<br />
For a second MPD (e.g., with icecast output to share music over the network) using the same music and playlist as the one above, simply copy the above configuration file and make a new file (e.g., {{ic|/home/username/.mpd/config-icecast}}), and only change the log_file, error_file, pid_file, and state_file parameters (e.g., {{ic|mpd-icecast.log}}, {{ic|mpd-icecast.error}}, and so on); using the same directory paths for the music and playlist directories would ensure that this second mpd would use the same music collection as the first one e.g., creating and editing a playlist under the first daemon would affect the second daemon as well. Users do not have to create the same playlists all over again for the second daemon. Call this second daemon the same way from {{ic|~/.xinitrc}} above. (Just be sure to have a different port number, so as to not conflict with the first mpd daemon).<br />
<br />
== Clients ==<br />
A separate client is needed to control mpd. Popular options are:<br />
<br />
=== Console ===<br />
*{{App|mpc|Simple KISS client. All basic functionality available|http://mpd.wikia.com/wiki/Client:Mpc|{{Pkg|mpc}}}}<br />
*{{App|ncmpc|A NCurses client for mpd|http://mpd.wikia.com/wiki/Client:Ncmpc|{{Pkg|ncmpc}}}}<br />
*{{App|ncmpcpp|An almost exact clone of ncmpc with some new features written in C++ (tag editor, search engine)|http://unkart.ovh.org/ncmpcpp/|{{Pkg|ncmpcpp}}}}<br />
*{{App|pms|Highly configurable and accessible ncurses client|http://pms.sourceforge.net/|{{AUR|pmus}}}}<br />
=== Graphical ===<br />
*{{App|Ario|A very feature-rich GTK2 GUI client for mpd, inspired by Rhythmbox|http://ario-player.sourceforge.net/|{{Pkg|ario}}}}<br />
*{{App|QmpdClient|A GUI client written with Qt 4.x|http://bitcheese.net/wiki/QMPDClient|{{Pkg|qmpdclient}}}}<br />
*{{App|Sonata|An elegant Python GTK+ client|http://sonata.berlios.de/|{{Pkg|sonata}}}}<br />
*{{App|gmpc|GNOME Client|http://gmpc.wikia.com/wiki/Gnome_Music_Player_Client|{{Pkg|gmpc}}}}<br />
*{{App|Dmpc|Dmenu-based MPC client with a playlist manager and state-saving on playlist changes|http://wintervenom.mine.nu/|{{AUR|dmpc}}}}<br />
<br />
=== Web ===<br />
*{{App|Patchfork|web client for MPD written in PHP and Ajax|http://mpd.wikia.com/wiki/Client:Pitchfork|{{AUR|patchfork-git}}}}.<br />
<br />
See a long list of clients at the [http://mpd.wikia.com/wiki/Clients mpd wiki].<br />
<br />
== External links ==<br />
* [http://mpd.wikia.com/wiki/Clients Sorted List of MPD Clients]<br />
* [http://www.musicpd.org/forum/ MPD forum]</div>Ne