https://wiki.archlinux.org/api.php?action=feedcontributions&user=Rasi&feedformat=atomArchWiki - User contributions [en]2024-03-29T14:22:05ZUser contributionsMediaWiki 1.41.0https://wiki.archlinux.org/index.php?title=Rofi&diff=593671Rofi2020-01-01T12:11:29Z<p>Rasi: highlight filename</p>
<hr />
<div>[[Category:Application launchers]]<br />
[[ja:Rofi]]<br />
[[pl:Rofi]]<br />
{{Related articles start}}<br />
{{Related|List of applications/Other#Application launchers}}<br />
{{Related articles end}}<br />
<br />
[https://github.com/DaveDavenport/rofi Rofi] is a window switcher, run dialog, ssh-launcher and [[dmenu]] replacement that started as a clone of [https://github.com/seanpringle/simpleswitcher simpleswitcher], written by [https://github.com/seanpringle Sean Pringle] and later expanded by [https://github.com/DaveDavenport Dave Davenport].<br />
<br />
== Installation ==<br />
<br />
[[Install]] the {{Pkg|rofi}} package.<br />
<br />
== Configuration ==<br />
<br />
There are currently four methods of setting configuration options:<br />
<br />
* Local configuration. Normally, depending on XDG, in {{ic|~/.config/rofi/config}}. This uses the Xresources format.<br />
* New theme format, which can have a configuration block. {{ic|~/.config/rofi/config.rasi}}<br />
* Xresources: A method of storing key values in the Xserver.<br />
* Command line options<br />
<br />
{{Note|Xresources format will be obsolete in future rofi versions}}<br />
<br />
So<br />
<br />
rofi -combi-modi window,drun,ssh -theme solarized -font "hack 10" -show combi<br />
<br />
can be expressed in a config file like this (New theme format):<br />
<br />
configuration {<br />
modi: "window,drun,ssh,combi";<br />
theme: solarized;<br />
font: "hack 10";<br />
combi-modi: "window,drun,ssh";<br />
}<br />
<br />
To get a full list of options for {{ic|config.rasi}} file run {{ic|rofi -dump-config}}. You can write the output of the command directly to your {{ic|config}} file while running {{ic|rofi -dump-config > ~/.config/rofi/config.rasi}}<br />
<br />
{{Note|i3 users be aware that putting commas in i3 config can cause issues. To bind a key to launch rofi, either use a config file or replace the commas with {{ic|#}} eg {{ic|rofi -combi-modi window#drun#ssh}}}}<br />
<br />
==Rofi as dmenu replacement==<br />
<br />
If called as dmenu (via a symlink), rofi acts like dmenu. You may want to install {{AUR|rofi-dmenu}}, which symlinks dmenu to rofi. Then programs that call dmenu from a script (like passmenu from [[pass]]) will use rofi instead of dmenu.<br />
<br />
If you prefer the look of dmenu, this approximates it:<br />
<br />
rofi -show run -modi run -location 1 -width 100 \<br />
-lines 2 -line-margin 0 -line-padding 1 \<br />
-separator-style none -font "mono 10" -columns 9 -bw 0 \<br />
-disable-history \<br />
-hide-scrollbar \<br />
-color-window "#222222, #222222, #b1b4b3" \<br />
-color-normal "#222222, #b1b4b3, #222222, #005577, #b1b4b3" \<br />
-color-active "#222222, #b1b4b3, #222222, #007763, #b1b4b3" \<br />
-color-urgent "#222222, #b1b4b3, #222222, #77003d, #b1b4b3" \<br />
-kb-row-select "Tab" -kb-row-tab ""<br />
<br />
==Execute shell commands from rofi==<br />
<br />
If you want the ability to run shell commands or use your own scripts directly from rofi with seeing the output, then ensure following:<br />
* configure the PATH variable in {{ic|~/.profile}} (instead of e.g. {{ic|~/.bashrc}}) and then logout and re-login to your window manager/desktop environment<br />
* define {{ic|-run-shell-command '{terminal} -e \\"{cmd}; read -n 1 -s"'}}. This allows you to enter the command on the inputbar followed by SHIFT+ENTER. The terminal stays open until the next keypress.<br />
<br />
This is an example with the recommended escaping sequence for i3:<br />
<br />
bindsym $mod+d exec --no-startup-id "rofi -show drun -font \\"DejaVu 9\\" -run-shell-command '{terminal} -e \\" {cmd}; read -n 1 -s\\"'"<br />
<br />
==Custom Themes==<br />
<br />
You can preview and apply themes for rofi with<br />
<br />
rofi-theme-selector<br />
<br />
Customizations may be saved to your [[X_resources|.Xresources file]] (requires the {{pkg|xorg-xrdb}} package).<br />
To apply changes reload .Xresources with {{ic|xrdb -load ~/.Xresources}}.<br />
<br />
===Contributed Themes===<br />
<br />
See the official [https://github.com/DaveDavenport/rofi-themes rofi-themes] repository for a list of custom themes.<br />
<br />
Download one of the .rasi themes and place it in {{ic|~/.config/rofi/example.rasi}}. Then load up the theme on the command line or in a config file:<br />
<br />
rofi <options> -theme example<br />
<br />
or in your configuration file<br />
<br />
rofi.theme: example</div>Rasihttps://wiki.archlinux.org/index.php?title=Rofi&diff=593670Rofi2020-01-01T12:10:13Z<p>Rasi: Add information about config.rasi and fix wrong info that mixes the 2 config formats</p>
<hr />
<div>[[Category:Application launchers]]<br />
[[ja:Rofi]]<br />
[[pl:Rofi]]<br />
{{Related articles start}}<br />
{{Related|List of applications/Other#Application launchers}}<br />
{{Related articles end}}<br />
<br />
[https://github.com/DaveDavenport/rofi Rofi] is a window switcher, run dialog, ssh-launcher and [[dmenu]] replacement that started as a clone of [https://github.com/seanpringle/simpleswitcher simpleswitcher], written by [https://github.com/seanpringle Sean Pringle] and later expanded by [https://github.com/DaveDavenport Dave Davenport].<br />
<br />
== Installation ==<br />
<br />
[[Install]] the {{Pkg|rofi}} package.<br />
<br />
== Configuration ==<br />
<br />
There are currently four methods of setting configuration options:<br />
<br />
* Local configuration. Normally, depending on XDG, in {{ic|~/.config/rofi/config}}. This uses the Xresources format.<br />
* New theme format, which can have a configuration block. {{ic|~/.config/rofi/config.rasi}}<br />
* Xresources: A method of storing key values in the Xserver.<br />
* Command line options<br />
<br />
{{Note|Xresources format will be obsolete in future rofi versions}}<br />
<br />
So<br />
<br />
rofi -combi-modi window,drun,ssh -theme solarized -font "hack 10" -show combi<br />
<br />
can be expressed in a config file like this (New theme format):<br />
<br />
configuration {<br />
modi: "window,drun,ssh,combi";<br />
theme: solarized;<br />
font: "hack 10";<br />
combi-modi: "window,drun,ssh";<br />
}<br />
<br />
To get a full list of options for config.rasi file run {{ic|rofi -dump-config}}. You can write the output of the command directly to your {{ic|config}} file while running {{ic|rofi -dump-config > ~/.config/rofi/config.rasi}}<br />
<br />
{{Note|i3 users be aware that putting commas in i3 config can cause issues. To bind a key to launch rofi, either use a config file or replace the commas with {{ic|#}} eg {{ic|rofi -combi-modi window#drun#ssh}}}}<br />
<br />
==Rofi as dmenu replacement==<br />
<br />
If called as dmenu (via a symlink), rofi acts like dmenu. You may want to install {{AUR|rofi-dmenu}}, which symlinks dmenu to rofi. Then programs that call dmenu from a script (like passmenu from [[pass]]) will use rofi instead of dmenu.<br />
<br />
If you prefer the look of dmenu, this approximates it:<br />
<br />
rofi -show run -modi run -location 1 -width 100 \<br />
-lines 2 -line-margin 0 -line-padding 1 \<br />
-separator-style none -font "mono 10" -columns 9 -bw 0 \<br />
-disable-history \<br />
-hide-scrollbar \<br />
-color-window "#222222, #222222, #b1b4b3" \<br />
-color-normal "#222222, #b1b4b3, #222222, #005577, #b1b4b3" \<br />
-color-active "#222222, #b1b4b3, #222222, #007763, #b1b4b3" \<br />
-color-urgent "#222222, #b1b4b3, #222222, #77003d, #b1b4b3" \<br />
-kb-row-select "Tab" -kb-row-tab ""<br />
<br />
==Execute shell commands from rofi==<br />
<br />
If you want the ability to run shell commands or use your own scripts directly from rofi with seeing the output, then ensure following:<br />
* configure the PATH variable in {{ic|~/.profile}} (instead of e.g. {{ic|~/.bashrc}}) and then logout and re-login to your window manager/desktop environment<br />
* define {{ic|-run-shell-command '{terminal} -e \\"{cmd}; read -n 1 -s"'}}. This allows you to enter the command on the inputbar followed by SHIFT+ENTER. The terminal stays open until the next keypress.<br />
<br />
This is an example with the recommended escaping sequence for i3:<br />
<br />
bindsym $mod+d exec --no-startup-id "rofi -show drun -font \\"DejaVu 9\\" -run-shell-command '{terminal} -e \\" {cmd}; read -n 1 -s\\"'"<br />
<br />
==Custom Themes==<br />
<br />
You can preview and apply themes for rofi with<br />
<br />
rofi-theme-selector<br />
<br />
Customizations may be saved to your [[X_resources|.Xresources file]] (requires the {{pkg|xorg-xrdb}} package).<br />
To apply changes reload .Xresources with {{ic|xrdb -load ~/.Xresources}}.<br />
<br />
===Contributed Themes===<br />
<br />
See the official [https://github.com/DaveDavenport/rofi-themes rofi-themes] repository for a list of custom themes.<br />
<br />
Download one of the .rasi themes and place it in {{ic|~/.config/rofi/example.rasi}}. Then load up the theme on the command line or in a config file:<br />
<br />
rofi <options> -theme example<br />
<br />
or in your configuration file<br />
<br />
rofi.theme: example</div>Rasihttps://wiki.archlinux.org/index.php?title=Music_Player_Daemon&diff=512502Music Player Daemon2018-03-02T15:42:01Z<p>Rasi: changed url to correct upstream url</p>
<hr />
<div>[[Category:Multimedia players]]<br />
[[de:Music Player Daemon]]<br />
[[es:Music Player Daemon]]<br />
[[fr:MPD]]<br />
[[it:Music Player Daemon]]<br />
[[ja:Music Player Daemon]]<br />
[[nl:Music Player Daemon]]<br />
[[pl:Music Player Daemon]]<br />
[[ru:Music Player Daemon]]<br />
[[sr:Music Player Daemon]]<br />
[[zh-hans:Music Player Daemon]]<br />
{{Style|Needs improvements in structure and clarify; compare to the [http://www.musicpd.org/doc/user/index.html User's manual].|section=Style comment}}<br />
<br />
{{Related articles start}}<br />
{{Related|MPD/Tips and Tricks}}<br />
{{Related|MPD/Troubleshooting}}<br />
{{Related articles end}}<br />
<br />
'''[http://www.musicpd.org/ 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 />
<br />
[[Install]] the {{Pkg|mpd}} package, or {{AUR|mpd-git}} for the development version.<br />
<br />
{{Note|An alternative implementation written in Python called [http://www.mopidy.com Mopidy] exists. It is available as {{Pkg|mopidy}} and {{AUR|mopidy-git}}. Be warned that is not a complete MPD [http://docs.mopidy.com/en/latest/ext/mpd/#limitations drop-in replacement]. The advantage of Mopidy over MPD is that it has plug-ins for playing music from cloud services like Spotify, SoundCloud, and Google Play Music. However, mopidy project is not as active and many plugins become unusable or buggy at least over time.}}<br />
<br />
== Setup ==<br />
<br />
MPD is able to run locally (per user settings), globally (settings apply to all users), and in multiple instances. The way of setting up mpd depends on the way it is intended to be used: a local configuration may prove more useful on a desktop system, for example.<br />
<br />
In order for MPD to be able to playback audio, [[ALSA]] or [[OSS]] (optionally with [[PulseAudio]]) needs to be setup and working.<br />
<br />
MPD is configured in {{ic|mpd.conf}}. The location of this file depends on how you want to run MPD (see the sections below). These are commonly used configuration options:<br />
* {{ic|pid_file}} - The file where mpd stores its process ID<br />
* {{ic|db_file}} - The music database<br />
* {{ic|state_file}} - MPD's current state is noted here<br />
* {{ic|playlist_directory}} - The folder where playlists are saved into<br />
* {{ic|music_directory}} - The folder that MPD scans for music<br />
* {{ic|sticker_file}} - The sticker database<br />
<br />
=== Global configuration ===<br />
<br />
{{Warning|Users of PulseAudio with a global 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 />
The default {{ic|/etc/mpd.conf}} keeps the setup in {{ic|/var/lib/mpd}} which is assigned to user as well as primary group ''mpd''.<br />
<br />
==== Music directory ====<br />
<br />
The music directory has to be set by parameter {{ic|music_directory}} in file {{ic|/etc/mpd.conf}}:<br />
music_directory "/path/to/music"<br />
<br />
MPD needs to have {{ic|+x}} permissions on ''all'' parent directories to the music collection and also read access to all directories containing music files. This conflicts with the default configuration of the user directory where many users store their music.<br />
<br />
While there are several solutions to this problem one of these should be most practical:<br />
* [[#Local configuration .28per user.29|run MPD as user]]<br />
* add the mpd user to your login group and grant group permission to your user directory:<br />
# gpasswd -a mpd <your login group><br />
$ chmod 710 /home/<your home dir><br />
* put your music collection to a different path (a) by moving it entirely, (b) with a bind mount or (c) with a [[Btrfs#Subvolumes|Btrfs subvolume]] (you should make this change persistent with an entry to {{ic|/etc/fstab}} ). Permissions of alternate directories can be adjusted with [[Access Control Lists]].<br />
<br />
The MPD config must contain only one music directory. 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 />
==== Start MPD ====<br />
<br />
MPD can be controlled with {{ic|mpd.service}} [[systemd#Using units|using systemd]]. The first startup can take some time as MPD will scan your music directory.<br />
<br />
Test everything by starting a client application ({{Pkg|ncmpc}} is a light and easy to use client), and play some music!<br />
<br />
===== Socket activation =====<br />
<br />
If the {{ic|mpd.socket}} unit (provided by {{Pkg|mpd}}) is enabled while {{ic|mpd.service}} is disabled, systemd will not start mpd immediately, but it will listen on the appropriate sockets. When an mpd client attempts to connect on one of those sockets, systemd will start {{ic|mpd.service}} and transparently hand over control of those ports to the mpd process.<br />
<br />
If you prefer to listen on different UNIX sockets or network ports (even multiple sockets of each type), or if you prefer not to listen on network ports at all, [[edit]] the {{ic|mpd.socket}} unit appropriately '''and''' modify {{ic|/etc/mpd.conf}} to match the configuration (see {{man|5|mpd.conf}} for details).<br />
<br />
==== Configure audio ====<br />
<br />
Users of [[ALSA]] will want to have the following device definition; replace {{ic|My Sound Card}} with the name of a sound card or pcm ({{ic|aplay --list-pcms}}).<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 />
The {{ic|mixer_type "software"}} option tells 'mpd' to use its own independent software volume control.<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 />
User will also have to edit {{ic|/etc/pulse/client.conf}} and change the default ''autospawn = no'' line to ''autospawn = yes'' in order to allow the mpd user to use pulseaudio. It will be necessary to restart pulseaudio after making this modification.<br />
<br />
==== Changing user ====<br />
<br />
Changing the group that MPD runs as may result in errors like {{ic|output: Failed to open "My ALSA Device"}}, {{ic|[alsa]: Failed to open ALSA device "default": No such file or directory}} or {{ic|player_thread: problems opening audio device while playing "Song Name.mp3"}}.<br />
<br />
This is because the MPD users need to be part of the ''audio'' group to access sound devices under {{Ic|/dev/snd/}}. To fix it add user make the MPD user part of the ''audio'' group:<br />
# gpasswd -a '''mpd''' audio<br />
<br />
==== Timeline of MPD startup ====<br />
<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 />
# Since MPD is started as root by systemd, 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 />
<br />
MPD can be configured per user (rather than the typical method of configuring MPD globally). Running MPD as a normal user has the benefits of:<br />
<br />
* A single directory {{ic|~/.config/mpd/}} (or any other directory under {{ic|$HOME}}) that will contain all the MPD configuration files.<br />
* Easier to avoid unforeseen read/write permission errors.<br />
<br />
Good practice is to create a single directory for the required files and playlists. It can be any directory for which you have read and write access, e.g. {{ic|~/.config/mpd/}} or {{ic|~/.mpd/}}. This section assumes it is {{ic|~/.config/mpd/}}, which corresponds to the default value of {{ic|$XDG_CONFIG_HOME}} (part of [http://standards.freedesktop.org/basedir-spec/basedir-spec-latest.html XDG Base Directory Specification]).<br />
<br />
MPD searches for a config file in {{ic|$XDG_CONFIG_HOME/mpd/mpd.conf}} and then {{ic|~/.mpdconf}}. It is also possible to pass other path as command line argument.<br />
<br />
Copy the example configuration file to desired location, for example:<br />
<br />
$ mkdir -p ~/.config/mpd<br />
$ cp /usr/share/doc/mpd/mpdconf.example ~/.config/mpd/mpd.conf<br />
<br />
Edit {{ic|~/.config/mpd/mpd.conf}} and specify the required files:<br />
<br />
{{hc|~/.config/mpd/mpd.conf|<br />
# Required files<br />
db_file "~/.config/mpd/database"<br />
log_file "~/.config/mpd/log"<br />
<br />
# Optional<br />
music_directory "~/Music"<br />
playlist_directory "~/.config/mpd/playlists"<br />
pid_file "~/.config/mpd/pid"<br />
state_file "~/.config/mpd/state"<br />
sticker_file "~/.config/mpd/sticker.sql"<br />
}}<br />
<br />
Create the playlist directory as configured above:<br />
<br />
$ mkdir ~/.config/mpd/playlists<br />
<br />
When the paths of required files are configured, MPD can be started. To specify custom location of the configuration file:<br />
<br />
$ mpd ''config_file''<br />
<br />
==== Autostart on tty login ====<br />
<br />
To start MPD on login add the following to {{ic|~/.profile}} (or another [[Autostarting#Shells|autostart file]]):<br />
<br />
# MPD daemon start (if no other user instance exists)<br />
[ ! -s ~/.config/mpd/pid ] && mpd<br />
<br />
==== Autostart in X ====<br />
<br />
If you use a [[desktop environment]], place the following file in {{ic|~/.config/autostart/}}:<br />
{{hc|~/.config/autostart/mpd.desktop|<nowiki><br />
[Desktop Entry]<br />
Encoding=UTF-8<br />
Type=Application<br />
Name=Music Player Daemon<br />
Comment=Server for playing audio files<br />
Exec=mpd<br />
StartupNotify=false<br />
Terminal=false<br />
Hidden=false<br />
X-GNOME-Autostart-enabled=false<br />
</nowiki>}}<br />
<br />
If you do not use a DE, place the line from [[#Autostart on tty login]] in your [[Autostarting#Graphical|autostart file]].<br />
<br />
==== Autostart with systemd ====<br />
<br />
The {{Pkg|mpd}} package provides a [[systemd/User|user service]] file. The configuration file is expected to exist either in {{ic|~/.mpdconf}} or {{ic|~/.config/mpd/mpd.conf}}; see [[systemd#Editing provided units]] if you would like to use a different path. The service starts the process as user, there is no need to change permission nor use the {{ic|user}} and {{ic|group}} variables in the MPD configuration file.<br />
<br />
All you have to do is [[start/enable]] the user unit {{ic|mpd.service}} (i.e. with the {{ic|--user}} flag).<br />
<br />
{{Note|{{Pkg|mpd}} also provides a system service file. The process is started as root and reads the [[#Global configuration]] from {{ic|/etc/mpd.conf}} rather than the [[#Local configuration (per user)]].}}<br />
<br />
==== Scripted configuration ====<br />
<br />
You can use a [https://53280.de/dl/mpdsetup.sh script] to create the proper directory structure, configuration files and prompt for the location of the user's Music directory.<br />
<br />
==== Scripted configuration for bit perfect playback ====<br />
<br />
You can use a [http://lacocina.nl/audiophile-mpd bash script] to also create a valid mpd configuration file which focusses on bit perfect audio playback. That is playback without any resampling or format conversion. It does this by setting audio output parameters to use a direct alsa hwardware address (like `hw:0,0`). The script detects and lists which playback interfaces alsa supports. When one interface is found it uses that one, if multiple are found it prompts the user which one to use. When not specified on the command line, it auto configures things like the music_directory and mpd's home directory by using freedesktop.org XDG configuration.<br />
<br />
=== Multi-mpd setup ===<br />
<br />
==== 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 />
==== Satellite setup ====<br />
<br />
The method above works, but at least in theory could lead to issues with the database, when both mpd instances try to write to the same database file. MPD has a [http://www.musicpd.org/doc/user/advanced_config.html#satellite satellite mode] where one instance can receive the database from an already running mpd instance.<br />
<br />
in your config-icecast add this, where host and port reflect your primary mpd server.<br />
<br />
{{bc|<br />
database {<br />
plugin "proxy"<br />
host "localhost"<br />
port "6600"<br />
}<br />
}}<br />
<br />
== Clients ==<br />
<br />
A separate client is needed to control mpd. See a long list of clients at the [https://www.musicpd.org/clients/ mpd website]. Popular options are:<br />
<br />
=== Console ===<br />
<br />
*{{App|mpc|Command line user interface for MPD server|http://www.musicpd.org/clients/mpc/|{{Pkg|mpc}}}}<br />
*{{App|ncmpc|Ncurses client for mpd|http://www.musicpd.org/clients/ncmpc/|{{Pkg|ncmpc}}}}<br />
*{{App|[[ncmpcpp]]|Almost exact clone of ncmpc with some new features written in C++ (tag editor, search engine)|http://ncmpcpp.rybczak.net/|{{Pkg|ncmpcpp}}}}<br />
*{{App|pms|Highly configurable and accessible ncurses client|https://ambientsound.github.io/pms/|{{AUR|pmus-git}}}}<br />
*{{App|vimpc|Ncurses based MPD client with vi-like key bindings|https://github.com/boysetsfrog/vimpc|{{AUR|vimpc-git}}}}<br />
*{{App|vimus|MPD client with vim-like key bindings, written in Haskell|https://github.com/vimus/vimus|{{AUR|vimus-git}}{{Broken package link|package not found}}}}<br />
<br />
=== Graphical ===<br />
<br />
*{{App|Ario|Very feature-rich GTK2 GUI client for mpd, inspired by Rhythmbox|http://ario-player.sourceforge.net/|{{Pkg|ario}}}}<br />
*{{App|QmpdClient|GUI client written with Qt 4.x|http://bitcheese.net/wiki/QMPDClient|{{Pkg|qmpdclient}}}}<br />
*{{App|Sonata|Elegant Python GTK+ client|http://www.nongnu.org/sonata/|{{Pkg|sonata}}}}<br />
*{{App|gmpc|GTK2 frontend for Music Player Daemon. It is designed to be lightweight and easy to use, while providing full access to all of MPD's features. Users are presented with several different methods to browse through their music. It can be extended by plugins, of which many are available.|http://gmpclient.org/|{{Pkg|gmpc}}}}<br />
*{{App|Cantata|High-feature, Qt4, Qt5 or KDE client for MPD with very configurable interface|https://github.com/CDrummond/cantata|{{Pkg|cantata}}}}<br />
*{{App|Xfmpc|A graphical GTK+ MPD client focusing on low footprint|http://goodies.xfce.org/projects/applications/xfmpc|{{Pkg|xfmpc}}}}<br />
*{{App|pymp'd|A GTK+ front end client for the music playing daemon MPD|http://pympd.sourceforge.net|{{Pkg|pympd}}}}<br />
*{{App|Quimup|A client for the music player daemon (MPD) written in C++ and QT3 / since v. 1.4.0 the code was migrated to Qt5 for MPD 0.17.0 and above|http://goodies.xfce.org/projects/applications/xfmpc|{{Aur|quimup}}}}<br />
*{{App|SkyMPC|A simple MPD client, powered by Qt5|https://github.com/soramimi/SkyMPC|{{Aur|skympc-git}}}}<br />
<br />
== See also ==<br />
<br />
* [http://forum.musicpd.org/ MPD Forum]<br />
* [http://www.musicpd.org/doc/user/ MPD User Manual]<br />
* [[Wikipedia:Music Player Daemon|Wikipedia article]]</div>Rasihttps://wiki.archlinux.org/index.php?title=Music_Player_Daemon&diff=350951Music Player Daemon2014-12-20T01:47:23Z<p>Rasi: /* Multi-mpd setup */</p>
<hr />
<div>[[Category:Player]]<br />
[[de:Music Player Daemon]]<br />
[[es:Music Player Daemon]]<br />
[[fr:MPD]]<br />
[[it:Music Player Daemon]]<br />
[[ja: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 />
{{Related articles start}}<br />
{{Related|MPD/Tips and Tricks}}<br />
{{Related|MPD/Troubleshooting}}<br />
{{Related articles end}}<br />
'''[http://www.musicpd.org/ 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 />
<br />
The latest stable version of {{Pkg|mpd}} is available in the [[official repositories]].<br />
<br />
Should users wish to run an experimental version, the [[AUR]] offers several from which to choose. For example, {{AUR|mpd-git}}.<br />
{{Note|An alternative plug-in based implementation called [http://www.mopidy.com Mopidy] exists. It is available in the AUR as {{AUR|mopidy}} and {{AUR|mopidy-git}}. Be warned that is not a complete MPD [http://docs.mopidy.com/en/latest/ext/mpd/#limitations drop-in relacement].}}<br />
<br />
== Setup ==<br />
<br />
MPD is able to run locally (per user settings), globally (settings apply to all users), and in multiple instances. The way of setting up mpd depends on the way it is intended to be used: a local configuration may prove more useful on a desktop system, for example.<br />
<br />
In order for MPD to be able to play back audio, [[ALSA]] or [[OSS]] (optionally with [[PulseAudio]]) needs to be setup and working.<br />
<br />
MPD is configured in {{ic|mpd.conf}}. The location of this file depends on how you want to run MPD (see the sections below). These are commonly used configuration options:<br />
* {{ic|pid_file}} - The file where mpd stores its process ID<br />
* {{ic|db_file}} - The music database<br />
* {{ic|state_file}} - MPD's current state is noted here<br />
* {{ic|playlist_directory}} - The folder where playlists are saved into<br />
* {{ic|music_directory}} - The folder that MPD scans for music<br />
* {{ic|sticker_file}} - The sticker database<br />
<br />
{{Note|The files must already exist (the path is specified in the configuration file) with proper permissions, otherwise MPD will fail to start.}}<br />
<br />
=== Global configuration ===<br />
<br />
{{Warning|Users of PulseAudio with a global 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 />
The default {{ic|/etc/mpd.conf}} keeps the setup in {{ic|/var/lib/mpd}} and uses ''mpd'' as default user. However, {{ic|/var/lib/mpd}} is owned by ''root'' by default, we need to change this so ''mpd'' can write here:<br />
# chown -R mpd /var/lib/mpd<br />
<br />
Edit {{ic|/etc/mpd.conf}} and add a {{ic|music_directory}} line with the path to your music directory:<br />
music_directory /path/to/music<br />
<br />
==== Music directory ====<br />
<br />
MPD needs to have {{ic|+x}} permissions on ''all'' parent directories to the music collection. <br />
<br />
If the music directory is located outside of {{ic|/var/lib/mpd}}, you will most likely need to remount the music directory under a directory that the MPD user (''mpd'' by default) has access to:<br />
# mkdir /var/lib/mpd/music<br />
# echo "/path/to/music/dir /var/lib/mpd/music none bind" >> /etc/fstab<br />
# mount -a<br />
Also see [https://bbs.archlinux.org/viewtopic.php?id=86449 this 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 /path/to/music/dir /var/lib/mpd/music/<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 />
==== Start MPD ====<br />
<br />
MPD can be controlled with {{ic|mpd.service}} [[systemd#Using units|using systemd]]. The first startup can take some time as MPD will scan your music directory.<br />
<br />
Test everything by starting a client application ({{Pkg|ncmpc}} is a light and easy to use client), and play some music!<br />
<br />
===== Socket activation =====<br />
<br />
If the following {{ic|mpd.socket}} file is enabled while {{ic|mpd.service}} (provided by {{Pkg|mpd}}) is disabled, systemd will not start mpd immediately, but it will listen on the appropriate sockets. When an mpd client attempts to connect on one of those sockets, systemd will start {{ic|mpd.service}} and transparently hand over control of those ports to the mpd process.<br />
<br />
If you prefer to listen on different UNIX sockets or network ports (even multiple sockets of each type), or if you prefer not to listen on network ports at all, you should add/edit/remove the appropriate {{ic|1="ListenStream="}} lines in the {{ic|[Socket]}} section of {{ic|mpd.socket}} '''and''' modify the appropriate lines {{ic|/etc/mpd.conf}} (see {{ic|man 5 mpd.conf}} for details).<br />
<br />
If you use different (even multiple) network or local sockets, or prefer not to use network sockets at all, simply add, change, or remove lines beginning with {{ic|1="ListenStream="}} in the {{ic|[Socket]}} section.<br />
<br />
{{hc|/etc/systemd/system/mpd.socket|<nowiki><br />
[Unit]<br />
Description=Music Player Daemon Sockets<br />
<br />
[Socket]<br />
ListenStream=/var/run/mpd/socket<br />
ListenStream=6600<br />
<br />
[Install]<br />
WantedBy=sockets.target<br />
</nowiki>}}<br />
<br />
==== Configure audio ====<br />
<br />
To change the volume for mpd independent from other programs, uncomment or add this switch in mpd.conf:<br />
{{hc|/etc/mpd.conf|<br />
mixer_type "software"<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 />
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 />
PulseAudio supports multiple advanced operations, e.g. transferring the audio to a different machine. For advanced configuration with MPD see [http://mpd.wikia.com/wiki/PulseAudio Music Player Daemon Community Wiki].<br />
<br />
==== Changing user ====<br />
<br />
Changing the group that MPD runs as may result in errors like {{ic|output: Failed to open "My ALSA Device"}}, {{ic|[alsa]: Failed to open ALSA device "default": No such file or directory}} or {{ic|player_thread: problems opening audio device while playing "Song Name.mp3"}}.<br />
<br />
This is because the MPD users need to be part of the ''audio'' group to access sound devices under {{Ic|/dev/snd/}}. To fix it add user make the MPD user part of the ''audio'' group:<br />
# gpasswd -a '''mpd''' audio<br />
<br />
==== Timeline of MPD startup ====<br />
<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 />
# Since MPD is started as root by systemd, 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 />
<br />
MPD can be configured per user (rather than the typical method of configuring MPD globally). Running MPD as a normal user has the benefits of:<br />
<br />
* A single directory {{ic|~/.config/mpd/}} (or any other directory under {{ic|$HOME}}) that will contain all the MPD configuration files.<br />
* Easier to avoid unforeseen read/write permission errors.<br />
<br />
Good practice is to create a single directory for the required files and playlists. It can be any directory for which you have read and write access, e.g. {{ic|~/.config/mpd/}} or {{ic|~/.mpd/}}. This section assumes it is {{ic|~/.config/mpd/}}, which corresponds to the default value of {{ic|$XDG_CONFIG_HOME}} (part of [http://standards.freedesktop.org/basedir-spec/basedir-spec-latest.html XDG Base Directory Specification]).<br />
<br />
MPD searches for a config file in {{ic|$XDG_CONFIG_HOME/mpd/mpd.conf}} and then {{ic|~/.mpdconf}}. It is also possible to pass other path as command line argument.<br />
<br />
Copy the example configuration file to desired location, for example:<br />
<br />
$ cp /usr/share/doc/mpd/mpdconf.example ~/.config/mpd/mpd.conf<br />
<br />
Edit {{ic|~/.config/mpd/mpd.conf}} and specify the required files:<br />
<br />
{{hc|~/.config/mpd/mpd.conf|<br />
# Required files<br />
db_file "~/.config/mpd/database"<br />
log_file "~/.config/mpd/log"<br />
<br />
# Optional<br />
music_directory "~/Music"<br />
playlist_directory "~/.config/mpd/playlists"<br />
pid_file "~/.config/mpd/pid"<br />
state_file "~/.config/mpd/state"<br />
sticker_file "~/.config/mpd/sticker.sql"<br />
}}<br />
<br />
Create all the files and directories as configured above:<br />
<br />
$ mkdir ~/.config/mpd/playlists<br />
$ touch ~/.config/mpd/{database,log,pid,state,sticker.sql}<br />
<br />
When the paths of required files are configured, MPD can be started. To specify custom location of the configuration file:<br />
<br />
$ mpd ''config_file''<br />
<br />
==== Autostart on tty login ====<br />
<br />
To start MPD on login add the following to {{ic|~/.profile}} (or another [[Autostarting#Shells|autostart file]]):<br />
<br />
# MPD daemon start (if no other user instance exists)<br />
[ ! -s ~/.config/mpd/pid ] && mpd<br />
<br />
==== Autostart in X ====<br />
<br />
If you use a [[Desktop environment|desktop environment]], place the following file in {{ic|~/.config/autostart/}}:<br />
{{hc|~/.config/autostart/mpd.desktop|<nowiki><br />
[Desktop Entry]<br />
Encoding=UTF-8<br />
Type=Application<br />
Name=Music Player Daemon<br />
Comment=Server for playing audio files<br />
Exec=mpd<br />
StartupNotify=false<br />
Terminal=false<br />
Hidden=false<br />
X-GNOME-Autostart-enabled=false<br />
</nowiki>}}<br />
<br />
If you do not use a DE, place the line from [[#Autostart on tty login]] in your [[Autostarting#Graphical|autostart file]].<br />
<br />
==== Autostart with systemd ====<br />
<br />
{{Note|It is assumed that you already have systemd user-session manager running. See the [[systemd/User]] page for details.}}<br />
<br />
The package {{Pkg|mpd}} provides user service file in {{ic|/usr/lib/systemd/user/mpd.service}}. The configuration file is expected to exist either in {{ic|~/.mpdconf}} or {{ic|~/.config/mpd/mpd.conf}}, see [[systemd#Editing provided unit files]] if you would like to use different path. The process is not started as root, so you should not use the {{ic|user}} and {{ic|group}} variables in the MPD configuration file, the process already has user permissions and therefore it is not necessary to change them further.<br />
<br />
All you have to do is enable and start the {{ic|mpd}} [[systemd/User#User Services|user service]].<br />
<br />
{{Note|<br />
* {{Pkg|mpd}} provides also system service file in {{ic|/usr/lib/systemd/system/mpd.service}}, but as the process is started as root, it does not read the user configuration file and falls back to {{ic|/etc/mpd.conf}}. [[#Global configuration|Global configuration]] is described in other section.<br />
* Make sure to disable every other method of starting mpd you used before.<br />
}}<br />
<br />
==== Scripted configuration ====<br />
<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://dl.53280.de/mpdsetup.sh here].<br />
<br />
=== Multi-mpd setup ===<br />
<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 />
<br />
'''Better solution: Satellite Setup'''<br />
<br />
The method above works, but at least in theory could lead to issues with the database, when both mpd instances try to write to the same database file.<br />
MPD has a satellite mode where one instance can receive the database from an already running mpd instance.<br />
<br />
in your config-icecast add this, where host and port reflect your primary mpd server.<br />
<br />
database {<br />
plugin "proxy"<br />
host "localhost"<br />
port "6600"<br />
}<br />
<br />
== Clients ==<br />
<br />
A separate client is needed to control mpd. See a long list of clients at the [http://mpd.wikia.com/wiki/Clients mpd wiki]. Popular options are:<br />
<br />
=== Console ===<br />
<br />
*{{App|mpc|Command line user interface for MPD server|http://www.musicpd.org/clients/mpc/|{{Pkg|mpc}}}}<br />
*{{App|ncmpc|Ncurses client for mpd|http://www.musicpd.org/clients/ncmpc/|{{Pkg|ncmpc}}}}<br />
*{{App|[[ncmpcpp]]|Almost exact clone of ncmpc with some new features written in C++ (tag editor, search engine)|http://ncmpcpp.rybczak.net/|{{Pkg|ncmpcpp}}}}<br />
*{{App|pms|Highly configurable and accessible ncurses client|http://pms.sourceforge.net/|{{AUR|pmus}}}}<br />
*{{App|vimpc|Ncurses based MPD client with vi-like key bindings|http://sourceforge.net/projects/vimpc/|{{AUR|vimpc}}}}<br />
<br />
=== Graphical ===<br />
<br />
*{{App|Ario|Very feature-rich GTK2 GUI client for mpd, inspired by Rhythmbox|http://ario-player.sourceforge.net/|{{Pkg|ario}}}}<br />
*{{App|QmpdClient|GUI client written with Qt 4.x|http://bitcheese.net/wiki/QMPDClient|{{Pkg|qmpdclient}}}}<br />
*{{App|Sonata|Elegant Python GTK+ client|http://sonata.berlios.de/|{{Pkg|sonata}}}}<br />
*{{App|gmpc|GTK2 frontend for Music Player Daemon. It is designed to be lightweight and easy to use, while providing full access to all of MPD's features. Users are presented with several different methods to browse through their music. It can be extended by plugins, of which many are available.|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 />
*{{App|Cantata|High-feature, Qt4, Qt5 or KDE4 client for MPD with very configurable interface|https://code.google.com/p/cantata/|{{Pkg|cantata}}}}<br />
<br />
=== Web ===<br />
<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 also ==<br />
<br />
* [http://forum.musicpd.org/ MPD Forum]<br />
* [http://www.musicpd.org/doc/user/ MPD User Manual]<br />
* [[Wikipedia:Music Player Daemon|Wikipedia article]]</div>Rasihttps://wiki.archlinux.org/index.php?title=Music_Player_Daemon&diff=294152Music Player Daemon2014-01-23T17:12:58Z<p>Rasi: /* Scripted configuration */</p>
<hr />
<div>[[Category:Player]]<br />
[[de:Music Player Daemon]]<br />
[[es:Music Player Daemon]]<br />
[[fr:MPD]]<br />
[[it:Music Player Daemon]]<br />
[[ja: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 />
{{Related articles start}}<br />
{{Related|MPD/Tips and Tricks}}<br />
{{Related|MPD/Troubleshooting}}<br />
{{Related articles end}}<br />
'''[http://www.musicpd.org/ 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 />
<br />
The latest stable version of {{Pkg|mpd}} is available in the [[official repositories]].<br />
<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 />
<br />
MPD is able to run locally (per user settings), globally (settings apply to all users), and in multiple instances. The way of setting up mpd depends on the way it is intended to be used: a local configuration may prove more useful on a desktop system, for example.<br />
<br />
In order for MPD to be able to play back audio, [[ALSA]] or [[OSS]] (optionally with [[PulseAudio]]) needs to be setup and working.<br />
<br />
MPD is configured in {{ic|mpd.conf}}. The location of this file depends on how you want to run MPD (see the sections below). These are commonly used configuration options:<br />
* {{ic|pid_file}} - The file where mpd stores its process ID<br />
* {{ic|db_file}} - The music database<br />
* {{ic|state_file}} - MPD's current state is noted here<br />
* {{ic|playlist_directory}} - The folder where playlists are saved into<br />
* {{ic|music_directory}} - The folder that MPD scans for music<br />
* {{ic|sticker_file}} - The sticker database<br />
<br />
{{Note|The files must already exist (the path is specified in the configuration file) with proper permissions, otherwise MPD will fail to start.}}<br />
<br />
=== Global configuration ===<br />
<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 />
The default {{ic|/etc/mpd.conf}} keeps the setup in {{ic|/var/lib/mpd}} and uses ''mpd'' as default user. However, {{ic|/var/lib/mpd}} is owned by ''root'' by default, we need to change this so ''mpd'' can write here:<br />
# chown -R mpd /var/lib/mpd<br />
<br />
Edit {{ic|/etc/mpd.conf}} and add a {{ic|music_directory}} line with the path to your music directory:<br />
music_directory /path/to/music<br />
<br />
==== Music directory ====<br />
<br />
MPD needs to have {{ic|+x}} permissions on ''all'' parent directories to the music collection. <br />
<br />
If the music directory is located outside of {{ic|/var/lib/mpd}}, you will most likely need to remount the music directory under a directory that the MPD user (''mpd'' by default) has access to:<br />
# mkdir /var/lib/mpd/music<br />
# echo "/path/to/music/dir /var/lib/mpd/music none bind" >> /etc/fstab<br />
# mount -a<br />
Also see [https://bbs.archlinux.org/viewtopic.php?id=86449 this 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 /path/to/music/dir /var/lib/mpd/music/<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 />
==== Start MPD ====<br />
<br />
MPD can be controlled with {{ic|mpd.service}} [[systemd#Using units|using systemd]]. The first startup can take some time as MPD will scan your music directory.<br />
<br />
Test everything by starting a client application ({{Pkg|ncmpc}} is a light and easy to use client), and play some music!<br />
<br />
==== Configure audio ====<br />
<br />
To change the volume for mpd independent from other programs, uncomment or add this switch in mpd.conf:<br />
{{hc|/etc/mpd.conf|<br />
mixer_type "software"<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 />
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 />
PulseAudio supports multiple advanced operations, e.g. transferring the audio to a different machine. For advanced configuration with MPD see [http://mpd.wikia.com/wiki/PulseAudio Music Player Daemon Community Wiki].<br />
<br />
==== Changing user ====<br />
<br />
Changing the group that MPD runs as may result in errors like {{ic|output: Failed to open "My ALSA Device"}}, {{ic|[alsa]: Failed to open ALSA device "default": No such file or directory}} or {{ic|player_thread: problems opening audio device while playing "Song Name.mp3"}}.<br />
<br />
This is because the MPD users need to be part of the ''audio'' group to access sound devices under {{Ic|/dev/snd/}}. To fix it add user make the MPD user part of the ''audio'' group:<br />
# gpasswd -a '''mpd''' audio<br />
<br />
==== Timeline of MPD startup ====<br />
<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 />
# Since MPD is started as root by systemd, 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 />
<br />
MPD can be configured per user (rather than the typical method of configuring MPD globally). Running MPD as a normal user has the benefits of:<br />
<br />
* A single directory {{ic|~/.config/mpd/}} (or any other directory under {{ic|$HOME}}) that will contain all the MPD configuration files.<br />
* Easier to avoid unforeseen read/write permission errors.<br />
<br />
Good practice is to create a single directory for the required files and playlists. It can be any directory for which you have read and write access, e.g. {{ic|~/.config/mpd/}} or {{ic|~/.mpd/}}. This section assumes it is {{ic|~/.config/mpd/}}, which corresponds to the default value of {{ic|$XDG_CONFIG_HOME}} (part of [http://standards.freedesktop.org/basedir-spec/basedir-spec-latest.html XDG Base Directory Specification]).<br />
<br />
MPD searches for a config file in {{ic|$XDG_CONFIG_HOME/mpd/mpd.conf}} and then {{ic|~/.mpdconf}}. It is also possible to pass other path as command line argument.<br />
<br />
Copy the example configuration file to desired location, for example:<br />
<br />
$ cp /usr/share/doc/mpd/mpdconf.example ~/.config/mpd/mpd.conf<br />
<br />
Edit {{ic|~/.config/mpd/mpd.conf}} and specify the required files:<br />
<br />
{{hc|~/.config/mpd/mpd.conf|<br />
# Required files<br />
db_file "~/.config/mpd/database"<br />
log_file "~/.config/mpd/log"<br />
<br />
# Optional<br />
music_directory "~/music"<br />
playlist_directory "~/.config/mpd/playlists"<br />
pid_file "~/.config/mpd/pid"<br />
state_file "~/.config/mpd/state"<br />
sticker_file "~/.config/mpd/sticker.sql"<br />
}}<br />
<br />
Create all the files and directories as configured above:<br />
<br />
$ mkdir ~/.config/mpd/playlists<br />
$ touch ~/.config/mpd/{database,log,pid,state,sticker.sql}<br />
<br />
When the paths of required files are configured, MPD can be started. To specify custom location of the configuration file:<br />
<br />
$ mpd ''config_file''<br />
<br />
==== Autostart on tty login ====<br />
<br />
To start MPD on login add the following to {{ic|~/.profile}} (or another [[Autostarting#Shells|autostart file]]):<br />
<br />
# MPD daemon start (if no other user instance exists)<br />
[ ! -s ~/.config/mpd/pid ] && mpd<br />
<br />
==== Autostart in X ====<br />
<br />
If you use a [[Desktop Environment|desktop environment]], place the following file in {{ic|~/.config/autostart/}}:<br />
{{hc|~/.config/autostart/mpd.desktop|<nowiki><br />
[Desktop Entry]<br />
Encoding=UTF-8<br />
Type=Application<br />
Name=Music Player Daemon<br />
Comment=Server for playing audio files<br />
Exec=mpd<br />
StartupNotify=false<br />
Terminal=false<br />
Hidden=false<br />
X-GNOME-Autostart-enabled=false<br />
</nowiki>}}<br />
<br />
If you do not use a DE, place the line from [[#Autostart on tty login]] in your [[Autostarting#Graphical|autostart file]].<br />
<br />
==== Autostart with systemd ====<br />
<br />
{{Note|It is assumed that you already have systemd user-session manager running. See the [[systemd/User]] page for details.}}<br />
<br />
The package {{Pkg|mpd}} provides user service file in {{ic|/usr/lib/systemd/user/mpd.service}}. The configuration file is expected to exist either in {{ic|~/.mpdconf}} or {{ic|~/.config/mpd/mpd.conf}}, see [[systemd#Editing provided unit files]] if you would like to use different path. The process is not started as root, so you should not use the {{ic|user}} and {{ic|group}} variables in the MPD configuration file, the process already has user permissions and therefore it is not necessary to change them further.<br />
<br />
All you have to do is enable and start the {{ic|mpd}} [[systemd/User#User Services|user service]].<br />
<br />
{{Note|<br />
* {{Pkg|mpd}} provides also system service file in {{ic|/usr/lib/systemd/system/mpd.service}}, but as the process is started as root, it does not read the user configuration file and falls back to {{ic|/etc/mpd.conf}}. [[#Global configuration|Global configuration]] is described in other section.<br />
* Make sure to disable every other method of starting mpd you used before.<br />
}}<br />
<br />
==== Scripted configuration ====<br />
<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://dl.53280.de/mpdsetup.sh here].<br />
<br />
=== Multi-mpd setup ===<br />
<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 />
<br />
A separate client is needed to control mpd. See a long list of clients at the [http://mpd.wikia.com/wiki/Clients mpd wiki]. Popular options are:<br />
<br />
=== Console ===<br />
<br />
*{{App|mpc|Simple KISS client. All basic functionality available|http://mpd.wikia.com/wiki/Client:Mpc|{{Pkg|mpc}}}}<br />
*{{App|ncmpc|Ncurses client for mpd|http://mpd.wikia.com/wiki/Client:Ncmpc|{{Pkg|ncmpc}}}}<br />
*{{App|[[ncmpcpp]]|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 />
*{{App|vimpc|Ncurses based MPD client with vi-like key bindings|http://sourceforge.net/projects/vimpc/|{{AUR|vimpc}}}}<br />
<br />
=== Graphical ===<br />
<br />
*{{App|Ario|Very feature-rich GTK2 GUI client for mpd, inspired by Rhythmbox|http://ario-player.sourceforge.net/|{{Pkg|ario}}}}<br />
*{{App|QmpdClient|GUI client written with Qt 4.x|http://bitcheese.net/wiki/QMPDClient|{{Pkg|qmpdclient}}}}<br />
*{{App|Sonata|Elegant Python GTK+ client|http://sonata.berlios.de/|{{Pkg|sonata}}}}<br />
*{{App|gmpc|GTK2 frontend for Music Player Daemon. It is designed to be lightweight and easy to use, while providing full access to all of MPD's features. Users are presented with several different methods to browse through their music. It can be extended by plugins, of which many are available.|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 />
*{{App|Cantata|High-feature, Qt4/KDE4 client for MPD with very configurable interface|https://code.google.com/p/cantata/|{{AUR|cantata-qt}}}}<br />
<br />
=== Web ===<br />
<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 also ==<br />
<br />
* [http://forum.musicpd.org/ MPD Forum]<br />
* [http://www.musicpd.org/doc/user/ MPD User Manual]<br />
* [[Wikipedia:Music Player Daemon|Wikipedia article]]</div>Rasihttps://wiki.archlinux.org/index.php?title=Pacaur&diff=253229Pacaur2013-04-07T13:29:00Z<p>Rasi: /* Sudo configuration */</p>
<hr />
<div>[[Category:Package management]]<br />
[[Category:Arch User Repository]]<br />
{{Article summary start}}<br />
{{Article summary text|How to install and use pacaur.}}<br />
{{Article summary heading|Related}}<br />
{{Article summary wiki|AUR Helpers}}<br />
{{Article summary end}}<br />
<br />
'''Pacaur''' is an [[Arch User Repository]] (AUR) [[AUR helpers|helper]] aiming at speed and simplicity, designed to minimize user prompt interaction and to use an uncluttered interface. It is written in Bash and built upon the well designed cower and expac C backends.<br />
<br />
{{note|Pacaur is targeted at '''advanced users''' who want some degree of automation for repetitive tasks. As such, the user is expected to be familiar with the [[Arch User Repository|manual build process]]. }}<br />
<br />
==Philosophy==<br />
<br />
Pacaur's main feature revolves around a ''fast workflow'' idea, that is, spending as little time as possible interacting with package management prompts. Speed, simplicity and the need for an uncluttered interface were also taken into consideration.<br />
<br />
Pacaur is:<br />
<br />
Fast<br />
* It minimizes user interaction.<br />
* It has very good performance with a small memory footprint.<br />
* It retrieve and edit all PKGBUILDs, and checks and solves all conflicts before building anything.<br />
<br />
<br />
Simple<br />
* It does not add a lot of features, but simply extends pacman to manage the AUR.<br />
* It does not reinvent the wheel, but is built upon existing tools (cower, expac, sudo).<br />
* It is a small bash script using tiny C libraries.<br />
* It is based on the libalpm C interface directly maintained by a pacman developer.<br />
<br />
<br />
Powerful<br />
* It can be used as a separate AUR frontend, or a single tool to manage official and AUR packages.<br />
* Its search function provides regex support (through cower).<br />
* It provides binary and AUR package names completion.<br />
* It passes arguments to pacman when appropriate.<br />
* It shows current and available versions when checking for updates.<br />
<br />
<br />
Secure<br />
* It does not source PKGBUILDs unecessarily.<br />
* It detects and warns of possible malicious pseudocode in PKGBUILDs.<br />
* It disposes of an additional full secured mode for paranoid people.<br />
<br />
==Installation==<br />
<!-- Please don't add direct commands to install pacaur. All users should be familiar with the build process. --><br />
<br />
The following binary dependencies need to be installed:<br />
* {{pkg|sudo}} [core]<br />
* {{pkg|expac}} [community]<br />
<br />
You can then install {{AUR|cower}} as a dependency, and then {{AUR|pacaur}} itself. Both of those packages are available in the AUR.<br />
<br />
==Usage==<br />
<br />
Invoking pacaur consists of supplying an operation, any applicable options, and usually one or more targets.<br />
<br />
<pre><br />
usage: pacaur <operation> [options] [package(s)]<br />
operations:<br />
pacman extension<br />
-S, -Q extend pacman operations to the AUR<br />
AUR only<br />
-s, --search search AUR repository for matching strings<br />
-i, --info view package information -- pass twice for details<br />
-d, --download download target(s) -- pass twice to download AUR dependencies<br />
-m, --makepkg download and make target(s)<br />
-y, --sync download, make and install target(s)<br />
-k, --check check for AUR update(s)<br />
-u, --update update AUR package(s)<br />
general<br />
-v, --version display version information<br />
-h, --help display help information<br />
--fixbackend quickly rebuild backend<br />
<br />
options:<br />
pacman extension - can be used with the -S, -Ss, -Si, -Sii, -Sw, -Su, -Qu, -Sc, -Scc operations<br />
-a, --aur only search, install or clean packages from the AUR<br />
-r, --repo only search, install or clean packages from the repositories<br />
general<br />
-e, --edit edit target PKGBUILD -- can be combined with the -d, -m, -y, -u flags<br />
-c, --clean clean target(s) build files -- can be combined with the -m, -y, -u flags<br />
-q, --quiet show less information for query and search<br />
--devel consider AUR development packages upgrade<br />
--ignore ignore a package upgrade (can be used more than once)<br />
--noconfirm do not prompt for any confirmation<br />
--noedit do not prompt to edit files<br />
--rebuild always rebuild package<br />
</pre><br />
<br />
===Userbase target===<br />
<br />
Pacaur has two types of users in mind:<br />
* those who prefer to have one single tool to manage AUR and official repositories,<br />
* those who prefer to keep their AUR frontend separate from Pacman.<br />
<br />
As such there are two sets of commands: <br />
* commands that wrap the pacman binary (-S, -Ss, -Si, -Sw. -Su, -Qu, -Sc) and extend its functions to the AUR. This behavior can be disabled with the fallback variable in the config file.<br />
* commands that are AUR specific (-s, -i, -m, -y, -k, -u).<br />
<br />
===Example===<br />
<br />
By default, pacaur -Ss ''package'' will search the repo, then the AUR if necessary.<br />
<br />
$ pacaur -Ss expac<br />
community/expac 1-2<br />
pacman database extraction utility<br />
aur/expac-git 20110324-1 (24)<br />
pacman database extraction utility<br />
<br />
This behavior is optional and can be disabled with the ''fallback'' variable in the config file. When disabled, pacaur -Ss ''package'' will search the repo only.<br />
<br />
Also, pacaur -Ssr ''package'' will be restricted to searching in the repo only, while pacaur -Ssa ''package'' will search the AUR.<br />
<br />
$ pacaur -Ssr expac<br />
community/expac 1-2<br />
pacman database extraction utility<br />
<br />
$ pacaur -Ssa expac<br />
aur/expac-git 20110324-1 (24)<br />
pacman database extraction utility<br />
<br />
pacaur -s ''package'' will search the AUR only.<br />
<br />
$ pacaur -s expac<br />
aur/expac-git 20110324-1 (24)<br />
pacman database extraction utility<br />
<br />
==Configuration==<br />
<br />
Here are the available options in the config file:<br />
<pre><br />
#<br />
# /etc/xdg/pacaur/config<br />
#<br />
<br />
# The following options are commented out with their default values listed.<br />
# If you wish to use different values, uncomment and update the values.<br />
#builddir="${BUILDDIR:-$tmpdir}" # build directory<br />
#editor="${EDITOR:-vi}" # PKGBUILD editor<br />
#editpkgbuild=true # edit PKGBUILD script<br />
#editinstall=true # edit install script<br />
#fallback=true # pacman fallback to the AUR<br />
#clean=true # clean up after package install<br />
#cleandevel=true # clean up devel package<br />
#secure=false # enhanced security<br />
#sudoloop=false # prevent sudo timeout<br />
</pre><br />
<br />
See also '''man pacaur'''.<br />
<br />
=== Config files ===<br />
Pacaur fully honors pacman and makepkg configuration files, as well as the sudoers and cower config file (if existing).<br />
<br />
=== Environment variables ===<br />
Note that pacaur fully honors pacman and makepkg environment variables ({{ic|$BUILDDIR}}, {{ic|$PKGDEST}}, {{ic|$PACMAN}}, ...).<br />
<br />
=== Sudo configuration ===<br />
Pacaur is designed to be used with [[sudo]] for minimal password prompting and your {{ic|/etc/sudoers}} should be configured accordingly.<br />
<br />
ATTENNTION: this is a huge security risk: <br />
To avoid password prompt timeout (typically if you went grabbing a coffee while waiting the build to finish), disable it in your sudoers:<br />
<pre><br />
Defaults passwd_timeout=0<br />
</pre><br />
<br />
==Troubleshooting==<br />
<br />
===Host name error===<br />
When checking AUR packages for updates, pacaur outputs a lot of "Couldn't resolve host name" and "Timeout was reached" messages in spite of the internet line working correctly.<br />
* [[General_Recommendations#DNS_speed_improvement|Configure your DNS server]] to improve queries speed. Try using Google primary DNS (8.8.8.8 and 8.8.4.4).<br />
* Alternatively, tweak cower's config file to decrease the number of threads used in "MaxThread" variable.<br />
<br />
===Using gvim as editor===<br />
When using gvim as editor, gvim opens but the build continues. In the config file, try:<br />
<br />
<pre><br />
editor="gvim --nofork"<br />
</pre><br />
<br />
===Vim complains about unicode characters===<br />
<br />
To ensure that pacaur is working correctly with non English locales, LC_ALL=C is enforced with languages that aren't provided by pacaur.<br />
You can however fix this issue in your global vim config file with:<br />
<pre>set encoding=utf-8</pre><br />
<br />
==Improving pacaur==<br />
<br />
===Internationalization===<br />
See [https://github.com/Spyhawk/pacaur/blob/master/po/HOWTO Internationalization howto].<br />
<br />
===Bug reports===<br />
When reporting problems, please:<br />
<br />
* check whether "makepkg -si" can build and install a package successfully. As pacaur relies exclusively on makepkg to build and install packages, the PKGBUILD must be corrected by its maintainer if makepkg fails.<br />
* check that the problem is reproducible, and is not caused by a misconfiguration of pacman.conf/makepkg.conf/pacaur.conf/sudoers/etc.<br />
* post the ouput of "bash -x pacaur <your command>" here or on github to help me debug the issue.<br />
<br />
===Feature requests===<br />
Pacaur is considered as "features complete" and most probably will not include new features. However, any feature request or patch will be considered, and might be implemented as long as the objectives of speed, simplicity, fast workflow, uncluttered interface and the Arch way are respected.<br />
<br />
==External Links==<br />
* [http://spyhawk.github.com/pacaur/ Project page]<br />
* [https://bbs.archlinux.org/viewtopic.php?pid=937423 Forum page]<br />
* [https://github.com/Spyhawk/pacaur pacaur's github page]</div>Rasihttps://wiki.archlinux.org/index.php?title=Pacaur&diff=253228Pacaur2013-04-07T13:28:10Z<p>Rasi: /* Sudo configuration */</p>
<hr />
<div>[[Category:Package management]]<br />
[[Category:Arch User Repository]]<br />
{{Article summary start}}<br />
{{Article summary text|How to install and use pacaur.}}<br />
{{Article summary heading|Related}}<br />
{{Article summary wiki|AUR Helpers}}<br />
{{Article summary end}}<br />
<br />
'''Pacaur''' is an [[Arch User Repository]] (AUR) [[AUR helpers|helper]] aiming at speed and simplicity, designed to minimize user prompt interaction and to use an uncluttered interface. It is written in Bash and built upon the well designed cower and expac C backends.<br />
<br />
{{note|Pacaur is targeted at '''advanced users''' who want some degree of automation for repetitive tasks. As such, the user is expected to be familiar with the [[Arch User Repository|manual build process]]. }}<br />
<br />
==Philosophy==<br />
<br />
Pacaur's main feature revolves around a ''fast workflow'' idea, that is, spending as little time as possible interacting with package management prompts. Speed, simplicity and the need for an uncluttered interface were also taken into consideration.<br />
<br />
Pacaur is:<br />
<br />
Fast<br />
* It minimizes user interaction.<br />
* It has very good performance with a small memory footprint.<br />
* It retrieve and edit all PKGBUILDs, and checks and solves all conflicts before building anything.<br />
<br />
<br />
Simple<br />
* It does not add a lot of features, but simply extends pacman to manage the AUR.<br />
* It does not reinvent the wheel, but is built upon existing tools (cower, expac, sudo).<br />
* It is a small bash script using tiny C libraries.<br />
* It is based on the libalpm C interface directly maintained by a pacman developer.<br />
<br />
<br />
Powerful<br />
* It can be used as a separate AUR frontend, or a single tool to manage official and AUR packages.<br />
* Its search function provides regex support (through cower).<br />
* It provides binary and AUR package names completion.<br />
* It passes arguments to pacman when appropriate.<br />
* It shows current and available versions when checking for updates.<br />
<br />
<br />
Secure<br />
* It does not source PKGBUILDs unecessarily.<br />
* It detects and warns of possible malicious pseudocode in PKGBUILDs.<br />
* It disposes of an additional full secured mode for paranoid people.<br />
<br />
==Installation==<br />
<!-- Please don't add direct commands to install pacaur. All users should be familiar with the build process. --><br />
<br />
The following binary dependencies need to be installed:<br />
* {{pkg|sudo}} [core]<br />
* {{pkg|expac}} [community]<br />
<br />
You can then install {{AUR|cower}} as a dependency, and then {{AUR|pacaur}} itself. Both of those packages are available in the AUR.<br />
<br />
==Usage==<br />
<br />
Invoking pacaur consists of supplying an operation, any applicable options, and usually one or more targets.<br />
<br />
<pre><br />
usage: pacaur <operation> [options] [package(s)]<br />
operations:<br />
pacman extension<br />
-S, -Q extend pacman operations to the AUR<br />
AUR only<br />
-s, --search search AUR repository for matching strings<br />
-i, --info view package information -- pass twice for details<br />
-d, --download download target(s) -- pass twice to download AUR dependencies<br />
-m, --makepkg download and make target(s)<br />
-y, --sync download, make and install target(s)<br />
-k, --check check for AUR update(s)<br />
-u, --update update AUR package(s)<br />
general<br />
-v, --version display version information<br />
-h, --help display help information<br />
--fixbackend quickly rebuild backend<br />
<br />
options:<br />
pacman extension - can be used with the -S, -Ss, -Si, -Sii, -Sw, -Su, -Qu, -Sc, -Scc operations<br />
-a, --aur only search, install or clean packages from the AUR<br />
-r, --repo only search, install or clean packages from the repositories<br />
general<br />
-e, --edit edit target PKGBUILD -- can be combined with the -d, -m, -y, -u flags<br />
-c, --clean clean target(s) build files -- can be combined with the -m, -y, -u flags<br />
-q, --quiet show less information for query and search<br />
--devel consider AUR development packages upgrade<br />
--ignore ignore a package upgrade (can be used more than once)<br />
--noconfirm do not prompt for any confirmation<br />
--noedit do not prompt to edit files<br />
--rebuild always rebuild package<br />
</pre><br />
<br />
===Userbase target===<br />
<br />
Pacaur has two types of users in mind:<br />
* those who prefer to have one single tool to manage AUR and official repositories,<br />
* those who prefer to keep their AUR frontend separate from Pacman.<br />
<br />
As such there are two sets of commands: <br />
* commands that wrap the pacman binary (-S, -Ss, -Si, -Sw. -Su, -Qu, -Sc) and extend its functions to the AUR. This behavior can be disabled with the fallback variable in the config file.<br />
* commands that are AUR specific (-s, -i, -m, -y, -k, -u).<br />
<br />
===Example===<br />
<br />
By default, pacaur -Ss ''package'' will search the repo, then the AUR if necessary.<br />
<br />
$ pacaur -Ss expac<br />
community/expac 1-2<br />
pacman database extraction utility<br />
aur/expac-git 20110324-1 (24)<br />
pacman database extraction utility<br />
<br />
This behavior is optional and can be disabled with the ''fallback'' variable in the config file. When disabled, pacaur -Ss ''package'' will search the repo only.<br />
<br />
Also, pacaur -Ssr ''package'' will be restricted to searching in the repo only, while pacaur -Ssa ''package'' will search the AUR.<br />
<br />
$ pacaur -Ssr expac<br />
community/expac 1-2<br />
pacman database extraction utility<br />
<br />
$ pacaur -Ssa expac<br />
aur/expac-git 20110324-1 (24)<br />
pacman database extraction utility<br />
<br />
pacaur -s ''package'' will search the AUR only.<br />
<br />
$ pacaur -s expac<br />
aur/expac-git 20110324-1 (24)<br />
pacman database extraction utility<br />
<br />
==Configuration==<br />
<br />
Here are the available options in the config file:<br />
<pre><br />
#<br />
# /etc/xdg/pacaur/config<br />
#<br />
<br />
# The following options are commented out with their default values listed.<br />
# If you wish to use different values, uncomment and update the values.<br />
#builddir="${BUILDDIR:-$tmpdir}" # build directory<br />
#editor="${EDITOR:-vi}" # PKGBUILD editor<br />
#editpkgbuild=true # edit PKGBUILD script<br />
#editinstall=true # edit install script<br />
#fallback=true # pacman fallback to the AUR<br />
#clean=true # clean up after package install<br />
#cleandevel=true # clean up devel package<br />
#secure=false # enhanced security<br />
#sudoloop=false # prevent sudo timeout<br />
</pre><br />
<br />
See also '''man pacaur'''.<br />
<br />
=== Config files ===<br />
Pacaur fully honors pacman and makepkg configuration files, as well as the sudoers and cower config file (if existing).<br />
<br />
=== Environment variables ===<br />
Note that pacaur fully honors pacman and makepkg environment variables ({{ic|$BUILDDIR}}, {{ic|$PKGDEST}}, {{ic|$PACMAN}}, ...).<br />
<br />
=== Sudo configuration ===<br />
Pacaur is designed to be used with [[sudo]] for minimal password prompting and your {{ic|/etc/sudoers}} should be configured accordingly.<br />
<br />
To avoid password prompt timeout (typically if you went grabbing a coffee while waiting the build to finish), disable it in your sudoers:<br />
<pre><br />
Defaults passwd_timeout=0<br />
</pre><br />
<br />
While this is convinient its also totally insecure, since every open terminal that had sudo executed at some point, can be used by anyone to <br />
do stuff as root.<br />
<br />
==Troubleshooting==<br />
<br />
===Host name error===<br />
When checking AUR packages for updates, pacaur outputs a lot of "Couldn't resolve host name" and "Timeout was reached" messages in spite of the internet line working correctly.<br />
* [[General_Recommendations#DNS_speed_improvement|Configure your DNS server]] to improve queries speed. Try using Google primary DNS (8.8.8.8 and 8.8.4.4).<br />
* Alternatively, tweak cower's config file to decrease the number of threads used in "MaxThread" variable.<br />
<br />
===Using gvim as editor===<br />
When using gvim as editor, gvim opens but the build continues. In the config file, try:<br />
<br />
<pre><br />
editor="gvim --nofork"<br />
</pre><br />
<br />
===Vim complains about unicode characters===<br />
<br />
To ensure that pacaur is working correctly with non English locales, LC_ALL=C is enforced with languages that aren't provided by pacaur.<br />
You can however fix this issue in your global vim config file with:<br />
<pre>set encoding=utf-8</pre><br />
<br />
==Improving pacaur==<br />
<br />
===Internationalization===<br />
See [https://github.com/Spyhawk/pacaur/blob/master/po/HOWTO Internationalization howto].<br />
<br />
===Bug reports===<br />
When reporting problems, please:<br />
<br />
* check whether "makepkg -si" can build and install a package successfully. As pacaur relies exclusively on makepkg to build and install packages, the PKGBUILD must be corrected by its maintainer if makepkg fails.<br />
* check that the problem is reproducible, and is not caused by a misconfiguration of pacman.conf/makepkg.conf/pacaur.conf/sudoers/etc.<br />
* post the ouput of "bash -x pacaur <your command>" here or on github to help me debug the issue.<br />
<br />
===Feature requests===<br />
Pacaur is considered as "features complete" and most probably will not include new features. However, any feature request or patch will be considered, and might be implemented as long as the objectives of speed, simplicity, fast workflow, uncluttered interface and the Arch way are respected.<br />
<br />
==External Links==<br />
* [http://spyhawk.github.com/pacaur/ Project page]<br />
* [https://bbs.archlinux.org/viewtopic.php?pid=937423 Forum page]<br />
* [https://github.com/Spyhawk/pacaur pacaur's github page]</div>Rasihttps://wiki.archlinux.org/index.php?title=Music_Player_Daemon&diff=251810Music Player Daemon2013-03-24T11:04:22Z<p>Rasi: /* Scripted Configuration */</p>
<hr />
<div>[[Category:Player]]<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|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:Music Player Daemon|Wikipedia article]]}}<br />
{{Article summary end}}<br />
<br />
'''[http://mpd.wikia.com 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 />
<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 />
<br />
MPD is able to run locally (per user settings), globally (settings apply to all users), and in multiple instances. The way of setting up mpd depends on the way it is intended to be used: a local configuration may prove more useful on a desktop system, for example.<br />
<br />
For a proper MPD operation these are the necessary files and directories:<br />
<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 />
=== Local Configuration (per user) ===<br />
<br />
MPD can be configured per user (rather than the typical method of configuring MPD globally). Running MPD as a normal user has the benefits of:<br />
<br />
* A single directory {{ic|~/.mpd}} (or any other directory under {{ic|/home/$USER/}}) that will contain all the MPD configuration files.<br />
* Easier to avoid unforeseen read/write permission errors.<br />
<br />
To setup: create a directory for the required files and the playlists; copy the example configuration locally; create all of the requisite files:<br />
<br />
mkdir -p ~/.mpd/playlists<br />
cp /usr/share/doc/mpd/mpdconf.example ~/.mpd/mpd.conf<br />
touch ~/.mpd/{database,log,state}<br />
<br />
Edit {{ic|~/.mpd/mpd.conf}} and specify the requisite files:<br />
<br />
{{hc|~/.mpd/mpd.conf|<br />
music_directory "~/music" # Can keep commented if XDG music dir.<br />
playlist_directory "~/.mpd/playlists"<br />
db_file "~/.mpd/database"<br />
log_file "~/.mpd/log"<br />
pid_file "~/.mpd/pid"<br />
state_file "~/.mpd/state"<br />
}}<br />
<br />
MPD can now be started by typing {{ic|mpd}} on the command line (mpd first searches for {{ic|~/.mpd.conf}}, then {{ic|~/.mpd/mpd.conf}}, and then for {{ic|/etc/mpd.conf}} [there is no support for XDG-config directory {{ic|~/.config/mpd/mpd.conf}}]). To specify the location of the configuration file :<br />
<br />
mpd ~/.config/mpd/mpd.conf<br />
<br />
To start MPD on login add to {{ic|~/.profile}} (or another [[Autostarting#Shells|Autostart file]]):<br />
<br />
# MPD daemon start (if no other user instance exists)<br />
[ ! -s ~/.mpd/mpd.pid ] && mpd<br />
<br />
To start with the X.org server add to either [[xprofile]] or [[xinitrc]]. Some DEs ignore these files (GNOME does) and a desktop file must be placed in {{ic|~/.config/autostart/mpd.desktop}}:<br />
<br />
<pre>[Desktop Entry]<br />
Encoding=UTF-8<br />
Type=Application<br />
Name=Music Player Daemon<br />
Comment=Server for playing audio files<br />
Exec=mpd<br />
StartupNotify=false<br />
Terminal=false<br />
Hidden=false<br />
X-GNOME-Autostart-enabled=false</pre><br />
<br />
==== Autostart with systemd ====<br />
<br />
{{Note|1=As of 2013-03-20 this functionality is still in development ([https://bbs.archlinux.org/viewtopic.php?pid=1208585 forum thread]). However, there is a workaround though it is peculiar as it requires a running X.org server to work.}}<br />
<br />
'''Expected setup'''<br />
<br />
* Start user-session service (e.g. {{ic|sudo systemctl enable user-session@USERNAME}}).<br />
* Add local service file {{ic|~/.config/systemd/user/mpd.service}} (see below).<br />
* Start local systemd {{ic|systemd --user &}}; enable service file {{ic|systemctl --user enable mpd}}; start it {{ic|systemctl --user start mpd}}.<br />
* Add {{ic|systemd --user &}} to {{ic|~/.profile}} or another autostart file.<br />
* Reboot and MPD start.<br />
<br />
<pre>[Unit]<br />
Description=Music Player Daemon<br />
<br />
[Service]<br />
ExecStart=/usr/bin/mpd %h/.config/mpd/mpd.conf --no-daemon<br />
ExecStop= /usr/bin/mpd %h/.config/mpd/mpd.conf --kill<br />
<br />
[Install]<br />
WantedBy=default.target</pre><br />
<br />
'''Current setup''' (this hasn't worked for everybody)<br />
<br />
As recommended above, it is best to use MPD as a service per user. In this case, we will use {{ic|~/.mpd/mpd.conf}} and not start mpd.service as a daemon for the whole system and all users.<br />
We will NOT use the {{ic|/usr/lib/systemd/system/mpd.service}} which is intended to start the mpd.service as root and for all users. <br />
<br />
{{Note|It is recommended to follow the instructions in the [[Systemd/User]] page fully, and to have your whole session managed by {{ic|systemd --user}}.}}<br />
<br />
If you already enabled it, just disable it first:<br />
{{bc| # systemctl disable mpd.service}}<br />
<br />
If you used to start mpd inside your {{ic|~/.xinitrc}}, comment or delete the line<br />
{{bc|mpd ~/.mpdconf}}<br />
<br />
Then, edit a new file ~/.config/systemd/user/mpd.service <br />
{{hc|~/.config/systemd/user/mpd.service|<br />
[Unit]<br />
Description &#61; Music Player Daemon<br />
<br />
[Service]<br />
ExecStart &#61; /usr/bin/mpd --no-daemon<br />
Restart &#61; always<br />
<br />
[Install]<br />
WantedBy &#61; default.target<br />
}}<br />
<br />
Then, add this line to [[xinitrc|.xinitrc]] before any exec <session-command><br />
{{hc|~/.xinitrc|<br />
#run systemd as user instance<br />
systemd --user &<br />
}}<br />
<br />
Log out, log in your xsession.<br />
Let's first check mpd is not running. If yes, just kill it. If not, continue to the next step.<br />
{{bc|$ ps -ef &#124; grep mpd}}<br />
<br />
Now, enable and start mpd.service as per user <br />
$ systemctl --user enable mpd<br />
$ systemctl --user start mpd<br />
<br />
Check the mpd status and see if mpd.service is correctly enabled and started<br />
{{bc|$ systemctl --user status mpd}}<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://53280.de/dl/mpdsetup.sh here].<br />
<br />
=== Global Configuration ===<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 />
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 "/path/to/music/dir"<br />
playlist_directory "/var/lib/mpd/playlists"<br />
db_file "/var/lib/mpd/mpd.db"<br />
log_file "syslog"<br />
pid_file "/run/mpd/mpd.pid"<br />
state_file "/var/lib/mpd/mpdstate"<br />
user "mpd"<br />
}}<br />
<br />
We just configured MPD to run as the ''mpd'' user, but {{ic|/var/lib/mpd}} is owned by ''root'' by default, we need to change this so ''mpd'' can write here:<br />
# chown -R mpd /var/lib/mpd<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 {{ic|/var/lib/mpd}}). 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 "/path/to/music/dir /var/lib/mpd/music none bind" >> /etc/fstab<br />
# mount -a<br />
Also see [https://bbs.archlinux.org/viewtopic.php?id=86449 this 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 /path/to/music/dir /var/lib/mpd/music/<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 />
==== Start MPD ====<br />
MPD can be controlled with the ''mpd'' [[daemon]]. The first startup can take some time as MPD will scan your music directory.<br />
<br />
Test everything by starting a client application ({{Pkg|ncmpc}} is a light and easy to use client), and play some music!<br />
<br />
==== Configure audio ====<br />
{{Note|Everything should work by default, only change this if it doesn't work for you!}}<br />
To change the volume for mpd independent from other programs, uncomment or add this switch in mpd.conf:<br />
{{hc|/etc/mpd.conf|<br />
mixer_type "software"<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 />
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 />
==== Changing user ====<br />
{{Note|This is only required if you change the user!}}<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, so add user {{Ic|mpd}} to group {{Ic|audio}}.<br />
# gpasswd -a mpd audio<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 />
# Since MPD is started as root by systemd, 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 />
=== 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 />
*{{App|vimpc|ncurses based MPD client with vi-like key bindings|http://sourceforge.net/projects/vimpc/|{{AUR|vimpc}}}}<br />
<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 />
*{{App|Cantata|High-feature, Qt4/KDE4 client for MPD with very configurable interface|https://code.google.com/p/cantata/|{{AUR|cantata-qt}}}}<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>Rasihttps://wiki.archlinux.org/index.php?title=Music_Player_Daemon&diff=245942Music Player Daemon2013-02-01T23:06:13Z<p>Rasi: /* Scripted Configuration */</p>
<hr />
<div>[[Category:Player]]<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 />
<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 intended 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 />
=== 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/{database,log,pid,state}</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/database"<br />
log_file "/home/USER/.mpd/log"<br />
pid_file "/home/USER/.mpd/pid"<br />
state_file "/home/USER/.mpd/state"<br />
}}<br />
<br />
or you can use<br />
{{bc|sed "s/var\/lib\/mpd\/music/home\/$USER\/music/;<br />
s/var\/lib\/mpd/home\/$USER\/.mpd/;<br />
s/var\/run\/mpd/home\/$USER\/.mpd/;<br />
s/var\/log\/mpd/home\/$USER\/.mpd/" /etc/mpd.conf > ~/.mpd/mpd.conf}}<br />
<br />
MPD can now be started by typing {{ic|mpd}} on the command line.<br />
<br />
To start MPD with the X server, add<br />
{{bc|mpd ~/.mpdconf}}<br />
to either [[xprofile]] or [[xinitrc]]<br />
<br />
==== Start MPD per user with systemd ====<br />
<br />
As recommended above, it is best to use MPD as a service per user. In this case, we will use {{ic|~/.mpd/mpd.conf}} and not start mpd.service as a daemon for the whole system and all users.<br />
We will NOT use the {{ic|/usr/lib/systemd/system/mpd.service}} which is intended to start the mpd.service as root and for all users. <br />
<br />
{{Note|It is recommended to follow the instructions in the [[Systemd/User]] page fully, and to have your whole session managed by {{ic|systemd --user}}.}}<br />
<br />
If you already enabled it, just disable it first:<br />
{{bc| # systemctl disable mpd.service}}<br />
<br />
If you used to start mpd inside your {{ic|~/.xinitrc}}, comment or delete the line<br />
{{bc|mpd ~/.mpdconf}}<br />
<br />
Then, edit a new file ~/.config/systemd/user/mpd.service <br />
{{hc|~/.config/systemd/user/mpd.service|<br />
[Unit]<br />
Description &#61; Music Player Daemon<br />
<br />
[Service]<br />
ExecStart &#61; /usr/bin/mpd --no-daemon<br />
Restart &#61; always<br />
<br />
[Install]<br />
WantedBy &#61; default.target<br />
}}<br />
<br />
Then, add this line to [[xinitrc|.xinitrc]] before any exec <session-command><br />
{{hc|~/.xinitrc|<br />
#run systemd as user instance<br />
systemd --user &<br />
}}<br />
<br />
Log out, log in your xsession.<br />
Let's first check mpd is not running. If yes, just kill it. If not, continue to the next step.<br />
{{bc|$ ps -ef &#124; grep mpd}}<br />
<br />
Now, enable and start mpd.service as per user <br />
$ systemctl --user enable mpd<br />
$ systemctl --user start mpd<br />
<br />
Check the mpd status and see if mpd.service is correctly enabled and started<br />
{{bc|$ systemctl --user status mpd}}<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://53280.de/dl/mpdsetup.tar here].<br />
<br />
=== Global Configuration ===<br />
{{Note|For 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}} is 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 return an error when it is started. The best way is to make the {{ic|/var/log/mpd/mpd.log}} belong to the mpd [[Users and Groups#Group management|user]].<br />
# chown -R mpd /var/log/mpd <br />
Run this to create the /run/mpd dir:<br />
# systemd-tmpfiles --create mpd.conf<br />
To change the volume for mpd independent from other programs, uncomment or add this 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, so add user {{Ic|mpd}} to group {{Ic|audio}}.<br />
# gpasswd -a mpd audio<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 />
# systemctl restart mpd.service<br />
Also see [https://bbs.archlinux.org/viewtopic.php?id=86449 this 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 />
# systemctl restart mpd.service<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 daemon 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: copy {{ic|/usr/lib/tmpfiles.d/mpd.conf}} to {{ic|/etc/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}}. You'll need to install the mpc package for this. It is in the official repositories<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 />
# Since MPD is started as root by systemd, 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 />
=== 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 />
*{{App|vimpc|ncurses based MPD client with vi-like key bindings|http://sourceforge.net/projects/vimpc/|{{AUR|vimpc}}}}<br />
<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>Rasihttps://wiki.archlinux.org/index.php?title=Music_Player_Daemon&diff=245941Music Player Daemon2013-02-01T23:05:15Z<p>Rasi: /* Scripted Configuration */</p>
<hr />
<div>[[Category:Player]]<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 />
<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 intended 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 />
=== 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/{database,log,pid,state}</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/database"<br />
log_file "/home/USER/.mpd/log"<br />
pid_file "/home/USER/.mpd/pid"<br />
state_file "/home/USER/.mpd/state"<br />
}}<br />
<br />
or you can use<br />
{{bc|sed "s/var\/lib\/mpd\/music/home\/$USER\/music/;<br />
s/var\/lib\/mpd/home\/$USER\/.mpd/;<br />
s/var\/run\/mpd/home\/$USER\/.mpd/;<br />
s/var\/log\/mpd/home\/$USER\/.mpd/" /etc/mpd.conf > ~/.mpd/mpd.conf}}<br />
<br />
MPD can now be started by typing {{ic|mpd}} on the command line.<br />
<br />
To start MPD with the X server, add<br />
{{bc|mpd ~/.mpdconf}}<br />
to either [[xprofile]] or [[xinitrc]]<br />
<br />
==== Start MPD per user with systemd ====<br />
<br />
As recommended above, it is best to use MPD as a service per user. In this case, we will use {{ic|~/.mpd/mpd.conf}} and not start mpd.service as a daemon for the whole system and all users.<br />
We will NOT use the {{ic|/usr/lib/systemd/system/mpd.service}} which is intended to start the mpd.service as root and for all users. <br />
<br />
{{Note|It is recommended to follow the instructions in the [[Systemd/User]] page fully, and to have your whole session managed by {{ic|systemd --user}}.}}<br />
<br />
If you already enabled it, just disable it first:<br />
{{bc| # systemctl disable mpd.service}}<br />
<br />
If you used to start mpd inside your {{ic|~/.xinitrc}}, comment or delete the line<br />
{{bc|mpd ~/.mpdconf}}<br />
<br />
Then, edit a new file ~/.config/systemd/user/mpd.service <br />
{{hc|~/.config/systemd/user/mpd.service|<br />
[Unit]<br />
Description &#61; Music Player Daemon<br />
<br />
[Service]<br />
ExecStart &#61; /usr/bin/mpd --no-daemon<br />
Restart &#61; always<br />
<br />
[Install]<br />
WantedBy &#61; default.target<br />
}}<br />
<br />
Then, add this line to [[xinitrc|.xinitrc]] before any exec <session-command><br />
{{hc|~/.xinitrc|<br />
#run systemd as user instance<br />
systemd --user &<br />
}}<br />
<br />
Log out, log in your xsession.<br />
Let's first check mpd is not running. If yes, just kill it. If not, continue to the next step.<br />
{{bc|$ ps -ef &#124; grep mpd}}<br />
<br />
Now, enable and start mpd.service as per user <br />
$ systemctl --user enable mpd<br />
$ systemctl --user start mpd<br />
<br />
Check the mpd status and see if mpd.service is correctly enabled and started<br />
{{bc|$ systemctl --user status mpd}}<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://53280.de/teiler here].<br />
<br />
=== Global Configuration ===<br />
{{Note|For 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}} is 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 return an error when it is started. The best way is to make the {{ic|/var/log/mpd/mpd.log}} belong to the mpd [[Users and Groups#Group management|user]].<br />
# chown -R mpd /var/log/mpd <br />
Run this to create the /run/mpd dir:<br />
# systemd-tmpfiles --create mpd.conf<br />
To change the volume for mpd independent from other programs, uncomment or add this 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, so add user {{Ic|mpd}} to group {{Ic|audio}}.<br />
# gpasswd -a mpd audio<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 />
# systemctl restart mpd.service<br />
Also see [https://bbs.archlinux.org/viewtopic.php?id=86449 this 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 />
# systemctl restart mpd.service<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 daemon 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: copy {{ic|/usr/lib/tmpfiles.d/mpd.conf}} to {{ic|/etc/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}}. You'll need to install the mpc package for this. It is in the official repositories<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 />
# Since MPD is started as root by systemd, 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 />
=== 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 />
*{{App|vimpc|ncurses based MPD client with vi-like key bindings|http://sourceforge.net/projects/vimpc/|{{AUR|vimpc}}}}<br />
<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>Rasihttps://wiki.archlinux.org/index.php?title=Music_Player_Daemon/Tips_and_tricks&diff=242400Music Player Daemon/Tips and tricks2013-01-01T04:02:22Z<p>Rasi: /* Cue Files */</p>
<hr />
<div>[[Category:Player]]<br />
Go back to [[Music Player Daemon]].<br />
<br />
==Tips and Tricks==<br />
===Organizing===<br />
MPD doesn't provide a tool to preserve the file structure of your audio files. Check out [http://beets.radbox.org/ beets].<br />
<br />
===Last.fm scrobbling===<br />
To scrobble your songs to [http://www.last.fm Last.fm] when using MPD, there are several possibilities.<br />
<br />
====mpdscribble====<br />
mpdscribble is a daemon, available in the "community" repository (if you prefer, the "git" version is available in the [https://aur.archlinux.org/packages.php?ID=22274 AUR]). This is arguably the best alternative, because it's the semi-official MPD scrobbler and uses the new "idle" feature in MPD for more accurate scrobbling. Also, you do not need root access to configure it, because it doesn't need any changes to {{ic|/etc}} at all. Visit [http://mpd.wikia.com/wiki/Client:Mpdscribble the official website] for more information.<br />
<br />
After you have installed mpdscribble, do the following (not as root):<br />
<br />
{{bc|$ mkdir ~/.mpdscribble}}<br />
* Create the file {{ic|~/.mpdscribble/mpdscribble.conf}} and add the following:<br />
{{hc|~/.mpdscribble/mpdscribble.conf|2=<br />
[mpdscribble] <br />
host = <your mpd host> # optional, defaults to $MPD_HOST or localhost<br />
port = <your mpd port> # optional, defaults to $MPD_PORT or 6600<br />
log = /home/<YOUR_USERNAME>/.mpdscribble/mpdscribble.log<br />
verbose = 2<br />
sleep = 1<br />
musicdir = <your music directory><br />
proxy = <your proxy> # optional, e. g. http://your.proxy:8080, defaults to none<br />
<br />
[last.fm]<br />
# last.fm section, comment if you do not use last.fm<br />
url = http://post.audioscrobbler.com/<br />
username = <your last.fm username><br />
password = <your last.fm password> <br />
journal = /home/<YOUR_USERNAME>/.mpdscribble/lastfm.journal<br />
<br />
[libre.fm]<br />
# libre.fm section, comment if you do not use libre.fm<br />
url = http://turtle.libre.fm/<br />
username = <your libre.fm username><br />
password = <your libre.fm password><br />
journal = /home/<YOUR_USERNAME>/.mpdscribble/librefm.journal<br />
}}<br />
Please note that passwords can also be written down as MD5:<br />
echo -n 'PASSWORD' | md5sum | cut -f 1 -d " "<br />
<br />
* Add {{ic|mpdscribble}} to the file in which you start {{ic|mpd}} as well (e.g. {{ic|~/.xinitrc}}):<br />
{{bc|<br />
pidof mpdscribble >& /dev/null<br />
if [ $? -ne 0 ]; then<br />
mpdscribble &<br />
fi<br />
}}<br />
<br />
====mpdscribble per user with systemd====<br />
<br />
Since systemd is default on new installations, starting mpdscribble with .xinitrc is outdated. mpdscribble should be started per user with systemd. See [[Mpd#Start_MPD_per_user_with_systemd]] and [[Systemd/User]].<br />
<br />
Install mpdscribble<br />
pacman -S mpdscribble<br />
<br />
Create a directory for mpdscribble and copy the example .conf<br />
mkdir ~/.mpdscribble<br />
cp /usr/share/mpdscribble/mpdscribble.conf.example ~/.mpdscribble.conf<br />
<br />
With the current version {{Pkg|mpdscribble 0.22-5}}, adding the sections mentiond above to ~/.mpdscribble.conf isn't necessary. Just add your username and password.<br />
<br />
Then, edit a new file ~/.config/systemd/user/mpdscribble.service<br />
{{hc|~/.config/systemd/user/mpdscribble.service|<br />
[Unit]<br />
Description &#61; MPD Scribbler<br />
<br />
[Service]<br />
ExecStart &#61; /usr/bin/mpdscribble -D<br />
Restart &#61; always<br />
<br />
[Install]<br />
WantedBy &#61; default.target<br />
}}<br />
<br />
Now, enable and start mpdscribble.service as per user <br />
$ systemctl --user enable mpdscribble<br />
$ systemctl --user start mpdscribble<br />
<br />
====Sonata & Ario====<br />
Sonata has built-in support for scrobbling, although that requires the program to run the whole time. Additionally, Sonata doesn't cache the songs if they cannot be forwarded to Last.fm at the time of playing, meaning they will not be added to the statistics.<br />
<br />
====lastfmsubmitd====<br />
The daemon lastfmsubmitd is a daemon which may be installed from the "community" repository as well. To install it, first edit {{ic|/etc/lastfmsubmitd.conf}} to reflect your requirements and add both {{ic|lastfmsubmitd}} and {{ic|lastmp}} to the {{ic|DAEMONS}} array in {{ic|/etc/rc.conf}}.<br />
<br />
====Last.fm playback====<br />
=====Native Last.fm playback=====<br />
Since version 0.16 mpd has a very well working method to [http://mpd.wikia.com/wiki/Last.fm_Radio play back last.fm streams].<br />
{{hc|/etc/mpd.conf|2=<br />
$ playlist_plugin {<br />
name "lastfm"<br />
user "my_username"<br />
password "my_password"<br />
}<br />
}}<br />
Then use e.g. mpc to load streams<br />
{{bc|$ mpc load "lastfm://artist/Beatles"}}<br />
<br />
===Never play on start===<br />
This feature is present in mpd after version 0.16.2. When this feature is enabled, the mpd process will always start in the "paused" state, even if a song was playing when mpd was stopped. Add the line below to your {{ic|mpd.conf}} file to enable this feature.<br />
restore_paused "yes"<br />
<br />
The following sections detail various methods to simulate the same feature for older versions of mpd.<br />
<br />
====Installing mpd from the AUR====<br />
This is the best method currently available, but is only currently (as of April 2011) enabled in the git version. Install [https://aur.archlinux.org/packages.php?ID=19676 mpd-git] from the [[AUR]] and add {{ic|restore_paused "yes"}} to your {{ic|mpd.conf}} file.<br />
<br />
If you have issues with connecting your client to [https://aur.archlinux.org/packages.php?ID=19676 mpd-git], see [[Music Player Daemon/Troubleshooting#Other issues when attempting to connect to mpd with a client]].<br />
<br />
====Method 1====<br />
If you do not want MPD to always play on your system start, but yet you want to preserve the other state information, add the following lines to your {{ic|/etc/rc.d/mpd}} file:<br />
=====Method 1.1=====<br />
Simpler, working method (disables playing on startup of mpd daemon):<br />
start)<br />
...<br />
mpc -q pause #add this line only<br />
add_daemon mpd<br />
stat_done<br />
<br />
To prevent updates from destroying these modifications, add this file to the {{ic|NoUpgrade}} variable in {{ic|/etc/pacman.conf}}:<br />
NoUpgrade = etc/rc.d/mpd<br />
<br />
====Method 2====<br />
Another simpler method, would be to add mpd to your {{ic|[[rc.conf]]}} daemons array and add {{ic|mpc stop}} or {{ic|mpc pause}} to {{ic|/etc/rc.local.shutdown}} and to {{ic|/etc/rc.local}}. (Remember you must have mpc installed to use this method).<br />
<br />
Adding only the order in {{ic|/etc/rc.local}} cannot assure that mpd will play absolutely nothing, since there may be a delay before the stop command is executed. <br />
On the other hand, if you only add the order to {{ic|/etc/rc.local.shutdown}}, that will assure that mpd won't play at all, as long as you properly shutdown your system.<br />
Even though they are redundant, adding it to {{ic|/etc/rc.local}} would serve as a safety for those, presumably, rare occasions when you do not shutdown the system properly.<br />
<br />
====Method 3====<br />
The general idea is to ask mpd to pause music when the user logs out, so that mpd will stick to the "pause" state after a reboot. Sending such command can be achieved using {{Pkg|mpc}}, the command line interface to MPD.<br />
<br />
GDM users can then add {{ic|/usr/bin/mpc pause}} to {{ic|/etc/gdm/PostSession/Default}} (be sure to add it before {{ic|exit 0}}):<br />
<br />
Non-GDM users can use their own login manager's method to launch the line at logout.<br />
<br />
====Example configuration: Output with 44.1 KHz at e. g. 16 bit depth, multiple programs at once====<br />
''Why these formats?'' Because they are standard CDA, because ALSA on its own allows more than one program "to sound" only with dmix — whose resampling algorithm is inferior — and because dmix by default resamples anything lower to 48 KHz (or whatever higher format is playing at the time). Also, some get clicking sounds if at least {{ic|mpd.conf}} is not changed this way.<br />
<br />
''What's the downside?'' These settings cause ''everything'' (if necessary) to be resampled to this format, such as material from DVD or TV which usually is at 48 KHz. But there is no known way to have ALSA dynamically change the format, and particularly if you listen to far more CDs than anything else the occasional 48 → 44.1 isn't too great a loss.<br />
<br />
The following assumes that there are not already other settings which conflict resp. overwrite it. This applies especially to the current user's potential {{ic|~/.asoundrc}} — which MPD as its own user ignores, therefore the following should go to {{ic|/etc/asound.conf}}:<br />
<br />
{{hc|/etc/asound.conf|<br />
defaults.pcm.dmix.rate 44100 # Force 44.1 KHz<br />
defaults.pcm.dmix.format S16_LE # Force 16 bits<br />
}}<br />
<br />
{{hc|/etc/mpd.conf|2=<br />
audio_output {<br />
type "alsa" # Use the ALSA output plugin.<br />
name "HDA Intel" # Can be called anything or nothing tmk, but must be present.<br />
options "dev=dmixer"<br />
device "plug:dmix" # Both lines cause MPD to output to dmix.<br />
format "44100:16:2" # the actual format<br />
auto_resample "no" # This bypasses ALSA's own algorithms, which generally are inferior. See below how to choose a different one.<br />
use_mmap "yes" # Minor speed improvement, should work with all modern cards.<br />
}<br />
<br />
samplerate_converter "0" # MPD's best, most CPU intensive algorithm. See 'man mpd.conf' for others — for anything other than the poorest "internal", libsamplerate must be installed.<br />
}}<br />
<br />
{{Note|MPD gives the mp3 format a special treatment at decoding: It's always put out as 24 bit. (The conversion as forced by the ''format'' line only comes after that.)}}<br />
<br />
If one wants to leave the bit depth decision to ALSA resp. MPD, comment out resp. omit the ''dmix.format'' line and change the one for mpd with ''format'' to "44100:*:2".<br />
<br />
{{Note|''Crossfading'' between files decoded at two different bit depths (say, one mp3 and one 16 bit flac) does not work unless conversion is active.}}<br />
<br />
=== Control MPD with lirc ===<br />
There are already some clients designed for communications between lircd and MPD, however, as far as the practical use, they aren't very useful since their functions are limited.<br />
<br />
It's recommended to use mpc with irexec. mpc is a command line player which only sends the command to MPD and exits immediately, which is perfect for irexec, the command runner included in lirc. What irexec does is that it runs a specified command once received a remote control button.<br />
<br />
First of all, please setup your remotes as referred to the '''[[Lirc]]''' article.<br />
<br />
Edit your favored lirc startup configuration file, default location is {{ic|~/.lircrc}}.<br />
<br />
Fill the file with the following pattern:<br />
begin<br />
prog = irexec<br />
button = <button_name><br />
config = <command_to_run><br />
repeat = <0 or 1><br />
end<br />
<br />
An useful example:<br />
## irexec<br />
begin<br />
prog = irexec<br />
button = play_pause<br />
config = mpc toggle<br />
repeat = 0<br />
end<br />
<br />
begin<br />
prog = irexec<br />
button = stop<br />
config = mpc stop<br />
repeat = 0<br />
end<br />
begin<br />
prog = irexec<br />
button = previous<br />
config = mpc prev<br />
repeat = 0<br />
end<br />
begin<br />
prog = irexec<br />
button = next<br />
config = mpc next<br />
repeat = 0<br />
end<br />
begin<br />
prog = irexec<br />
button = volup<br />
config = mpc volume +2<br />
repeat = 1<br />
end<br />
begin<br />
prog = irexec<br />
button = voldown<br />
config = mpc volume -2<br />
repeat = 1<br />
end<br />
begin<br />
prog = irexec<br />
button = pbc<br />
config = mpc random<br />
repeat = 0<br />
end<br />
begin<br />
prog = irexec<br />
button = pdvd<br />
config = mpc update<br />
repeat = 0<br />
end<br />
begin<br />
prog = irexec<br />
button = right<br />
config = mpc seek +00:00:05<br />
repeat = 0<br />
end<br />
begin<br />
prog = irexec<br />
button = left<br />
config = mpc seek -00:00:05<br />
repeat = 0<br />
end<br />
begin<br />
prog = irexec<br />
button = up<br />
config = mpc seek +1%<br />
repeat = 0<br />
end<br />
begin<br />
prog = irexec<br />
button = down<br />
config = mpc seek -1%<br />
repeat = 0<br />
end<br />
<br />
There are more functions for mpc, run {{ic|man mpc}} for more info.<br />
<br />
===Control MPD with phone===<br />
=====remuco via bluetooth=====<br />
* install [http://remuco.sourceforge.net/index.php/Remuco remuco] -- a wireless remote control for several Linux media players ([https://aur.archlinux.org/packages.php?ID=25072 aur])<br />
* transfer remuco client -- jar/jad files from {{ic|/usr/share/remuco/client/}} to your phone and install it<br />
* run {{ic|remuco-mpd}} (as current user)<br />
* run remuco on your phone, define a new bluetooth remuco connection (pair first if you haven't done this previously) and explore its capabilities<br />
<br />
=====others=====<br />
There are several MPD-specific clients available in the app-store/market of Symbian, Android and iOS.<br />
<br />
=== MPD & PulseAudio ===<br />
<br />
mpd supports both local and remote use of PulseAudio.<br />
<br />
==== Local (as your own user) ====<br />
No special options are required; just add a pulse output as described in the comments of mpd's config file.<br />
<br />
==== Local (with separate mpd user) ====<br />
When run as its own user as per the wiki instructions, mpd will be unable to send sound to another user's pulseaudio server. Rather than setting up pulseaudio as a system-wide daemon, a practice strongly discouraged by upstream, you can instead configure mpd to use pulseaudio's tcp module to send sound to localhost:<br />
<br />
First, uncomment the tcp module in {{ic|/etc/pulse/default.pa}} or {{ic|$XDG_CONFIG_HOME/default.pa}} (typically {{ic|~/.config/pulse/default.pa}}) and set 127.0.0.1 as an allowed IP address; the home directory takes precedence:<br />
<br />
### Network access (may be configured with paprefs, so leave this commented<br />
### here if you plan to use paprefs)<br />
#load-module module-esound-protocol-tcp<br />
load-module module-native-protocol-tcp auth-ip-acl=127.0.0.1<br />
#load-module module-zeroconf-publish<br />
<br />
Additional IP ranges in cidr notation may be added using {{ic|;}} as the separator. Once this is complete, restart pulseaudio:<br />
$ pulseaudio --kill<br />
$ pulseaudio --start -or- start-pulseaudio-x11/kde<br />
<br />
Next, edit {{ic|/etc/mpd.conf}} and add a new pulse output pointing to 127.0.0.1 as a "remote" server:<br />
audio_output {<br />
type "pulse"<br />
name "Local Music Player Daemon"<br />
server "127.0.0.1"<br />
}<br />
<br />
Once this is added, restart mpd:<br />
# systemctl restart mpd<br />
<br />
Enable the output in mpd; you should now have a working local mpd, usable by all users whose pulseaudio servers allow sound from 127.0.0.1.<br />
<br />
==== Remote ====<br />
<br />
As with any PulseAudio-enabled program, mpd can send sound over the network. The complete PulseAudio system is not required on the server running mpd; {{Pkg|libpulse}} is the only requirement to act as a source and is already a dependency of mpd.<br />
<br />
In order to send audio from mpd to another computer follow the directions above, editing {{ic|/etc/mpd.conf}} on the server running mpd using the IP address of the target computer and {{ic|/etc/pulse/default.pa}} or {{ic|$XDG_CONFIG_HOME/default.pa}} (typically {{ic|~/.config/pulse/default.pa}}) on the target computer using the IP address of the server.<br />
<br />
Once this is done, the server's mpd source should show up on the target computer while playing or paused as a normal source able to be rerouted and controlled as usual; there will be no visible source on the target while mpd is stopped.<br />
<br />
=== Cue Files ===<br />
<br />
No additional steps are needed for cue support in mpd since 0.17. MPD has its own integrated parser which works with both external and embedded cuesheets.<br />
<br />
=== HTTP Streaming ===<br />
Since version 0.15 there is a built-in HTTP streaming daemon/server that comes with MPD. To activate this server simply set it as output device in mpd.conf:<br />
<br />
audio_output { <br />
type "httpd" <br />
name "My HTTP Stream" <br />
encoder "vorbis" # optional, vorbis or lame <br />
port "8000" <br />
# quality "5.0" # do not define if bitrate is defined <br />
bitrate "128" # do not define if quality is defined <br />
format "44100:16:1" <br />
}<br />
<br />
Then to listen to this stream simply open the URL of your mpd server (along with the specified port) in your favorite music player. Note: You may have to specify the file format of the stream using an appropriate file extension in the URL. For example, using Winamp 5.5, You would use http://192.168.1.2:8000/mpd.ogg rather than http://192.168.1.2:8000/.<br />
<br />
To use mpd to connect to the stream from another computer.<br />
<br />
mpc add http://192.168.1.2:8000</div>Rasihttps://wiki.archlinux.org/index.php?title=Systemd&diff=235518Systemd2012-11-15T10:13:51Z<p>Rasi: /* Installation */</p>
<hr />
<div>{{Lowercase title}}<br />
[[Category:Daemons and system services]]<br />
[[Category:Boot process]]<br />
[[es:Systemd]]<br />
[[fr:Systemd]]<br />
[[it:Systemd]]<br />
[[ja:Systemd]]<br />
[[ru:Systemd]]<br />
[[zh-CN:Systemd]]<br />
{{Article summary start}}<br />
{{Article summary text|Covers how to install and configure systemd.}}<br />
{{Article summary heading|Related}}<br />
{{Article summary wiki|systemd/User}}<br />
{{Article summary wiki|systemd/Services}}<br />
{{Article summary wiki|systemd FAQ}}<br />
{{Article summary wiki|init Rosetta}}<br />
{{Article summary wiki|udev}}<br />
{{Article summary end}}<br />
From the [http://freedesktop.org/wiki/Software/systemd project web page]:<br />
<br />
'''''systemd''' is a system and service manager for Linux, compatible with SysV and LSB init scripts. '''systemd''' provides aggressive parallelization capabilities, uses socket and [[D-Bus]] activation for starting services, offers on-demand starting of daemons, keeps track of processes using Linux [[cgroups|control groups]], supports snapshotting and restoring of the system state, maintains mount and automount points and implements an elaborate transactional dependency-based service control logic. It can work as a drop-in replacement for [[SysVinit|sysvinit]].''<br />
<br />
{{Note|1=For a detailed explanation as to why Arch has moved to systemd, see [https://bbs.archlinux.org/viewtopic.php?pid=1149530#p1149530 this forum post].}}<br />
<br />
See also the [[Wikipedia:Systemd|Wikipedia article]].<br />
<br />
== Considerations before switching ==<br />
<br />
* Check if you are already using systemd with the command {{ic| cat /proc/1/comm}}, where the output {{ic| init}} stands for sysvinit and {{ic|systemd}} for systemd.<br />
* It is highly recommended to switch to the new '''initscripts''' configuration system described in the [[rc.conf|rc.conf article]]. Once you have this configuration established, you will have done most of the work needed to make the switch to systemd.<br />
* Do [http://freedesktop.org/wiki/Software/systemd/ some reading] about systemd.<br />
* Note the fact that systemd has a '''journal''' system that replaces '''syslog''', although the two can co-exist. See the [[#Journal|section on the journal]] below.<br />
* While systemd can replace some of the functionality of '''cron''', '''acpid''', or '''xinetd''', there is no need to switch away from using the traditional daemons unless you want to.<br />
* Interactive initscripts are not working with systemd. In particular, '''netcfg-menu''' [https://bugs.archlinux.org/task/31377 cannot] be used at system start-up.<br />
<br />
== Installation ==<br />
{{Note|{{pkg|systemd}} and {{pkg|systemd-sysvcompat}} are both installed by default on installation media newer than [https://www.archlinux.org/news/systemd-is-now-the-default-on-new-installations/ 2012-10-13].}}<br />
The following section is aimed at Arch Linux installations that still rely on {{pkg|sysvinit}} and {{pkg|initscripts}} which have not migrated to {{pkg|systemd}}.<br />
<br />
# Install {{pkg|systemd}} and append the following to your [[kernel line]]: {{ic|1=init=/usr/lib/systemd/systemd}}<br />
# Once completed you may enable any desired services via the use of {{ic|systemctl enable <service_name>}} (this roughly equates to what you included in the {{ic|DAEMONS}} array).<br />
# Reboot your system and verify that {{ic|systemd}} is currently active by using the following command: {{ic|$ cat /proc/1/comm}}. This should return the string {{ic|systemd}}.<br />
# Proceed to remove {{pkg|initscripts}} and {{pkg|sysvinit}} from your system and install {{pkg|systemd-sysvcompat}}.<br />
# Finally, remove the {{ic|1=init=/usr/lib/systemd/systemd}} parameter as it is no longer required. (optional)<br />
<br />
=== Supplementary information ===<br />
<br />
* If you have {{ic|quiet}} in your kernel parameters, you might want to remove it for your first couple of systemd boots, to assist with identifying any issues during boot.<br />
<br />
* Adding your user to [[Users and Groups|groups]] ({{ic|optical}}, {{ic|audio}}, {{ic|scanner}}, etc.) is '''not''' necessary for most use cases with systemd. The groups can even cause some functionality to break. For example, the audio group will break fast user switching and allows applications to block software mixing. Every PAM login provides a logind session, which for a local session will give you permissions via [[Wikipedia:Access control list|POSIX ACLs]] on audio/video devices, and allow certain operations like mounting removable storage via [[udisks]].<br />
<br />
{{Note|Systemd-logind replaced [[ConsoleKit]], which was removed from the repositories, so a system must be booted with systemd to be fully functional. See [https://www.archlinux.org/news/consolekit-replaced-by-logind/ here] for more info.}}<br />
<br />
== Native configuration ==<br />
<br />
{{Note|You may need to create these files. All files should have '''644''' permissions and '''root:root''' ownership.}}<br />
<br />
=== Hostname ===<br />
<br />
The hostname is configured in {{ic|/etc/hostname}}. The file should not contain the system's domain, if any. To set the hostname, do:<br />
<br />
# hostnamectl set-hostname '''myhostname'''<br />
<br />
See {{ic|man 5 hostname}} and {{ic|man 1 hostnamectl}} for details.<br />
<br />
Here is an example file:<br />
{{hc|/etc/hostname|<br />
myhostname<br />
}}<br />
<br />
=== Locale ===<br />
<br />
The default system locale is configured in {{ic|/etc/locale.conf}}. To set the default locale, do:<br />
<br />
# localectl set-locale LANG="de_DE.utf8"<br />
<br />
{{Note|Before you set the default locale, you first need to enable locales available to the system by uncommenting them in {{ic|/etc/locale.gen}} and then executing {{ic|locale-gen}} as root. The locale set via {{ic|localectl}} must be one of the '''uncommented''' locales in {{ic|/etc/locale.gen}}.}}<br />
<br />
See {{ic|man 1 localectl}} and {{ic|man 5 locale.conf}} for details.<br />
<br />
* For more information, see [[Locale]].<br />
<br />
Here is an example file:<br />
{{hc|/etc/locale.conf|<nowiki><br />
LANG=en_US.utf8<br />
</nowiki>}}<br />
<br />
=== Virtual console ===<br />
<br />
The virtual console (keyboard mapping, console font and console map) is configured in {{ic|/etc/vconsole.conf}}:<br />
<br />
{{hc|/etc/vconsole.conf|2=<br />
KEYMAP=us<br />
FONT=lat9w-16<br />
FONT_MAP=8859-1_to_uni}}<br />
<br />
{{Note|As of {{pkg|systemd}}-194, the built-in ''kernel'' font and the ''us'' keymap are used if {{ic|1=KEYMAP=}} and {{ic|1=FONT=}} are empty or not set.}}<br />
<br />
Another way to set the keyboard mapping (keymap) is doing:<br />
<br />
# localectl set-keymap de<br />
<br />
This has the advantage that it will also set the same keymap for use in X11.<br />
<br />
See {{ic|man 1 localectl}} and {{ic|man 5 vconsole.conf}} for details.<br />
<br />
* For more information, see [[Fonts#Console fonts|console fonts]] and [[KEYMAP|keymaps]].<br />
<br />
=== Time zone ===<br />
<br />
The time zone is configured by creating an appropriate {{ic|/etc/localtime}} symlink, pointing to a zoneinfo file under {{ic|/usr/share/zoneinfo/}}. To do this automatically:<br />
<br />
# timedatectl set-timezone America/Toronto<br />
<br />
See {{ic|man 1 timedatectl}}, {{ic|man 5 localtime}}, and {{ic|man 7 archlinux}} for more details.<br />
<br />
Alternatively, create the symlink yourself:<br />
<!-- DO NOT MAKE THIS AN ABSOLUTE SYMLINK, archlinux(7) clearly shows this should be a relative symlink --><br />
# ln -sf ../usr/share/zoneinfo/America/Toronto /etc/localtime<br />
<br />
=== Hardware clock ===<br />
<br />
Systemd will use '''UTC''' for the hardware clock by default.<br />
<br />
{{Tip|It is advised to have a [[NTP|Network Time Protocol daemon]] running to keep the system time synchronized with Internet time and the hardware clock.}}<br />
<br />
==== Hardware clock in localtime ====<br />
<br />
If you want to change the hardware clock to use local time ('''STRONGLY DISCOURAGED''') do:<br />
<br />
# timedatectl set-local-rtc true<br />
<br />
If you want to revert to the hardware clock being in UTC, do:<br />
<br />
# timedatectl set-local-rtc false<br />
<br />
Be warned that, if the hardware clock is set to localtime, dealing with daylight saving time is messy. If the DST changes when your computer is off, your clock will be wrong on next boot ([http://www.cl.cam.ac.uk/~mgk25/mswish/ut-rtc.html there is a lot more to it]). Recent kernels set the system time from the RTC directly on boot, assuming that the RTC is in UTC. This means that if the RTC is in local time, then the system time will first be set up wrongly and then corrected shortly afterwards on every boot. This is the root of certain weird bugs (time going backwards is rarely a good thing).<br />
<br />
One reason for allowing the RTC to be in local time is to allow dual boot with Windows ([http://blogs.msdn.com/b/oldnewthing/archive/2004/09/02/224672.aspx which uses localtime]). However, Windows is able to deal with the RTC being in UTC with a simple [[Time#UTC in Windows|registry fix]]. There, it is recommended that Windows are changed to use UTC, rather than Linux to use localtime. If you make Windows use UTC, also remember to disable the "Internet Time Update" Windows feature, so that Windows don't mess with the hardware clock, trying to sync it with internet time. You should instead leave touching the RTC and syncing it to internet time to Linux, by enabling an [[NTP]] daemon, as suggested previously.<br />
<br />
* For more information, see [[Time]].<br />
<br />
=== Kernel modules ===<br />
<br />
Today, all necessary module loading is handled automatically by [[udev]], so that, if you don't want/need to use any out-of-tree kernel modules, there is no need to put modules that should be loaded at boot in any config file. However, there are cases where you might want to load an extra module during the boot process, or blacklist another one for your computer to function properly.<br />
<br />
==== Extra modules to load at boot ====<br />
<br />
Extra kernel modules to be loaded during boot are configured as a static list in files under {{ic|/etc/modules-load.d/}}. Each configuration file is named in the style of {{ic|/etc/modules-load.d/<program>.conf}}. Configuration files simply contain a list of kernel module names to load, separated by newlines. Empty lines and lines whose first non-whitespace character is {{ic|#}} or {{ic|;}} are ignored.<br />
<br />
{{hc|/etc/modules-load.d/virtio-net.conf|<br />
# Load virtio-net.ko at boot<br />
virtio-net}}<br />
<br />
See {{ic|man 5 modules-load.d}} for more details.<br />
<br />
==== Blacklisting ====<br />
<br />
Module blacklisting works the same way as with {{Pkg|initscripts}} since it is actually handled by {{Pkg|kmod}}. See [[Kernel modules#Blacklisting|Module Blacklisting]] for details.<br />
<br />
=== Filesystem mounts ===<br />
<br />
The default setup will automatically fsck and mount filesystems before starting services that need them to be mounted. For example, systemd automatically makes sure that remote filesystem mounts like [[NFS]] or [[Samba]] are only started after the network has been set up. Therefore, local and remote filesystem mounts specified in {{ic|/etc/fstab}} should work out of the box.<br />
<br />
See {{ic|man 5 systemd.mount}} for details.<br />
<br />
==== Automount ====<br />
<br />
* If you have a large {{ic|/home}} partition, it might be better to allow services that do not depend on {{ic|/home}} to start while {{ic|/home}} is being fsck'ed. This can be achieved by adding the following options to the {{ic|/etc/fstab}} entry of your {{ic|/home}} partition:<br />
<br />
noauto,x-systemd.automount<br />
<br />
This will fsck and mount {{ic|/home}} when it is first accessed, and the kernel will buffer all file access to {{ic|/home}} until it is ready.<br />
<br />
* The same applies to remote filesystem mounts. If you want them to be mounted only upon access, you will need to use the {{ic|noauto,x-systemd.automount}} parameters. In addition, you can use the {{ic|1=x-systemd.device-timeout=#}} option to specify a timeout in case the network resource is not available.<br />
<br />
* If you have encrypted filesystems with keyfiles, you can also add the {{ic|noauto}} parameter to the corresponding entries in {{ic|/etc/crypttab}}. Systemd will then not open the encrypted device on boot, but instead wait until it is actually accessed and then automatically open it with the specified keyfile before mounting it. This might save a few seconds on boot if you are using an encrypted RAID device for example, because systemd doesn't have to wait for the device to become available. For example:<br />
<br />
{{hc|/etc/crypttab|<br />
data /dev/md0 /root/key noauto}}<br />
<br />
==== LVM ====<br />
<br />
If you have LVM volumes not activated via the [[Mkinitcpio|initramfs]], enable {{ic|lvm.service}} (provided by the {{pkg|lvm2}} package):<br />
<br />
# systemctl enable lvm<br />
<br />
Similarly, if you have LVM on encrypted devices mounted later during boot (e.g. from {{ic|/etc/crypttab}}), enable {{ic|lvm-on-crypt.service}} (also provided by the {{pkg|lvm2}} package):<br />
<br />
# systemctl enable lvm-on-crypt<br />
<br />
=== ACPI power management ===<br />
<br />
Systemd handles some power-related [[Wikipedia:Advanced_Configuration_and_Power_Interface|ACPI]] events. They can be configured via the following options from {{ic|/etc/systemd/logind.conf}}:<br />
<br />
* {{ic|HandlePowerKey}}: specifies which action is invoked when the power key is pressed.<br />
* {{ic|HandleSuspendKey}}: specifies which action is invoked when the suspend key is pressed.<br />
* {{ic|HandleHibernateKey}}: specifies which action is invoked when the hibernate key is pressed.<br />
* {{ic|HandleLidSwitch}}: specifies which action is invoked when the lid is closed.<br />
<br />
The specified action can be one of {{ic|ignore}}, {{ic|poweroff}}, {{ic|reboot}}, {{ic|halt}}, {{ic|suspend}}, {{ic|hibernate}} or {{ic|kexec}}.<br />
<br />
If these options are not configured, systemd will use its defaults: {{ic|1=HandlePowerKey=poweroff}}, {{ic|1=HandleSuspendKey=suspend}}, {{ic|1=HandleHibernateKey=hibernate}}, and {{ic|1=HandleLidSwitch=suspend}}.<br />
<br />
On systems which run no graphical setup or only a simple window manager like [[i3]] or [[awesome]], this may replace the [[acpid]] daemon which is usually used to react to these ACPI events.<br />
<br />
In the current version of systemd, the {{ic|Handle}} options will apply throughout the system unless they are "inhibited" (temporarily turned off) by a program, such as a power manager inside a desktop environment. If these inhibits are not taken, you can end up with a situation where systemd suspends your system, then when it wakes up the other power manager suspends it again.<br />
<br />
{{Warning|Currently, the power managers in the newest versions of [[KDE]] and [[GNOME]] are the only ones that issue the necessary "inhibited" commands. Until the others do, you will need to set the {{ic|Handle}} options to {{ic|ignore}} if you want your ACPI events to be handled by [[Xfce]], [[acpid]] or other programs. New versions are on the way that will include this functionality.}}<br />
<br />
{{Note|Systemd can also use other suspend backends (such as [[Uswsusp]] or [[TuxOnIce]]), in addition to the default ''kernel'' backend, in order to put the computer to sleep or hibernate.}}<br />
<br />
==== Sleep hooks ====<br />
<br />
Systemd does not use [[pm-utils]] to put the machine to sleep when using {{ic|systemctl suspend}} or {{ic|systemctl hibernate}}; [[pm-utils]] hooks, including any [[Pm-utils#Creating_your_own_hooks|custom hooks]], will not be run. However, systemd provides a similar mechanism to run custom scripts on these events. Systemd runs all executables in {{ic|/usr/lib/systemd/system-sleep/}}, passing two arguments to each of them:<br />
<br />
* Argument 1: either {{ic|pre}} or {{ic|post}}, depending on whether the machine is going to sleep or waking up<br />
* Argument 2: either {{ic|suspend}} or {{ic|hibernate}}, depending on which is being invoked<br />
<br />
In contrast to [[pm-utils]], systemd will run these scripts concurrently and not one after another.<br />
<br />
The output of any custom script will be logged by {{ic|systemd-suspend.service}} or {{ic|systemd-hibernate.service}}. You can see its output in systemd's [[Systemd#Journal|journal]]:<br />
# journalctl -b -u systemd-suspend<br />
<br />
Note that you can also use {{ic|sleep.target}}, {{ic|suspend.target}} or {{ic|hibernate.target}} to hook units into the sleep state logic instead of using custom scripts.<br />
<br />
An example of a custom sleep script:<br />
<br />
{{hc|/usr/lib/systemd/system-sleep/example.sh|<br />
#!/bin/sh<br />
case $1/$2 in<br />
pre/*)<br />
echo "Going to $2..."<br />
;;<br />
post/*)<br />
echo "Waking up from $2..."<br />
;;<br />
esac}}<br />
<br />
See {{ic|man 7 systemd.special}} and {{ic|man 8 systemd-sleep}} for more details.<br />
<br />
=== Temporary files ===<br />
<br />
Systemd-tmpfiles uses configuration files in {{ic|/usr/lib/tmpfiles.d/}} and {{ic|/etc/tmpfiles.d/}} to describe the creation, cleaning and removal of volatile and temporary files and directories which usually reside in directories such as {{ic|/run}} or {{ic|/tmp}}. Each configuration file is named in the style of {{ic|/etc/tmpfiles.d/<program>.conf}}. This will also override any files in {{ic|/usr/lib/tmpfiles.d/}} with the same name.<br />
<br />
tmpfiles are usually provided together with service files to create directories which are expected to exist by certain daemons. For example the [[Samba]] daemon expects the directory {{ic|/var/run/samba}} to exist and to have the correct permissions. The corresponding tmpfile looks like this:<br />
<br />
{{hc|/usr/lib/tmpfiles.d/samba.conf|<br />
D /var/run/samba 0755 root root}}<br />
<br />
However, tmpfiles may also be used to write values into certain files on boot. For example, if you use {{ic|/etc/rc.local}} to disable wakeup from USB devices with {{ic|echo USBE > /proc/acpi/wakeup}}, you may use the following tmpfile instead:<br />
<br />
{{hc|/etc/tmpfiles.d/disable-usb-wake.conf|<br />
w /proc/acpi/wakeup - - - - USBE}}<br />
<br />
The tmpfiles method is recommended in this case since systemd doesn't actually support {{ic|/etc/rc.local}}.<br />
<br />
See {{ic|man 5 tmpfiles.d}} for details.<br />
<br />
=== Units ===<br />
<br />
A unit configuration file encodes information about a service, a socket, a device, a mount point, an automount point, a swap file or partition, a start-up target, a file system path or a timer controlled and supervised by systemd. The syntax is inspired by XDG Desktop Entry Specification .desktop files, which are in turn inspired by Microsoft Windows .ini files.<br />
<br />
See {{ic|man 5 systemd.unit}} for details.<br />
<br />
== Transitioning from initscripts to systemd ==<br />
<br />
=== Initscripts emulation ===<br />
<br />
Integration with Arch's classic configuration is provided by the {{Pkg|initscripts}} package. When {{Pkg|initscripts}} are installed in parallel with systemd, with the system running on systemd, systemd will do the following:<br />
<br />
# Parse the {{ic|DAEMONS}} array of {{ic|/etc/rc.conf}} and start all listed daemons at boot<br />
# Execute {{ic|/etc/rc.local}} during boot<br />
# Execute {{ic|/etc/rc.local.shutdown}} during shutdown<br />
<br />
Initscripts emulation is simply meant as a transitional measure to ease users' move to systemd, and '''will eventually go away'''. Native systemd does not rely on {{ic|rc.conf}} centralised configuration, so it is recommended to use [[#Native configuration|native systemd configuration files]], which will take precedence over {{ic|/etc/rc.conf}}.<br />
<br />
{{Note|The recommended way to replace {{ic|/etc/rc.local}} is to write the custom service files for any things you want to run on the system startup. See the corresponding [[#Writing_custom_.service_files|section]].}}<br />
<br />
{{Note|If you disabled {{keypress|Ctrl+Alt+Del}} to reboot in {{ic|/etc/inittab}}, you will have to reconfigure this setting for systemd by running {{ic|systemctl mask ctrl-alt-del.target}} as root.}}<br />
<br />
=== Moving away from the DAEMONS array ===<br />
<br />
For a pure systemd setup, you should remove the {{ic|/etc/rc.conf}} file entirely and enable services only via {{ic|systemctl}}. For each {{ic|<service_name>}} in the {{ic|DAEMONS}} array in {{ic|/etc/rc.conf}}, run:<br />
<br />
# systemctl enable <service_name><br />
<br />
{{Tip|For a list of commonly used daemons with their initscripts and systemd equivalents, see [[Daemons List|this table]].}}<br />
<br />
If {{ic|<service_name>.service}} does not exist:<br />
<br />
* Most probably, systemd uses a different name. For example, {{ic|cronie.service}} replaces the {{ic|crond}} init daemon; {{ic|alsa-store.service}} and {{ic|alsa-restore.service}} replace the {{ic|alsa}} init daemon. Another important instance is the {{ic|network}} daemon, which is replaced with another set of service files (see [[Configuring Network]] for more details.)<br />
* Otherwise, a service file may not be available for systemd. In that case, you'll need to keep {{ic|rc.conf}} to start the service during boot up.<br />
<br />
{{Tip|You may look inside a package that contains daemon start scripts for service names. For instance:<br />
$ pacman -Ql cronie<br />
[...]<br />
cronie /etc/rc.d/crond #Daemon initscript listed in the DAEMONS array (unused in a "pure" systemd configuration)<br />
[...]<br />
cronie /usr/lib/systemd/system/cronie.service #Corresponding systemd daemon service<br />
[...]<br />
}}<br />
<br />
* Finally, some services do not need to be explicitly enabled by the user. For instance, {{ic|dbus.service}} will automatically be enabled when {{ic|dbus-core}} is installed. {{ic|alsa-store.service}} and {{ic|alsa-restore.service}} are also enabled automatically by systemd. Check the list of available services and their state using the {{ic|systemctl}} command like this: {{ic|systemctl status <service_name>}}.<br />
<br />
== Basic systemctl usage ==<br />
<br />
The main command used to introspect and control systemd is {{ic|systemctl}}. Some of its uses are examining the system state and managing the system and services. See {{ic|man 1 systemctl}} for more details.<br />
<br />
{{Tip|You can use all of the following {{ic|systemctl}} commands with the {{ic|-H <user>@<host>}} switch to control a systemd instance on a remote machine. This will use [[SSH]] to connect to the remote systemd instance.}}<br />
<br />
{{Note|{{ic|systemadm}} is the official graphical frontend for {{ic|systemctl}}. It is provided by the {{AUR|systemd-ui-git}} package from the [[AUR]].}}<br />
<br />
=== Analyzing the system state ===<br />
<br />
List running units:<br />
<br />
$ systemctl<br />
<br />
or:<br />
<br />
$ systemctl list-units<br />
<br />
List failed units:<br />
<br />
$ systemctl --failed<br />
<br />
The available unit files can be seen in {{ic|/usr/lib/systemd/system/}} and {{ic|/etc/systemd/system/}} (the latter takes precedence). You can see list installed unit files by:<br />
<br />
$ systemctl list-unit-files<br />
<br />
=== Using units ===<br />
<br />
Units can be, for example, services ({{ic|.service}}), mount points ({{ic|.mount}}), devices ({{ic|.device}}) or sockets ({{ic|.socket}}).<br />
<br />
When using {{ic|systemctl}}, you generally have to specify the complete name of the unit file, including its suffix, for example {{ic|sshd.socket}}. There are however a few shortforms when specifying the unit in the following {{ic|systemctl}} commands:<br />
<br />
* If you don't specify the suffix, systemctl will assume {{ic|.service}}. For example, {{ic|netcfg}} and {{ic|netcfg.service}} are treated equivalent.<br />
* Mount points will automatically be translated into the appropriate {{ic|.mount}} unit. For example, specifying {{ic|/home}} is equivalent to {{ic|home.mount}}.<br />
* Similiar to mount points, devices are automatically translated into the appropriate {{ic|.device}} unit, therefore specifying {{ic|/dev/sda2}} is equivalent to {{ic|dev-sda2.device}}.<br />
<br />
See {{ic|man systemd.unit}} for details.<br />
<br />
Activate a unit immediately:<br />
<br />
# systemctl start <unit><br />
<br />
Deactivate a unit immediately:<br />
<br />
# systemctl stop <unit><br />
<br />
Restart a unit:<br />
<br />
# systemctl restart <unit><br />
<br />
Ask a unit to reload its configuration:<br />
<br />
# systemctl reload <unit><br />
<br />
Show the status of a unit, including whether it is running or not:<br />
<br />
$ systemctl status <unit><br />
<br />
Check whether a unit is already enabled or not:<br />
<br />
$ systemctl is-enabled <unit><br />
<br />
Enable a unit to be started on bootup:<br />
<br />
# systemctl enable <unit><br />
<br />
{{Note|If services do not have an {{ic|Install}} section, it usually means they are called automatically by other services. But if you need to install them manually, use the following command, replacing {{ic|foo}} with the name of the service.<br />
# ln -s /usr/lib/systemd/system/''foo''.service /etc/systemd/system/graphical.target.wants/<br />
}}<br />
<br />
Disable a unit to not start during bootup:<br />
<br />
# systemctl disable <unit><br />
<br />
Show the manual page associated with a unit (this has to be supported by the unit file):<br />
<br />
$ systemctl help <unit><br />
<br />
=== Power management ===<br />
<br />
If you are in a local {{ic|systemd-logind}} user session and no other session is active, the following commands will work without root privileges. If not (for example, because another user is logged into a tty), systemd will automatically ask you for the root password.<br />
<br />
Shut down and reboot the system:<br />
<br />
$ systemctl reboot<br />
<br />
Shut down and power-off the system:<br />
<br />
$ systemctl poweroff<br />
<br />
Shut down and halt the system:<br />
<br />
$ systemctl halt<br />
<br />
Suspend the system:<br />
<br />
$ systemctl suspend<br />
<br />
Put the system into hibernation:<br />
<br />
$ systemctl hibernate<br />
<br />
== Running DEs under systemd ==<br />
<br />
To enable graphical login, run your preferred [[Display Manager]] daemon (e.g. [[KDM]]). At the moment, service files exist for [[GDM]], [[KDM]], [[SLiM]], [[XDM]], [[LXDM]] and [[LightDM]].<br />
<br />
# systemctl enable kdm<br />
<br />
This should work out of the box. If not, you might have a {{ic|default.target}} set manually or from a older install:<br />
<br />
{{hc|# ls -l /etc/systemd/system/default.target|<br />
/etc/systemd/system/default.target -> /usr/lib/systemd/system/graphical.target}}<br />
<br />
Simply delete the symlink and systemd will use its stock {{ic|default.target}} (i.e. {{ic|graphical.target}}).<br />
<br />
# rm /etc/systemd/system/default.target<br />
<br />
=== Using systemd-logind ===<br />
<br />
{{Note|As of 2012-10-30, [[ConsoleKit]] has been [https://www.archlinux.org/news/consolekit-replaced-by-logind/ replaced by systemd-logind] as the default mechanism to login to the DE.}}<br />
<br />
In order to check the status of your user session, you can use {{ic|loginctl}}. All [[PolicyKit]] actions like suspending the system or mounting external drives will work out of the box.<br />
<br />
$ loginctl show-session $XDG_SESSION_ID<br />
<br />
== Writing custom .service files ==<br />
<br />
=== Handling dependencies ===<br />
<br />
With systemd, dependencies can be resolved by designing the unit files correctly. The most typical case is that the unit {{ic|A}} requires the unit {{ic|B}} to be running before {{ic|A}} is started. In that case add {{ic|1=Requires=B}} and {{ic|1=After=B}} to the {{ic|[Unit]}} section of {{ic|A}}. If the dependency is optional, add {{ic|1=Wants=B}} and {{ic|1=After=B}} instead. Note that {{ic|1=Wants=}} and {{ic|1=Requires=}} do not imply {{ic|1=After=}}, meaning that if {{ic|1=After=}} is not specified, the two units will be started in parallel.<br />
<br />
Dependencies are typically placed on services and not on targets. For example, {{ic|network.target}} is pulled in by whatever service configures your network interfaces, therefore ordering your custom unit after it is sufficient since {{ic|network.target}} is started anyway.<br />
<br />
=== Type ===<br />
<br />
There are several different start-up types to consider when writing a custom service file. This is set with the {{ic|1=Type=}} parameter in the {{ic|[Service]}} section. See {{ic|man systemd.service}} for a more detailed explanation.<br />
<br />
* {{ic|1=Type=simple}}: systemd considers the service to be started up immediately. The process must not fork. Do not use this type if other services need to be ordered on this service, unless it is socket activated.<br />
* {{ic|1=Type=forking}}: systemd considers the service started up once the process forks and the parent has exited. For classic daemons use this type unless you know that it is not necessary. You should specify {{ic|1=PIDFile=}} as well so systemd can keep track of the main process.<br />
* {{ic|1=Type=oneshot}}: This is useful for scripts that do a single job and then exit. You may want to set {{ic|1=RemainAfterExit=}} as well so that systemd still considers the service as active after the process has exited.<br />
* {{ic|1=Type=notify}}: Identical to {{ic|1=Type=simple}}, but with the stipulation that the daemon will send a signal to systemd when it is ready. The reference implementation for this notification is provided by {{ic|libsystemd-daemon.so}}.<br />
* {{ic|1=Type=dbus}}: The service is considered ready when the specified {{ic|BusName}} appears on DBus's system bus.<br />
<br />
=== Replacing provided unit files ===<br />
<br />
The unit files in {{ic|/etc/systemd/system/}} take precedence over the ones in {{ic|/usr/lib/systemd/system/}}.<br />
To make your own version of a unit (which will not be destroyed by an upgrade), copy the old unit file from {{ic|/usr/lib/}} to {{ic|/etc/}} and make your changes there. Alternatively you can use {{ic|.include}} to parse an existing service file and then override or add new options. For example, if you simply want to add an additional dependency to a service file, you may use:<br />
<br />
{{hc|/etc/systemd/system/<service-name>.service|2=<br />
.include /usr/lib/systemd/system/<service-name>.service<br />
<br />
[Unit]<br />
Requires=<new dependency><br />
After=<new dependency>}}<br />
<br />
Then run the following for your changes to take effect:<br />
<br />
# systemctl reenable <unit><br />
# systemctl restart <unit><br />
<br />
{{Tip|You can use {{ic|systemd-delta}} to see which unit files have been overridden and what exactly has been changed.}}<br />
<br />
=== Syntax highlighting for units within Vim ===<br />
<br />
Syntax highlighting for systemd unit files within [[Vim]] can be enabled by installing {{AUR|vim-systemd}} from the [[Arch User Repository|AUR]].<br />
<br />
== Targets ==<br />
<br />
Systemd uses ''targets'' which serve a similar purpose as runlevels but act a little different. Each ''target'' is named instead of numbered and is intended to serve a specific purpose with the possibility of having multiple ones active at the same time. Some ''targets'' are implemented by inheriting all of the services of another ''target'' and adding additional services to it. There are systemd ''target''s that mimic the common SystemVinit runlevels so you can still switch ''target''s using the familiar {{ic|telinit RUNLEVEL}} command.<br />
<br />
=== Get current targets ===<br />
<br />
The following should be used under systemd instead of {{ic|runlevel}}:<br />
<br />
$ systemctl list-units --type=target<br />
<br />
=== Create custom target ===<br />
<br />
The runlevels that are assigned a specific purpose on vanilla Fedora installs; 0, 1, 3, 5, and 6; have a 1:1 mapping with a specific systemd ''target''. Unfortunately, there is no good way to do the same for the user-defined runlevels like 2 and 4. If you make use of those it is suggested that you make a new named systemd ''target'' as {{ic|/etc/systemd/system/<your target>}} that takes one of the existing runlevels as a base (you can look at {{ic|/usr/lib/systemd/system/graphical.target}} as an example), make a directory {{ic|/etc/systemd/system/<your target>.wants}}, and then symlink the additional services from {{ic|/usr/lib/systemd/system/}} that you wish to enable.<br />
<br />
=== Targets table ===<br />
<br />
{| border="1"<br />
! SysV Runlevel !! systemd Target !! Notes<br />
|-<br />
| 0 || runlevel0.target, poweroff.target || Halt the system.<br />
|-<br />
| 1, s, single || runlevel1.target, rescue.target || Single user mode.<br />
|-<br />
| 2, 4 || runlevel2.target, runlevel4.target, multi-user.target || User-defined/Site-specific runlevels. By default, identical to 3.<br />
|-<br />
| 3 || runlevel3.target, multi-user.target || Multi-user, non-graphical. Users can usually login via multiple consoles or via the network.<br />
|-<br />
| 5 || runlevel5.target, graphical.target || Multi-user, graphical. Usually has all the services of runlevel 3 plus a graphical login.<br />
|-<br />
| 6 || runlevel6.target, reboot.target || Reboot<br />
|-<br />
| emergency || emergency.target || Emergency shell<br />
|-<br />
|}<br />
<br />
=== Change current target ===<br />
<br />
In systemd targets are exposed via "target units". You can change them like this:<br />
<br />
# systemctl isolate graphical.target<br />
<br />
This will only change the current target, and has no effect on the next boot. This is equivalent to commands such as {{ic|telinit 3}} or {{ic|telinit 5}} in Sysvinit.<br />
<br />
=== Change default target to boot into ===<br />
<br />
The standard target is {{ic|default.target}}, which is aliased by default to {{ic|graphical.target}} (which roughly corresponds to the old runlevel 5). To change the default target at boot-time, append one of the following [[kernel parameters]] to your bootloader:<br />
<br />
{{Tip|The {{ic|.target}} extension can be left out.}}<br />
<br />
* {{ic|1=systemd.unit=multi-user.target}} (which roughly corresponds to the old runlevel 3),<br />
* {{ic|1=systemd.unit=rescue.target}} (which roughly corresponds to the old runlevel 1).<br />
<br />
Alternatively, you may leave the bootloader alone and change {{ic|default.target}}. This can be done using {{ic|systemctl}}:<br />
<br />
# systemctl enable multi-user.target<br />
<br />
The effect of this command is outputted by {{ic|systemctl}}; a symlink to the new default target is made at {{ic|/etc/systemd/system/default.target}}. This works if, and only if:<br />
<br />
[Install]<br />
Alias=default.target<br />
<br />
is in the target's configuration file. Currently, {{ic|multi-user.target}} and {{ic|graphical.target}} both have it.<br />
<br />
== Journal ==<br />
<br />
Since version 38, systemd has its own logging system, the journal. Therefore, running a syslog daemon is no longer required. To read the log, use:<br />
<br />
# journalctl<br />
<br />
By default (when {{ic|Storage&#61;}} is set to {{ic|auto}} in {{ic|/etc/systemd/journald.conf}}), the journal writes to {{ic|/var/log/journal/}}. If the directory {{ic|/var/log/journal/}} does not exist (e.g. if you or some program delete it), systemd will '''not''' create it automatically, but instead write its logs to {{ic|/run/systemd/journal}}. This means that logs will be lost on reboot.<br />
<br />
=== Filtering output ===<br />
<br />
{{ic|journalctl}} allows you to filter the output by specific fields.<br />
<br />
Examples:<br />
<br />
Show all messages from this boot:<br />
<br />
# journalctl -b<br />
<br />
Follow new messages:<br />
<br />
# journalctl -f<br />
<br />
Show all messages by a specific executable:<br />
<br />
# journalctl /usr/lib/systemd/systemd<br />
<br />
Show all messages by a specific process:<br />
<br />
# journalctl _PID=1<br />
<br />
Show all messages by a specific unit:<br />
<br />
# journalctl -u netcfg<br />
<br />
See {{ic|man journalctl}}, {{ic|systemd.journal-fields}} or Lennert's [http://0pointer.de/blog/projects/journalctl.html blog post] for details.<br />
<br />
=== Journal size limit ===<br />
<br />
If the journal is persistent (non-volatile), its size limit is set to a default value of 10% of the size of the respective file system. E.g. with {{ic|/var/log/journal}} located on a 50 GiB root partition this would lead to 5 GiB of journal data. The maximum size of the persistent journal can be controlled by {{ic|SystemMaxUse}} in {{ic|/etc/systemd/journald.conf}}, so to limit it for example to 50 MiB uncomment and edit the corresponding line to:<br />
<br />
SystemMaxUse=50M<br />
<br />
Refer to {{ic|man journald.conf}} for more info.<br />
<br />
=== Journald in conjunction with syslog ===<br />
<br />
Compatibility with classic syslog implementations is provided via a socket {{ic|/run/systemd/journal/syslog}}, to which all messages are forwarded. To make the syslog daemon work with the journal, it has to bind to this socket instead of {{ic|/dev/log}} ([http://lwn.net/Articles/474968/ official announcement]). The {{pkg|syslog-ng}} package in the repositories automatically provides the necessary configuration.<br />
<br />
# systemctl enable syslog-ng<br />
<br />
== Optimization ==<br />
<br />
=== Analyzing the boot process ===<br />
<br />
==== Using systemd-analyze ====<br />
<br />
Systemd provides a tool called {{ic|systemd-analyze}} that allows you to analyze your boot process so you can see which unit files are causing your boot process to slow down. You can then optimize your system accordingly. You have to install {{Pkg|python2-dbus}} and {{Pkg|python2-cairo}} to use it.<br />
<br />
To see how much time was spent in kernelspace and userspace on boot, simply use:<br />
<br />
$ systemd-analyze<br />
<br />
{{Tip|To see how much time was spent in the initramfs, append the {{ic|timestamp}} hook to your {{ic|HOOKS}} array in {{ic|/etc/[[mkinitcpio]].conf}} and as root, rebuild your initramfs with {{ic|mkinitcpio -p linux}} }}<br />
<br />
To list the started unit files, sorted by the time each of them took to start up:<br />
<br />
$ systemd-analyze blame<br />
<br />
You can also create a SVG file which describes your boot process graphically, similiar to [[Bootchart]]:<br />
<br />
$ systemd-analyze plot > plot.svg<br />
<br />
==== Using bootchart ====<br />
<br />
You could also use a version of bootchart to visualize the boot sequence. Since you are not able to put a second init into the kernel command line you won't be able to use any of the standard bootchart setups. However the {{AUR|bootchart2}} package from [[AUR]] comes with an undocumented systemd service. After you've installed bootchart2 do:<br />
<br />
# systemctl enable bootchart<br />
<br />
Read the [https://github.com/mmeeks/bootchart bootchart documentation] for further details on using this version of bootchart.<br />
<br />
=== Readahead ===<br />
<br />
Systemd comes with its own readahead implementation, this should in principle improve boot time. However, depending on your kernel version and the type of your hard drive, your mileage may vary (i.e. it might be slower). To enable, do:<br />
<br />
# systemctl enable systemd-readahead-collect systemd-readahead-replay<br />
<br />
Remember that in order for the readahead to work its magic, you should reboot a couple of times.<br />
<br />
=== Early start for services ===<br />
<br />
One central feature of systemd is [[D-Bus]] and socket activation. This causes services to be started when they are first accessed and is generally a good thing. However, if you know that a service (like [[UPower]]) will always be started during boot, then the overall boot time might be reduced by starting it as early as possible. This can be achieved (if the service file is set up for it, which in most cases it is) by issuing:<br />
<br />
# systemctl enable upower<br />
<br />
This will cause systemd to start UPower as soon as possible, without causing races with the socket or D-Bus activation.<br />
<br />
=== Less output during boot ===<br />
<br />
Change {{ic|verbose}} to {{ic|quiet}} on the bootloader's kernel line. For some systems, particularly those with an SSD, the slow performance of the TTY is actually a bottleneck, and so less output means faster booting.<br />
<br />
== Troubleshooting ==<br />
<br />
=== Shutdown/reboot takes terribly long ===<br />
<br />
If the shutdown process takes a very long time (or seems to freeze) most likely a service not exiting is to blame. Systemd waits some time for each service to exit before trying to kill it. To find out if you are affected, see [http://freedesktop.org/wiki/Software/systemd/Debugging#Shutdown_Completes_Eventually this article].<br />
<br />
== See also ==<br />
<br />
*[http://www.freedesktop.org/wiki/Software/systemd Official Web Site]<br />
*[http://0pointer.de/public/systemd-man/ Manual Pages]<br />
*[http://freedesktop.org/wiki/Software/systemd/Optimizations systemd Optimizations]<br />
*[http://www.freedesktop.org/wiki/Software/systemd/FrequentlyAskedQuestions FAQ]<br />
*[http://www.freedesktop.org/wiki/Software/systemd/TipsAndTricks Tips And Tricks]<br />
*[http://0pointer.de/public/systemd-ebook-psankar.pdf systemd for Administrators (PDF)]<br />
*[http://fedoraproject.org/wiki/Systemd About systemd on Fedora Project]<br />
*[http://fedoraproject.org/wiki/How_to_debug_Systemd_problems How to debug systemd problems]<br />
*[http://www.h-online.com/open/features/Booting-up-Tools-and-tips-for-systemd-1570630.html Booting up: Tools and tips for systemd, a Linux init tool. In The H]<br />
*[http://0pointer.de/blog/projects/systemd.html Lennart's blog story]<br />
*[http://0pointer.de/blog/projects/systemd-update.html status update]<br />
*[http://0pointer.de/blog/projects/systemd-update-2.html status update2]<br />
*[http://0pointer.de/blog/projects/systemd-update-3.html status update3]<br />
*[http://0pointer.de/blog/projects/why.html most recent summary]<br />
*[http://fedoraproject.org/wiki/SysVinit_to_Systemd_Cheatsheet Fedora's SysVinit to systemd cheatsheet]</div>Rasihttps://wiki.archlinux.org/index.php?title=Systemd&diff=235517Systemd2012-11-15T10:13:21Z<p>Rasi: /* Installation */</p>
<hr />
<div>{{Lowercase title}}<br />
[[Category:Daemons and system services]]<br />
[[Category:Boot process]]<br />
[[es:Systemd]]<br />
[[fr:Systemd]]<br />
[[it:Systemd]]<br />
[[ja:Systemd]]<br />
[[ru:Systemd]]<br />
[[zh-CN:Systemd]]<br />
{{Article summary start}}<br />
{{Article summary text|Covers how to install and configure systemd.}}<br />
{{Article summary heading|Related}}<br />
{{Article summary wiki|systemd/User}}<br />
{{Article summary wiki|systemd/Services}}<br />
{{Article summary wiki|systemd FAQ}}<br />
{{Article summary wiki|init Rosetta}}<br />
{{Article summary wiki|udev}}<br />
{{Article summary end}}<br />
From the [http://freedesktop.org/wiki/Software/systemd project web page]:<br />
<br />
'''''systemd''' is a system and service manager for Linux, compatible with SysV and LSB init scripts. '''systemd''' provides aggressive parallelization capabilities, uses socket and [[D-Bus]] activation for starting services, offers on-demand starting of daemons, keeps track of processes using Linux [[cgroups|control groups]], supports snapshotting and restoring of the system state, maintains mount and automount points and implements an elaborate transactional dependency-based service control logic. It can work as a drop-in replacement for [[SysVinit|sysvinit]].''<br />
<br />
{{Note|1=For a detailed explanation as to why Arch has moved to systemd, see [https://bbs.archlinux.org/viewtopic.php?pid=1149530#p1149530 this forum post].}}<br />
<br />
See also the [[Wikipedia:Systemd|Wikipedia article]].<br />
<br />
== Considerations before switching ==<br />
<br />
* Check if you are already using systemd with the command {{ic| cat /proc/1/comm}}, where the output {{ic| init}} stands for sysvinit and {{ic|systemd}} for systemd.<br />
* It is highly recommended to switch to the new '''initscripts''' configuration system described in the [[rc.conf|rc.conf article]]. Once you have this configuration established, you will have done most of the work needed to make the switch to systemd.<br />
* Do [http://freedesktop.org/wiki/Software/systemd/ some reading] about systemd.<br />
* Note the fact that systemd has a '''journal''' system that replaces '''syslog''', although the two can co-exist. See the [[#Journal|section on the journal]] below.<br />
* While systemd can replace some of the functionality of '''cron''', '''acpid''', or '''xinetd''', there is no need to switch away from using the traditional daemons unless you want to.<br />
* Interactive initscripts are not working with systemd. In particular, '''netcfg-menu''' [https://bugs.archlinux.org/task/31377 cannot] be used at system start-up.<br />
<br />
== Installation ==<br />
{{Note|{{pkg|systemd}} and {{pkg|systemd-sysvcompat}} are both installed by default on installation media newer than [https://www.archlinux.org/news/systemd-is-now-the-default-on-new-installations/ 2012-10-13].}}<br />
The following section is aimed at Arch Linux installations that still rely on {{pkg|sysvinit}} and {{pkg|initscripts}} which have not migrated to {{pkg|systemd}}.<br />
<br />
# Install {{pkg|systemd}} and append the following to your [[kernel line]]: {{ic|1=init=/usr/lib/systemd/systemd}}<br />
# Once completed you may enable any desired services via the use of {{ic|systemctl enable <service_name>}} (this roughly equates to what you included in the {{ic|DAEMONS}} array).<br />
# Reboot your system and verify that {{ic|systemd}} is currently active by using the following command: {{ic|$ cat /proc/1/comm}}. This should return the string {{ic|systemd}}.<br />
# Proceed to remove {{pkg|initscripts}} and {{pkg|sysvinit}} from your system and install {{pkg|systemd-sysvcompat}}.<br />
# Finally, remove the {{ic|1=init=/usr/lib/systemd/systemd}} parameter as it is no longer required.<br />
<br />
=== Supplementary information ===<br />
<br />
* If you have {{ic|quiet}} in your kernel parameters, you might want to remove it for your first couple of systemd boots, to assist with identifying any issues during boot.<br />
<br />
* Adding your user to [[Users and Groups|groups]] ({{ic|optical}}, {{ic|audio}}, {{ic|scanner}}, etc.) is '''not''' necessary for most use cases with systemd. The groups can even cause some functionality to break. For example, the audio group will break fast user switching and allows applications to block software mixing. Every PAM login provides a logind session, which for a local session will give you permissions via [[Wikipedia:Access control list|POSIX ACLs]] on audio/video devices, and allow certain operations like mounting removable storage via [[udisks]].<br />
<br />
{{Note|Systemd-logind replaced [[ConsoleKit]], which was removed from the repositories, so a system must be booted with systemd to be fully functional. See [https://www.archlinux.org/news/consolekit-replaced-by-logind/ here] for more info.}}<br />
<br />
== Native configuration ==<br />
<br />
{{Note|You may need to create these files. All files should have '''644''' permissions and '''root:root''' ownership.}}<br />
<br />
=== Hostname ===<br />
<br />
The hostname is configured in {{ic|/etc/hostname}}. The file should not contain the system's domain, if any. To set the hostname, do:<br />
<br />
# hostnamectl set-hostname '''myhostname'''<br />
<br />
See {{ic|man 5 hostname}} and {{ic|man 1 hostnamectl}} for details.<br />
<br />
Here is an example file:<br />
{{hc|/etc/hostname|<br />
myhostname<br />
}}<br />
<br />
=== Locale ===<br />
<br />
The default system locale is configured in {{ic|/etc/locale.conf}}. To set the default locale, do:<br />
<br />
# localectl set-locale LANG="de_DE.utf8"<br />
<br />
{{Note|Before you set the default locale, you first need to enable locales available to the system by uncommenting them in {{ic|/etc/locale.gen}} and then executing {{ic|locale-gen}} as root. The locale set via {{ic|localectl}} must be one of the '''uncommented''' locales in {{ic|/etc/locale.gen}}.}}<br />
<br />
See {{ic|man 1 localectl}} and {{ic|man 5 locale.conf}} for details.<br />
<br />
* For more information, see [[Locale]].<br />
<br />
Here is an example file:<br />
{{hc|/etc/locale.conf|<nowiki><br />
LANG=en_US.utf8<br />
</nowiki>}}<br />
<br />
=== Virtual console ===<br />
<br />
The virtual console (keyboard mapping, console font and console map) is configured in {{ic|/etc/vconsole.conf}}:<br />
<br />
{{hc|/etc/vconsole.conf|2=<br />
KEYMAP=us<br />
FONT=lat9w-16<br />
FONT_MAP=8859-1_to_uni}}<br />
<br />
{{Note|As of {{pkg|systemd}}-194, the built-in ''kernel'' font and the ''us'' keymap are used if {{ic|1=KEYMAP=}} and {{ic|1=FONT=}} are empty or not set.}}<br />
<br />
Another way to set the keyboard mapping (keymap) is doing:<br />
<br />
# localectl set-keymap de<br />
<br />
This has the advantage that it will also set the same keymap for use in X11.<br />
<br />
See {{ic|man 1 localectl}} and {{ic|man 5 vconsole.conf}} for details.<br />
<br />
* For more information, see [[Fonts#Console fonts|console fonts]] and [[KEYMAP|keymaps]].<br />
<br />
=== Time zone ===<br />
<br />
The time zone is configured by creating an appropriate {{ic|/etc/localtime}} symlink, pointing to a zoneinfo file under {{ic|/usr/share/zoneinfo/}}. To do this automatically:<br />
<br />
# timedatectl set-timezone America/Toronto<br />
<br />
See {{ic|man 1 timedatectl}}, {{ic|man 5 localtime}}, and {{ic|man 7 archlinux}} for more details.<br />
<br />
Alternatively, create the symlink yourself:<br />
<!-- DO NOT MAKE THIS AN ABSOLUTE SYMLINK, archlinux(7) clearly shows this should be a relative symlink --><br />
# ln -sf ../usr/share/zoneinfo/America/Toronto /etc/localtime<br />
<br />
=== Hardware clock ===<br />
<br />
Systemd will use '''UTC''' for the hardware clock by default.<br />
<br />
{{Tip|It is advised to have a [[NTP|Network Time Protocol daemon]] running to keep the system time synchronized with Internet time and the hardware clock.}}<br />
<br />
==== Hardware clock in localtime ====<br />
<br />
If you want to change the hardware clock to use local time ('''STRONGLY DISCOURAGED''') do:<br />
<br />
# timedatectl set-local-rtc true<br />
<br />
If you want to revert to the hardware clock being in UTC, do:<br />
<br />
# timedatectl set-local-rtc false<br />
<br />
Be warned that, if the hardware clock is set to localtime, dealing with daylight saving time is messy. If the DST changes when your computer is off, your clock will be wrong on next boot ([http://www.cl.cam.ac.uk/~mgk25/mswish/ut-rtc.html there is a lot more to it]). Recent kernels set the system time from the RTC directly on boot, assuming that the RTC is in UTC. This means that if the RTC is in local time, then the system time will first be set up wrongly and then corrected shortly afterwards on every boot. This is the root of certain weird bugs (time going backwards is rarely a good thing).<br />
<br />
One reason for allowing the RTC to be in local time is to allow dual boot with Windows ([http://blogs.msdn.com/b/oldnewthing/archive/2004/09/02/224672.aspx which uses localtime]). However, Windows is able to deal with the RTC being in UTC with a simple [[Time#UTC in Windows|registry fix]]. There, it is recommended that Windows are changed to use UTC, rather than Linux to use localtime. If you make Windows use UTC, also remember to disable the "Internet Time Update" Windows feature, so that Windows don't mess with the hardware clock, trying to sync it with internet time. You should instead leave touching the RTC and syncing it to internet time to Linux, by enabling an [[NTP]] daemon, as suggested previously.<br />
<br />
* For more information, see [[Time]].<br />
<br />
=== Kernel modules ===<br />
<br />
Today, all necessary module loading is handled automatically by [[udev]], so that, if you don't want/need to use any out-of-tree kernel modules, there is no need to put modules that should be loaded at boot in any config file. However, there are cases where you might want to load an extra module during the boot process, or blacklist another one for your computer to function properly.<br />
<br />
==== Extra modules to load at boot ====<br />
<br />
Extra kernel modules to be loaded during boot are configured as a static list in files under {{ic|/etc/modules-load.d/}}. Each configuration file is named in the style of {{ic|/etc/modules-load.d/<program>.conf}}. Configuration files simply contain a list of kernel module names to load, separated by newlines. Empty lines and lines whose first non-whitespace character is {{ic|#}} or {{ic|;}} are ignored.<br />
<br />
{{hc|/etc/modules-load.d/virtio-net.conf|<br />
# Load virtio-net.ko at boot<br />
virtio-net}}<br />
<br />
See {{ic|man 5 modules-load.d}} for more details.<br />
<br />
==== Blacklisting ====<br />
<br />
Module blacklisting works the same way as with {{Pkg|initscripts}} since it is actually handled by {{Pkg|kmod}}. See [[Kernel modules#Blacklisting|Module Blacklisting]] for details.<br />
<br />
=== Filesystem mounts ===<br />
<br />
The default setup will automatically fsck and mount filesystems before starting services that need them to be mounted. For example, systemd automatically makes sure that remote filesystem mounts like [[NFS]] or [[Samba]] are only started after the network has been set up. Therefore, local and remote filesystem mounts specified in {{ic|/etc/fstab}} should work out of the box.<br />
<br />
See {{ic|man 5 systemd.mount}} for details.<br />
<br />
==== Automount ====<br />
<br />
* If you have a large {{ic|/home}} partition, it might be better to allow services that do not depend on {{ic|/home}} to start while {{ic|/home}} is being fsck'ed. This can be achieved by adding the following options to the {{ic|/etc/fstab}} entry of your {{ic|/home}} partition:<br />
<br />
noauto,x-systemd.automount<br />
<br />
This will fsck and mount {{ic|/home}} when it is first accessed, and the kernel will buffer all file access to {{ic|/home}} until it is ready.<br />
<br />
* The same applies to remote filesystem mounts. If you want them to be mounted only upon access, you will need to use the {{ic|noauto,x-systemd.automount}} parameters. In addition, you can use the {{ic|1=x-systemd.device-timeout=#}} option to specify a timeout in case the network resource is not available.<br />
<br />
* If you have encrypted filesystems with keyfiles, you can also add the {{ic|noauto}} parameter to the corresponding entries in {{ic|/etc/crypttab}}. Systemd will then not open the encrypted device on boot, but instead wait until it is actually accessed and then automatically open it with the specified keyfile before mounting it. This might save a few seconds on boot if you are using an encrypted RAID device for example, because systemd doesn't have to wait for the device to become available. For example:<br />
<br />
{{hc|/etc/crypttab|<br />
data /dev/md0 /root/key noauto}}<br />
<br />
==== LVM ====<br />
<br />
If you have LVM volumes not activated via the [[Mkinitcpio|initramfs]], enable {{ic|lvm.service}} (provided by the {{pkg|lvm2}} package):<br />
<br />
# systemctl enable lvm<br />
<br />
Similarly, if you have LVM on encrypted devices mounted later during boot (e.g. from {{ic|/etc/crypttab}}), enable {{ic|lvm-on-crypt.service}} (also provided by the {{pkg|lvm2}} package):<br />
<br />
# systemctl enable lvm-on-crypt<br />
<br />
=== ACPI power management ===<br />
<br />
Systemd handles some power-related [[Wikipedia:Advanced_Configuration_and_Power_Interface|ACPI]] events. They can be configured via the following options from {{ic|/etc/systemd/logind.conf}}:<br />
<br />
* {{ic|HandlePowerKey}}: specifies which action is invoked when the power key is pressed.<br />
* {{ic|HandleSuspendKey}}: specifies which action is invoked when the suspend key is pressed.<br />
* {{ic|HandleHibernateKey}}: specifies which action is invoked when the hibernate key is pressed.<br />
* {{ic|HandleLidSwitch}}: specifies which action is invoked when the lid is closed.<br />
<br />
The specified action can be one of {{ic|ignore}}, {{ic|poweroff}}, {{ic|reboot}}, {{ic|halt}}, {{ic|suspend}}, {{ic|hibernate}} or {{ic|kexec}}.<br />
<br />
If these options are not configured, systemd will use its defaults: {{ic|1=HandlePowerKey=poweroff}}, {{ic|1=HandleSuspendKey=suspend}}, {{ic|1=HandleHibernateKey=hibernate}}, and {{ic|1=HandleLidSwitch=suspend}}.<br />
<br />
On systems which run no graphical setup or only a simple window manager like [[i3]] or [[awesome]], this may replace the [[acpid]] daemon which is usually used to react to these ACPI events.<br />
<br />
In the current version of systemd, the {{ic|Handle}} options will apply throughout the system unless they are "inhibited" (temporarily turned off) by a program, such as a power manager inside a desktop environment. If these inhibits are not taken, you can end up with a situation where systemd suspends your system, then when it wakes up the other power manager suspends it again.<br />
<br />
{{Warning|Currently, the power managers in the newest versions of [[KDE]] and [[GNOME]] are the only ones that issue the necessary "inhibited" commands. Until the others do, you will need to set the {{ic|Handle}} options to {{ic|ignore}} if you want your ACPI events to be handled by [[Xfce]], [[acpid]] or other programs. New versions are on the way that will include this functionality.}}<br />
<br />
{{Note|Systemd can also use other suspend backends (such as [[Uswsusp]] or [[TuxOnIce]]), in addition to the default ''kernel'' backend, in order to put the computer to sleep or hibernate.}}<br />
<br />
==== Sleep hooks ====<br />
<br />
Systemd does not use [[pm-utils]] to put the machine to sleep when using {{ic|systemctl suspend}} or {{ic|systemctl hibernate}}; [[pm-utils]] hooks, including any [[Pm-utils#Creating_your_own_hooks|custom hooks]], will not be run. However, systemd provides a similar mechanism to run custom scripts on these events. Systemd runs all executables in {{ic|/usr/lib/systemd/system-sleep/}}, passing two arguments to each of them:<br />
<br />
* Argument 1: either {{ic|pre}} or {{ic|post}}, depending on whether the machine is going to sleep or waking up<br />
* Argument 2: either {{ic|suspend}} or {{ic|hibernate}}, depending on which is being invoked<br />
<br />
In contrast to [[pm-utils]], systemd will run these scripts concurrently and not one after another.<br />
<br />
The output of any custom script will be logged by {{ic|systemd-suspend.service}} or {{ic|systemd-hibernate.service}}. You can see its output in systemd's [[Systemd#Journal|journal]]:<br />
# journalctl -b -u systemd-suspend<br />
<br />
Note that you can also use {{ic|sleep.target}}, {{ic|suspend.target}} or {{ic|hibernate.target}} to hook units into the sleep state logic instead of using custom scripts.<br />
<br />
An example of a custom sleep script:<br />
<br />
{{hc|/usr/lib/systemd/system-sleep/example.sh|<br />
#!/bin/sh<br />
case $1/$2 in<br />
pre/*)<br />
echo "Going to $2..."<br />
;;<br />
post/*)<br />
echo "Waking up from $2..."<br />
;;<br />
esac}}<br />
<br />
See {{ic|man 7 systemd.special}} and {{ic|man 8 systemd-sleep}} for more details.<br />
<br />
=== Temporary files ===<br />
<br />
Systemd-tmpfiles uses configuration files in {{ic|/usr/lib/tmpfiles.d/}} and {{ic|/etc/tmpfiles.d/}} to describe the creation, cleaning and removal of volatile and temporary files and directories which usually reside in directories such as {{ic|/run}} or {{ic|/tmp}}. Each configuration file is named in the style of {{ic|/etc/tmpfiles.d/<program>.conf}}. This will also override any files in {{ic|/usr/lib/tmpfiles.d/}} with the same name.<br />
<br />
tmpfiles are usually provided together with service files to create directories which are expected to exist by certain daemons. For example the [[Samba]] daemon expects the directory {{ic|/var/run/samba}} to exist and to have the correct permissions. The corresponding tmpfile looks like this:<br />
<br />
{{hc|/usr/lib/tmpfiles.d/samba.conf|<br />
D /var/run/samba 0755 root root}}<br />
<br />
However, tmpfiles may also be used to write values into certain files on boot. For example, if you use {{ic|/etc/rc.local}} to disable wakeup from USB devices with {{ic|echo USBE > /proc/acpi/wakeup}}, you may use the following tmpfile instead:<br />
<br />
{{hc|/etc/tmpfiles.d/disable-usb-wake.conf|<br />
w /proc/acpi/wakeup - - - - USBE}}<br />
<br />
The tmpfiles method is recommended in this case since systemd doesn't actually support {{ic|/etc/rc.local}}.<br />
<br />
See {{ic|man 5 tmpfiles.d}} for details.<br />
<br />
=== Units ===<br />
<br />
A unit configuration file encodes information about a service, a socket, a device, a mount point, an automount point, a swap file or partition, a start-up target, a file system path or a timer controlled and supervised by systemd. The syntax is inspired by XDG Desktop Entry Specification .desktop files, which are in turn inspired by Microsoft Windows .ini files.<br />
<br />
See {{ic|man 5 systemd.unit}} for details.<br />
<br />
== Transitioning from initscripts to systemd ==<br />
<br />
=== Initscripts emulation ===<br />
<br />
Integration with Arch's classic configuration is provided by the {{Pkg|initscripts}} package. When {{Pkg|initscripts}} are installed in parallel with systemd, with the system running on systemd, systemd will do the following:<br />
<br />
# Parse the {{ic|DAEMONS}} array of {{ic|/etc/rc.conf}} and start all listed daemons at boot<br />
# Execute {{ic|/etc/rc.local}} during boot<br />
# Execute {{ic|/etc/rc.local.shutdown}} during shutdown<br />
<br />
Initscripts emulation is simply meant as a transitional measure to ease users' move to systemd, and '''will eventually go away'''. Native systemd does not rely on {{ic|rc.conf}} centralised configuration, so it is recommended to use [[#Native configuration|native systemd configuration files]], which will take precedence over {{ic|/etc/rc.conf}}.<br />
<br />
{{Note|The recommended way to replace {{ic|/etc/rc.local}} is to write the custom service files for any things you want to run on the system startup. See the corresponding [[#Writing_custom_.service_files|section]].}}<br />
<br />
{{Note|If you disabled {{keypress|Ctrl+Alt+Del}} to reboot in {{ic|/etc/inittab}}, you will have to reconfigure this setting for systemd by running {{ic|systemctl mask ctrl-alt-del.target}} as root.}}<br />
<br />
=== Moving away from the DAEMONS array ===<br />
<br />
For a pure systemd setup, you should remove the {{ic|/etc/rc.conf}} file entirely and enable services only via {{ic|systemctl}}. For each {{ic|<service_name>}} in the {{ic|DAEMONS}} array in {{ic|/etc/rc.conf}}, run:<br />
<br />
# systemctl enable <service_name><br />
<br />
{{Tip|For a list of commonly used daemons with their initscripts and systemd equivalents, see [[Daemons List|this table]].}}<br />
<br />
If {{ic|<service_name>.service}} does not exist:<br />
<br />
* Most probably, systemd uses a different name. For example, {{ic|cronie.service}} replaces the {{ic|crond}} init daemon; {{ic|alsa-store.service}} and {{ic|alsa-restore.service}} replace the {{ic|alsa}} init daemon. Another important instance is the {{ic|network}} daemon, which is replaced with another set of service files (see [[Configuring Network]] for more details.)<br />
* Otherwise, a service file may not be available for systemd. In that case, you'll need to keep {{ic|rc.conf}} to start the service during boot up.<br />
<br />
{{Tip|You may look inside a package that contains daemon start scripts for service names. For instance:<br />
$ pacman -Ql cronie<br />
[...]<br />
cronie /etc/rc.d/crond #Daemon initscript listed in the DAEMONS array (unused in a "pure" systemd configuration)<br />
[...]<br />
cronie /usr/lib/systemd/system/cronie.service #Corresponding systemd daemon service<br />
[...]<br />
}}<br />
<br />
* Finally, some services do not need to be explicitly enabled by the user. For instance, {{ic|dbus.service}} will automatically be enabled when {{ic|dbus-core}} is installed. {{ic|alsa-store.service}} and {{ic|alsa-restore.service}} are also enabled automatically by systemd. Check the list of available services and their state using the {{ic|systemctl}} command like this: {{ic|systemctl status <service_name>}}.<br />
<br />
== Basic systemctl usage ==<br />
<br />
The main command used to introspect and control systemd is {{ic|systemctl}}. Some of its uses are examining the system state and managing the system and services. See {{ic|man 1 systemctl}} for more details.<br />
<br />
{{Tip|You can use all of the following {{ic|systemctl}} commands with the {{ic|-H <user>@<host>}} switch to control a systemd instance on a remote machine. This will use [[SSH]] to connect to the remote systemd instance.}}<br />
<br />
{{Note|{{ic|systemadm}} is the official graphical frontend for {{ic|systemctl}}. It is provided by the {{AUR|systemd-ui-git}} package from the [[AUR]].}}<br />
<br />
=== Analyzing the system state ===<br />
<br />
List running units:<br />
<br />
$ systemctl<br />
<br />
or:<br />
<br />
$ systemctl list-units<br />
<br />
List failed units:<br />
<br />
$ systemctl --failed<br />
<br />
The available unit files can be seen in {{ic|/usr/lib/systemd/system/}} and {{ic|/etc/systemd/system/}} (the latter takes precedence). You can see list installed unit files by:<br />
<br />
$ systemctl list-unit-files<br />
<br />
=== Using units ===<br />
<br />
Units can be, for example, services ({{ic|.service}}), mount points ({{ic|.mount}}), devices ({{ic|.device}}) or sockets ({{ic|.socket}}).<br />
<br />
When using {{ic|systemctl}}, you generally have to specify the complete name of the unit file, including its suffix, for example {{ic|sshd.socket}}. There are however a few shortforms when specifying the unit in the following {{ic|systemctl}} commands:<br />
<br />
* If you don't specify the suffix, systemctl will assume {{ic|.service}}. For example, {{ic|netcfg}} and {{ic|netcfg.service}} are treated equivalent.<br />
* Mount points will automatically be translated into the appropriate {{ic|.mount}} unit. For example, specifying {{ic|/home}} is equivalent to {{ic|home.mount}}.<br />
* Similiar to mount points, devices are automatically translated into the appropriate {{ic|.device}} unit, therefore specifying {{ic|/dev/sda2}} is equivalent to {{ic|dev-sda2.device}}.<br />
<br />
See {{ic|man systemd.unit}} for details.<br />
<br />
Activate a unit immediately:<br />
<br />
# systemctl start <unit><br />
<br />
Deactivate a unit immediately:<br />
<br />
# systemctl stop <unit><br />
<br />
Restart a unit:<br />
<br />
# systemctl restart <unit><br />
<br />
Ask a unit to reload its configuration:<br />
<br />
# systemctl reload <unit><br />
<br />
Show the status of a unit, including whether it is running or not:<br />
<br />
$ systemctl status <unit><br />
<br />
Check whether a unit is already enabled or not:<br />
<br />
$ systemctl is-enabled <unit><br />
<br />
Enable a unit to be started on bootup:<br />
<br />
# systemctl enable <unit><br />
<br />
{{Note|If services do not have an {{ic|Install}} section, it usually means they are called automatically by other services. But if you need to install them manually, use the following command, replacing {{ic|foo}} with the name of the service.<br />
# ln -s /usr/lib/systemd/system/''foo''.service /etc/systemd/system/graphical.target.wants/<br />
}}<br />
<br />
Disable a unit to not start during bootup:<br />
<br />
# systemctl disable <unit><br />
<br />
Show the manual page associated with a unit (this has to be supported by the unit file):<br />
<br />
$ systemctl help <unit><br />
<br />
=== Power management ===<br />
<br />
If you are in a local {{ic|systemd-logind}} user session and no other session is active, the following commands will work without root privileges. If not (for example, because another user is logged into a tty), systemd will automatically ask you for the root password.<br />
<br />
Shut down and reboot the system:<br />
<br />
$ systemctl reboot<br />
<br />
Shut down and power-off the system:<br />
<br />
$ systemctl poweroff<br />
<br />
Shut down and halt the system:<br />
<br />
$ systemctl halt<br />
<br />
Suspend the system:<br />
<br />
$ systemctl suspend<br />
<br />
Put the system into hibernation:<br />
<br />
$ systemctl hibernate<br />
<br />
== Running DEs under systemd ==<br />
<br />
To enable graphical login, run your preferred [[Display Manager]] daemon (e.g. [[KDM]]). At the moment, service files exist for [[GDM]], [[KDM]], [[SLiM]], [[XDM]], [[LXDM]] and [[LightDM]].<br />
<br />
# systemctl enable kdm<br />
<br />
This should work out of the box. If not, you might have a {{ic|default.target}} set manually or from a older install:<br />
<br />
{{hc|# ls -l /etc/systemd/system/default.target|<br />
/etc/systemd/system/default.target -> /usr/lib/systemd/system/graphical.target}}<br />
<br />
Simply delete the symlink and systemd will use its stock {{ic|default.target}} (i.e. {{ic|graphical.target}}).<br />
<br />
# rm /etc/systemd/system/default.target<br />
<br />
=== Using systemd-logind ===<br />
<br />
{{Note|As of 2012-10-30, [[ConsoleKit]] has been [https://www.archlinux.org/news/consolekit-replaced-by-logind/ replaced by systemd-logind] as the default mechanism to login to the DE.}}<br />
<br />
In order to check the status of your user session, you can use {{ic|loginctl}}. All [[PolicyKit]] actions like suspending the system or mounting external drives will work out of the box.<br />
<br />
$ loginctl show-session $XDG_SESSION_ID<br />
<br />
== Writing custom .service files ==<br />
<br />
=== Handling dependencies ===<br />
<br />
With systemd, dependencies can be resolved by designing the unit files correctly. The most typical case is that the unit {{ic|A}} requires the unit {{ic|B}} to be running before {{ic|A}} is started. In that case add {{ic|1=Requires=B}} and {{ic|1=After=B}} to the {{ic|[Unit]}} section of {{ic|A}}. If the dependency is optional, add {{ic|1=Wants=B}} and {{ic|1=After=B}} instead. Note that {{ic|1=Wants=}} and {{ic|1=Requires=}} do not imply {{ic|1=After=}}, meaning that if {{ic|1=After=}} is not specified, the two units will be started in parallel.<br />
<br />
Dependencies are typically placed on services and not on targets. For example, {{ic|network.target}} is pulled in by whatever service configures your network interfaces, therefore ordering your custom unit after it is sufficient since {{ic|network.target}} is started anyway.<br />
<br />
=== Type ===<br />
<br />
There are several different start-up types to consider when writing a custom service file. This is set with the {{ic|1=Type=}} parameter in the {{ic|[Service]}} section. See {{ic|man systemd.service}} for a more detailed explanation.<br />
<br />
* {{ic|1=Type=simple}}: systemd considers the service to be started up immediately. The process must not fork. Do not use this type if other services need to be ordered on this service, unless it is socket activated.<br />
* {{ic|1=Type=forking}}: systemd considers the service started up once the process forks and the parent has exited. For classic daemons use this type unless you know that it is not necessary. You should specify {{ic|1=PIDFile=}} as well so systemd can keep track of the main process.<br />
* {{ic|1=Type=oneshot}}: This is useful for scripts that do a single job and then exit. You may want to set {{ic|1=RemainAfterExit=}} as well so that systemd still considers the service as active after the process has exited.<br />
* {{ic|1=Type=notify}}: Identical to {{ic|1=Type=simple}}, but with the stipulation that the daemon will send a signal to systemd when it is ready. The reference implementation for this notification is provided by {{ic|libsystemd-daemon.so}}.<br />
* {{ic|1=Type=dbus}}: The service is considered ready when the specified {{ic|BusName}} appears on DBus's system bus.<br />
<br />
=== Replacing provided unit files ===<br />
<br />
The unit files in {{ic|/etc/systemd/system/}} take precedence over the ones in {{ic|/usr/lib/systemd/system/}}.<br />
To make your own version of a unit (which will not be destroyed by an upgrade), copy the old unit file from {{ic|/usr/lib/}} to {{ic|/etc/}} and make your changes there. Alternatively you can use {{ic|.include}} to parse an existing service file and then override or add new options. For example, if you simply want to add an additional dependency to a service file, you may use:<br />
<br />
{{hc|/etc/systemd/system/<service-name>.service|2=<br />
.include /usr/lib/systemd/system/<service-name>.service<br />
<br />
[Unit]<br />
Requires=<new dependency><br />
After=<new dependency>}}<br />
<br />
Then run the following for your changes to take effect:<br />
<br />
# systemctl reenable <unit><br />
# systemctl restart <unit><br />
<br />
{{Tip|You can use {{ic|systemd-delta}} to see which unit files have been overridden and what exactly has been changed.}}<br />
<br />
=== Syntax highlighting for units within Vim ===<br />
<br />
Syntax highlighting for systemd unit files within [[Vim]] can be enabled by installing {{AUR|vim-systemd}} from the [[Arch User Repository|AUR]].<br />
<br />
== Targets ==<br />
<br />
Systemd uses ''targets'' which serve a similar purpose as runlevels but act a little different. Each ''target'' is named instead of numbered and is intended to serve a specific purpose with the possibility of having multiple ones active at the same time. Some ''targets'' are implemented by inheriting all of the services of another ''target'' and adding additional services to it. There are systemd ''target''s that mimic the common SystemVinit runlevels so you can still switch ''target''s using the familiar {{ic|telinit RUNLEVEL}} command.<br />
<br />
=== Get current targets ===<br />
<br />
The following should be used under systemd instead of {{ic|runlevel}}:<br />
<br />
$ systemctl list-units --type=target<br />
<br />
=== Create custom target ===<br />
<br />
The runlevels that are assigned a specific purpose on vanilla Fedora installs; 0, 1, 3, 5, and 6; have a 1:1 mapping with a specific systemd ''target''. Unfortunately, there is no good way to do the same for the user-defined runlevels like 2 and 4. If you make use of those it is suggested that you make a new named systemd ''target'' as {{ic|/etc/systemd/system/<your target>}} that takes one of the existing runlevels as a base (you can look at {{ic|/usr/lib/systemd/system/graphical.target}} as an example), make a directory {{ic|/etc/systemd/system/<your target>.wants}}, and then symlink the additional services from {{ic|/usr/lib/systemd/system/}} that you wish to enable.<br />
<br />
=== Targets table ===<br />
<br />
{| border="1"<br />
! SysV Runlevel !! systemd Target !! Notes<br />
|-<br />
| 0 || runlevel0.target, poweroff.target || Halt the system.<br />
|-<br />
| 1, s, single || runlevel1.target, rescue.target || Single user mode.<br />
|-<br />
| 2, 4 || runlevel2.target, runlevel4.target, multi-user.target || User-defined/Site-specific runlevels. By default, identical to 3.<br />
|-<br />
| 3 || runlevel3.target, multi-user.target || Multi-user, non-graphical. Users can usually login via multiple consoles or via the network.<br />
|-<br />
| 5 || runlevel5.target, graphical.target || Multi-user, graphical. Usually has all the services of runlevel 3 plus a graphical login.<br />
|-<br />
| 6 || runlevel6.target, reboot.target || Reboot<br />
|-<br />
| emergency || emergency.target || Emergency shell<br />
|-<br />
|}<br />
<br />
=== Change current target ===<br />
<br />
In systemd targets are exposed via "target units". You can change them like this:<br />
<br />
# systemctl isolate graphical.target<br />
<br />
This will only change the current target, and has no effect on the next boot. This is equivalent to commands such as {{ic|telinit 3}} or {{ic|telinit 5}} in Sysvinit.<br />
<br />
=== Change default target to boot into ===<br />
<br />
The standard target is {{ic|default.target}}, which is aliased by default to {{ic|graphical.target}} (which roughly corresponds to the old runlevel 5). To change the default target at boot-time, append one of the following [[kernel parameters]] to your bootloader:<br />
<br />
{{Tip|The {{ic|.target}} extension can be left out.}}<br />
<br />
* {{ic|1=systemd.unit=multi-user.target}} (which roughly corresponds to the old runlevel 3),<br />
* {{ic|1=systemd.unit=rescue.target}} (which roughly corresponds to the old runlevel 1).<br />
<br />
Alternatively, you may leave the bootloader alone and change {{ic|default.target}}. This can be done using {{ic|systemctl}}:<br />
<br />
# systemctl enable multi-user.target<br />
<br />
The effect of this command is outputted by {{ic|systemctl}}; a symlink to the new default target is made at {{ic|/etc/systemd/system/default.target}}. This works if, and only if:<br />
<br />
[Install]<br />
Alias=default.target<br />
<br />
is in the target's configuration file. Currently, {{ic|multi-user.target}} and {{ic|graphical.target}} both have it.<br />
<br />
== Journal ==<br />
<br />
Since version 38, systemd has its own logging system, the journal. Therefore, running a syslog daemon is no longer required. To read the log, use:<br />
<br />
# journalctl<br />
<br />
By default (when {{ic|Storage&#61;}} is set to {{ic|auto}} in {{ic|/etc/systemd/journald.conf}}), the journal writes to {{ic|/var/log/journal/}}. If the directory {{ic|/var/log/journal/}} does not exist (e.g. if you or some program delete it), systemd will '''not''' create it automatically, but instead write its logs to {{ic|/run/systemd/journal}}. This means that logs will be lost on reboot.<br />
<br />
=== Filtering output ===<br />
<br />
{{ic|journalctl}} allows you to filter the output by specific fields.<br />
<br />
Examples:<br />
<br />
Show all messages from this boot:<br />
<br />
# journalctl -b<br />
<br />
Follow new messages:<br />
<br />
# journalctl -f<br />
<br />
Show all messages by a specific executable:<br />
<br />
# journalctl /usr/lib/systemd/systemd<br />
<br />
Show all messages by a specific process:<br />
<br />
# journalctl _PID=1<br />
<br />
Show all messages by a specific unit:<br />
<br />
# journalctl -u netcfg<br />
<br />
See {{ic|man journalctl}}, {{ic|systemd.journal-fields}} or Lennert's [http://0pointer.de/blog/projects/journalctl.html blog post] for details.<br />
<br />
=== Journal size limit ===<br />
<br />
If the journal is persistent (non-volatile), its size limit is set to a default value of 10% of the size of the respective file system. E.g. with {{ic|/var/log/journal}} located on a 50 GiB root partition this would lead to 5 GiB of journal data. The maximum size of the persistent journal can be controlled by {{ic|SystemMaxUse}} in {{ic|/etc/systemd/journald.conf}}, so to limit it for example to 50 MiB uncomment and edit the corresponding line to:<br />
<br />
SystemMaxUse=50M<br />
<br />
Refer to {{ic|man journald.conf}} for more info.<br />
<br />
=== Journald in conjunction with syslog ===<br />
<br />
Compatibility with classic syslog implementations is provided via a socket {{ic|/run/systemd/journal/syslog}}, to which all messages are forwarded. To make the syslog daemon work with the journal, it has to bind to this socket instead of {{ic|/dev/log}} ([http://lwn.net/Articles/474968/ official announcement]). The {{pkg|syslog-ng}} package in the repositories automatically provides the necessary configuration.<br />
<br />
# systemctl enable syslog-ng<br />
<br />
== Optimization ==<br />
<br />
=== Analyzing the boot process ===<br />
<br />
==== Using systemd-analyze ====<br />
<br />
Systemd provides a tool called {{ic|systemd-analyze}} that allows you to analyze your boot process so you can see which unit files are causing your boot process to slow down. You can then optimize your system accordingly. You have to install {{Pkg|python2-dbus}} and {{Pkg|python2-cairo}} to use it.<br />
<br />
To see how much time was spent in kernelspace and userspace on boot, simply use:<br />
<br />
$ systemd-analyze<br />
<br />
{{Tip|To see how much time was spent in the initramfs, append the {{ic|timestamp}} hook to your {{ic|HOOKS}} array in {{ic|/etc/[[mkinitcpio]].conf}} and as root, rebuild your initramfs with {{ic|mkinitcpio -p linux}} }}<br />
<br />
To list the started unit files, sorted by the time each of them took to start up:<br />
<br />
$ systemd-analyze blame<br />
<br />
You can also create a SVG file which describes your boot process graphically, similiar to [[Bootchart]]:<br />
<br />
$ systemd-analyze plot > plot.svg<br />
<br />
==== Using bootchart ====<br />
<br />
You could also use a version of bootchart to visualize the boot sequence. Since you are not able to put a second init into the kernel command line you won't be able to use any of the standard bootchart setups. However the {{AUR|bootchart2}} package from [[AUR]] comes with an undocumented systemd service. After you've installed bootchart2 do:<br />
<br />
# systemctl enable bootchart<br />
<br />
Read the [https://github.com/mmeeks/bootchart bootchart documentation] for further details on using this version of bootchart.<br />
<br />
=== Readahead ===<br />
<br />
Systemd comes with its own readahead implementation, this should in principle improve boot time. However, depending on your kernel version and the type of your hard drive, your mileage may vary (i.e. it might be slower). To enable, do:<br />
<br />
# systemctl enable systemd-readahead-collect systemd-readahead-replay<br />
<br />
Remember that in order for the readahead to work its magic, you should reboot a couple of times.<br />
<br />
=== Early start for services ===<br />
<br />
One central feature of systemd is [[D-Bus]] and socket activation. This causes services to be started when they are first accessed and is generally a good thing. However, if you know that a service (like [[UPower]]) will always be started during boot, then the overall boot time might be reduced by starting it as early as possible. This can be achieved (if the service file is set up for it, which in most cases it is) by issuing:<br />
<br />
# systemctl enable upower<br />
<br />
This will cause systemd to start UPower as soon as possible, without causing races with the socket or D-Bus activation.<br />
<br />
=== Less output during boot ===<br />
<br />
Change {{ic|verbose}} to {{ic|quiet}} on the bootloader's kernel line. For some systems, particularly those with an SSD, the slow performance of the TTY is actually a bottleneck, and so less output means faster booting.<br />
<br />
== Troubleshooting ==<br />
<br />
=== Shutdown/reboot takes terribly long ===<br />
<br />
If the shutdown process takes a very long time (or seems to freeze) most likely a service not exiting is to blame. Systemd waits some time for each service to exit before trying to kill it. To find out if you are affected, see [http://freedesktop.org/wiki/Software/systemd/Debugging#Shutdown_Completes_Eventually this article].<br />
<br />
== See also ==<br />
<br />
*[http://www.freedesktop.org/wiki/Software/systemd Official Web Site]<br />
*[http://0pointer.de/public/systemd-man/ Manual Pages]<br />
*[http://freedesktop.org/wiki/Software/systemd/Optimizations systemd Optimizations]<br />
*[http://www.freedesktop.org/wiki/Software/systemd/FrequentlyAskedQuestions FAQ]<br />
*[http://www.freedesktop.org/wiki/Software/systemd/TipsAndTricks Tips And Tricks]<br />
*[http://0pointer.de/public/systemd-ebook-psankar.pdf systemd for Administrators (PDF)]<br />
*[http://fedoraproject.org/wiki/Systemd About systemd on Fedora Project]<br />
*[http://fedoraproject.org/wiki/How_to_debug_Systemd_problems How to debug systemd problems]<br />
*[http://www.h-online.com/open/features/Booting-up-Tools-and-tips-for-systemd-1570630.html Booting up: Tools and tips for systemd, a Linux init tool. In The H]<br />
*[http://0pointer.de/blog/projects/systemd.html Lennart's blog story]<br />
*[http://0pointer.de/blog/projects/systemd-update.html status update]<br />
*[http://0pointer.de/blog/projects/systemd-update-2.html status update2]<br />
*[http://0pointer.de/blog/projects/systemd-update-3.html status update3]<br />
*[http://0pointer.de/blog/projects/why.html most recent summary]<br />
*[http://fedoraproject.org/wiki/SysVinit_to_Systemd_Cheatsheet Fedora's SysVinit to systemd cheatsheet]</div>Rasihttps://wiki.archlinux.org/index.php?title=Systemd&diff=235513Systemd2012-11-15T10:03:16Z<p>Rasi: /* Installation */</p>
<hr />
<div>{{Lowercase title}}<br />
[[Category:Daemons and system services]]<br />
[[Category:Boot process]]<br />
[[es:Systemd]]<br />
[[fr:Systemd]]<br />
[[it:Systemd]]<br />
[[ja:Systemd]]<br />
[[ru:Systemd]]<br />
[[zh-CN:Systemd]]<br />
{{Article summary start}}<br />
{{Article summary text|Covers how to install and configure systemd.}}<br />
{{Article summary heading|Related}}<br />
{{Article summary wiki|systemd/User}}<br />
{{Article summary wiki|systemd/Services}}<br />
{{Article summary wiki|systemd FAQ}}<br />
{{Article summary wiki|init Rosetta}}<br />
{{Article summary wiki|udev}}<br />
{{Article summary end}}<br />
From the [http://freedesktop.org/wiki/Software/systemd project web page]:<br />
<br />
'''''systemd''' is a system and service manager for Linux, compatible with SysV and LSB init scripts. '''systemd''' provides aggressive parallelization capabilities, uses socket and [[D-Bus]] activation for starting services, offers on-demand starting of daemons, keeps track of processes using Linux [[cgroups|control groups]], supports snapshotting and restoring of the system state, maintains mount and automount points and implements an elaborate transactional dependency-based service control logic. It can work as a drop-in replacement for [[SysVinit|sysvinit]].''<br />
<br />
{{Note|1=For a detailed explanation as to why Arch has moved to systemd, see [https://bbs.archlinux.org/viewtopic.php?pid=1149530#p1149530 this forum post].}}<br />
<br />
See also the [[Wikipedia:Systemd|Wikipedia article]].<br />
<br />
== Considerations before switching ==<br />
<br />
* Check if you are already using systemd with the command {{ic| cat /proc/1/comm}}, where the output {{ic| init}} stands for sysvinit and {{ic|systemd}} for systemd.<br />
* It is highly recommended to switch to the new '''initscripts''' configuration system described in the [[rc.conf|rc.conf article]]. Once you have this configuration established, you will have done most of the work needed to make the switch to systemd.<br />
* Do [http://freedesktop.org/wiki/Software/systemd/ some reading] about systemd.<br />
* Note the fact that systemd has a '''journal''' system that replaces '''syslog''', although the two can co-exist. See the [[#Journal|section on the journal]] below.<br />
* While systemd can replace some of the functionality of '''cron''', '''acpid''', or '''xinetd''', there is no need to switch away from using the traditional daemons unless you want to.<br />
* Interactive initscripts are not working with systemd. In particular, '''netcfg-menu''' [https://bugs.archlinux.org/task/31377 cannot] be used at system start-up.<br />
<br />
== Installation ==<br />
{{Note|{{pkg|systemd}} and {{pkg|systemd-sysvcompat}} are both installed by default on installation media newer than [https://www.archlinux.org/news/systemd-is-now-the-default-on-new-installations/ 2012-10-13].}}<br />
The following section is aimed at Arch Linux installations that still rely on {{pkg|sysvinit}} and {{pkg|initscripts}} which have not migrated to {{pkg|systemd}}.<br />
<br />
# Install {{pkg|systemd}} and append the following to your [[kernel line]]: {{ic|1=init=/usr/lib/systemd/systemd}}<br />
# Once completed you may enable any desired services via the use of {{ic|systemctl enable <service_name>}} (this roughly equates to what you included in the {{ic|DAEMONS}} array).<br />
# Reboot your system and verify that {{ic|systemd}} is currently active by using the following command: {{ic|$ cat /proc/1/comm}}. This should return the string {{ic|systemd}}.<br />
# Proceed to remove {{pkg|initscripts}} and {{pkg|sysvinit}} from your system and install {{pkg|systemd-sysvcompat}}.<br />
<br />
=== Supplementary information ===<br />
<br />
* If you have {{ic|quiet}} in your kernel parameters, you might want to remove it for your first couple of systemd boots, to assist with identifying any issues during boot.<br />
<br />
* Adding your user to [[Users and Groups|groups]] ({{ic|optical}}, {{ic|audio}}, {{ic|scanner}}, etc.) is '''not''' necessary for most use cases with systemd. The groups can even cause some functionality to break. For example, the audio group will break fast user switching and allows applications to block software mixing. Every PAM login provides a logind session, which for a local session will give you permissions via [[Wikipedia:Access control list|POSIX ACLs]] on audio/video devices, and allow certain operations like mounting removable storage via [[udisks]].<br />
<br />
{{Note|Systemd-logind replaced [[ConsoleKit]], which was removed from the repositories, so a system must be booted with systemd to be fully functional. See [https://www.archlinux.org/news/consolekit-replaced-by-logind/ here] for more info.}}<br />
<br />
== Native configuration ==<br />
<br />
{{Note|You may need to create these files. All files should have '''644''' permissions and '''root:root''' ownership.}}<br />
<br />
=== Hostname ===<br />
<br />
The hostname is configured in {{ic|/etc/hostname}}. The file should not contain the system's domain, if any. To set the hostname, do:<br />
<br />
# hostnamectl set-hostname '''myhostname'''<br />
<br />
See {{ic|man 5 hostname}} and {{ic|man 1 hostnamectl}} for details.<br />
<br />
Here is an example file:<br />
{{hc|/etc/hostname|<br />
myhostname<br />
}}<br />
<br />
=== Locale ===<br />
<br />
The default system locale is configured in {{ic|/etc/locale.conf}}. To set the default locale, do:<br />
<br />
# localectl set-locale LANG="de_DE.utf8"<br />
<br />
{{Note|Before you set the default locale, you first need to enable locales available to the system by uncommenting them in {{ic|/etc/locale.gen}} and then executing {{ic|locale-gen}} as root. The locale set via {{ic|localectl}} must be one of the '''uncommented''' locales in {{ic|/etc/locale.gen}}.}}<br />
<br />
See {{ic|man 1 localectl}} and {{ic|man 5 locale.conf}} for details.<br />
<br />
* For more information, see [[Locale]].<br />
<br />
Here is an example file:<br />
{{hc|/etc/locale.conf|<nowiki><br />
LANG=en_US.utf8<br />
</nowiki>}}<br />
<br />
=== Virtual console ===<br />
<br />
The virtual console (keyboard mapping, console font and console map) is configured in {{ic|/etc/vconsole.conf}}:<br />
<br />
{{hc|/etc/vconsole.conf|2=<br />
KEYMAP=us<br />
FONT=lat9w-16<br />
FONT_MAP=8859-1_to_uni}}<br />
<br />
{{Note|As of {{pkg|systemd}}-194, the built-in ''kernel'' font and the ''us'' keymap are used if {{ic|1=KEYMAP=}} and {{ic|1=FONT=}} are empty or not set.}}<br />
<br />
Another way to set the keyboard mapping (keymap) is doing:<br />
<br />
# localectl set-keymap de<br />
<br />
This has the advantage that it will also set the same keymap for use in X11.<br />
<br />
See {{ic|man 1 localectl}} and {{ic|man 5 vconsole.conf}} for details.<br />
<br />
* For more information, see [[Fonts#Console fonts|console fonts]] and [[KEYMAP|keymaps]].<br />
<br />
=== Time zone ===<br />
<br />
The time zone is configured by creating an appropriate {{ic|/etc/localtime}} symlink, pointing to a zoneinfo file under {{ic|/usr/share/zoneinfo/}}. To do this automatically:<br />
<br />
# timedatectl set-timezone America/Toronto<br />
<br />
See {{ic|man 1 timedatectl}}, {{ic|man 5 localtime}}, and {{ic|man 7 archlinux}} for more details.<br />
<br />
Alternatively, create the symlink yourself:<br />
<!-- DO NOT MAKE THIS AN ABSOLUTE SYMLINK, archlinux(7) clearly shows this should be a relative symlink --><br />
# ln -sf ../usr/share/zoneinfo/America/Toronto /etc/localtime<br />
<br />
=== Hardware clock ===<br />
<br />
Systemd will use '''UTC''' for the hardware clock by default.<br />
<br />
{{Tip|It is advised to have a [[NTP|Network Time Protocol daemon]] running to keep the system time synchronized with Internet time and the hardware clock.}}<br />
<br />
==== Hardware clock in localtime ====<br />
<br />
If you want to change the hardware clock to use local time ('''STRONGLY DISCOURAGED''') do:<br />
<br />
# timedatectl set-local-rtc true<br />
<br />
If you want to revert to the hardware clock being in UTC, do:<br />
<br />
# timedatectl set-local-rtc false<br />
<br />
Be warned that, if the hardware clock is set to localtime, dealing with daylight saving time is messy. If the DST changes when your computer is off, your clock will be wrong on next boot ([http://www.cl.cam.ac.uk/~mgk25/mswish/ut-rtc.html there is a lot more to it]). Recent kernels set the system time from the RTC directly on boot, assuming that the RTC is in UTC. This means that if the RTC is in local time, then the system time will first be set up wrongly and then corrected shortly afterwards on every boot. This is the root of certain weird bugs (time going backwards is rarely a good thing).<br />
<br />
One reason for allowing the RTC to be in local time is to allow dual boot with Windows ([http://blogs.msdn.com/b/oldnewthing/archive/2004/09/02/224672.aspx which uses localtime]). However, Windows is able to deal with the RTC being in UTC with a simple [[Time#UTC in Windows|registry fix]]. There, it is recommended that Windows are changed to use UTC, rather than Linux to use localtime. If you make Windows use UTC, also remember to disable the "Internet Time Update" Windows feature, so that Windows don't mess with the hardware clock, trying to sync it with internet time. You should instead leave touching the RTC and syncing it to internet time to Linux, by enabling an [[NTP]] daemon, as suggested previously.<br />
<br />
* For more information, see [[Time]].<br />
<br />
=== Kernel modules ===<br />
<br />
Today, all necessary module loading is handled automatically by [[udev]], so that, if you don't want/need to use any out-of-tree kernel modules, there is no need to put modules that should be loaded at boot in any config file. However, there are cases where you might want to load an extra module during the boot process, or blacklist another one for your computer to function properly.<br />
<br />
==== Extra modules to load at boot ====<br />
<br />
Extra kernel modules to be loaded during boot are configured as a static list in files under {{ic|/etc/modules-load.d/}}. Each configuration file is named in the style of {{ic|/etc/modules-load.d/<program>.conf}}. Configuration files simply contain a list of kernel module names to load, separated by newlines. Empty lines and lines whose first non-whitespace character is {{ic|#}} or {{ic|;}} are ignored.<br />
<br />
{{hc|/etc/modules-load.d/virtio-net.conf|<br />
# Load virtio-net.ko at boot<br />
virtio-net}}<br />
<br />
See {{ic|man 5 modules-load.d}} for more details.<br />
<br />
==== Blacklisting ====<br />
<br />
Module blacklisting works the same way as with {{Pkg|initscripts}} since it is actually handled by {{Pkg|kmod}}. See [[Kernel modules#Blacklisting|Module Blacklisting]] for details.<br />
<br />
=== Filesystem mounts ===<br />
<br />
The default setup will automatically fsck and mount filesystems before starting services that need them to be mounted. For example, systemd automatically makes sure that remote filesystem mounts like [[NFS]] or [[Samba]] are only started after the network has been set up. Therefore, local and remote filesystem mounts specified in {{ic|/etc/fstab}} should work out of the box.<br />
<br />
See {{ic|man 5 systemd.mount}} for details.<br />
<br />
==== Automount ====<br />
<br />
* If you have a large {{ic|/home}} partition, it might be better to allow services that do not depend on {{ic|/home}} to start while {{ic|/home}} is being fsck'ed. This can be achieved by adding the following options to the {{ic|/etc/fstab}} entry of your {{ic|/home}} partition:<br />
<br />
noauto,x-systemd.automount<br />
<br />
This will fsck and mount {{ic|/home}} when it is first accessed, and the kernel will buffer all file access to {{ic|/home}} until it is ready.<br />
<br />
* The same applies to remote filesystem mounts. If you want them to be mounted only upon access, you will need to use the {{ic|noauto,x-systemd.automount}} parameters. In addition, you can use the {{ic|1=x-systemd.device-timeout=#}} option to specify a timeout in case the network resource is not available.<br />
<br />
* If you have encrypted filesystems with keyfiles, you can also add the {{ic|noauto}} parameter to the corresponding entries in {{ic|/etc/crypttab}}. Systemd will then not open the encrypted device on boot, but instead wait until it is actually accessed and then automatically open it with the specified keyfile before mounting it. This might save a few seconds on boot if you are using an encrypted RAID device for example, because systemd doesn't have to wait for the device to become available. For example:<br />
<br />
{{hc|/etc/crypttab|<br />
data /dev/md0 /root/key noauto}}<br />
<br />
==== LVM ====<br />
<br />
If you have LVM volumes not activated via the [[Mkinitcpio|initramfs]], enable {{ic|lvm.service}} (provided by the {{pkg|lvm2}} package):<br />
<br />
# systemctl enable lvm<br />
<br />
Similarly, if you have LVM on encrypted devices mounted later during boot (e.g. from {{ic|/etc/crypttab}}), enable {{ic|lvm-on-crypt.service}} (also provided by the {{pkg|lvm2}} package):<br />
<br />
# systemctl enable lvm-on-crypt<br />
<br />
=== ACPI power management ===<br />
<br />
Systemd handles some power-related [[Wikipedia:Advanced_Configuration_and_Power_Interface|ACPI]] events. They can be configured via the following options from {{ic|/etc/systemd/logind.conf}}:<br />
<br />
* {{ic|HandlePowerKey}}: specifies which action is invoked when the power key is pressed.<br />
* {{ic|HandleSuspendKey}}: specifies which action is invoked when the suspend key is pressed.<br />
* {{ic|HandleHibernateKey}}: specifies which action is invoked when the hibernate key is pressed.<br />
* {{ic|HandleLidSwitch}}: specifies which action is invoked when the lid is closed.<br />
<br />
The specified action can be one of {{ic|ignore}}, {{ic|poweroff}}, {{ic|reboot}}, {{ic|halt}}, {{ic|suspend}}, {{ic|hibernate}} or {{ic|kexec}}.<br />
<br />
If these options are not configured, systemd will use its defaults: {{ic|1=HandlePowerKey=poweroff}}, {{ic|1=HandleSuspendKey=suspend}}, {{ic|1=HandleHibernateKey=hibernate}}, and {{ic|1=HandleLidSwitch=suspend}}.<br />
<br />
On systems which run no graphical setup or only a simple window manager like [[i3]] or [[awesome]], this may replace the [[acpid]] daemon which is usually used to react to these ACPI events.<br />
<br />
In the current version of systemd, the {{ic|Handle}} options will apply throughout the system unless they are "inhibited" (temporarily turned off) by a program, such as a power manager inside a desktop environment. If these inhibits are not taken, you can end up with a situation where systemd suspends your system, then when it wakes up the other power manager suspends it again.<br />
<br />
{{Warning|Currently, the power managers in the newest versions of [[KDE]] and [[GNOME]] are the only ones that issue the necessary "inhibited" commands. Until the others do, you will need to set the {{ic|Handle}} options to {{ic|ignore}} if you want your ACPI events to be handled by [[Xfce]], [[acpid]] or other programs. New versions are on the way that will include this functionality.}}<br />
<br />
{{Note|Systemd can also use other suspend backends (such as [[Uswsusp]] or [[TuxOnIce]]), in addition to the default ''kernel'' backend, in order to put the computer to sleep or hibernate.}}<br />
<br />
==== Sleep hooks ====<br />
<br />
Systemd does not use [[pm-utils]] to put the machine to sleep when using {{ic|systemctl suspend}} or {{ic|systemctl hibernate}}; [[pm-utils]] hooks, including any [[Pm-utils#Creating_your_own_hooks|custom hooks]], will not be run. However, systemd provides a similar mechanism to run custom scripts on these events. Systemd runs all executables in {{ic|/usr/lib/systemd/system-sleep/}}, passing two arguments to each of them:<br />
<br />
* Argument 1: either {{ic|pre}} or {{ic|post}}, depending on whether the machine is going to sleep or waking up<br />
* Argument 2: either {{ic|suspend}} or {{ic|hibernate}}, depending on which is being invoked<br />
<br />
In contrast to [[pm-utils]], systemd will run these scripts concurrently and not one after another.<br />
<br />
The output of any custom script will be logged by {{ic|systemd-suspend.service}} or {{ic|systemd-hibernate.service}}. You can see its output in systemd's [[Systemd#Journal|journal]]:<br />
# journalctl -b -u systemd-suspend<br />
<br />
Note that you can also use {{ic|sleep.target}}, {{ic|suspend.target}} or {{ic|hibernate.target}} to hook units into the sleep state logic instead of using custom scripts.<br />
<br />
An example of a custom sleep script:<br />
<br />
{{hc|/usr/lib/systemd/system-sleep/example.sh|<br />
#!/bin/sh<br />
case $1/$2 in<br />
pre/*)<br />
echo "Going to $2..."<br />
;;<br />
post/*)<br />
echo "Waking up from $2..."<br />
;;<br />
esac}}<br />
<br />
See {{ic|man 7 systemd.special}} and {{ic|man 8 systemd-sleep}} for more details.<br />
<br />
=== Temporary files ===<br />
<br />
Systemd-tmpfiles uses configuration files in {{ic|/usr/lib/tmpfiles.d/}} and {{ic|/etc/tmpfiles.d/}} to describe the creation, cleaning and removal of volatile and temporary files and directories which usually reside in directories such as {{ic|/run}} or {{ic|/tmp}}. Each configuration file is named in the style of {{ic|/etc/tmpfiles.d/<program>.conf}}. This will also override any files in {{ic|/usr/lib/tmpfiles.d/}} with the same name.<br />
<br />
tmpfiles are usually provided together with service files to create directories which are expected to exist by certain daemons. For example the [[Samba]] daemon expects the directory {{ic|/var/run/samba}} to exist and to have the correct permissions. The corresponding tmpfile looks like this:<br />
<br />
{{hc|/usr/lib/tmpfiles.d/samba.conf|<br />
D /var/run/samba 0755 root root}}<br />
<br />
However, tmpfiles may also be used to write values into certain files on boot. For example, if you use {{ic|/etc/rc.local}} to disable wakeup from USB devices with {{ic|echo USBE > /proc/acpi/wakeup}}, you may use the following tmpfile instead:<br />
<br />
{{hc|/etc/tmpfiles.d/disable-usb-wake.conf|<br />
w /proc/acpi/wakeup - - - - USBE}}<br />
<br />
The tmpfiles method is recommended in this case since systemd doesn't actually support {{ic|/etc/rc.local}}.<br />
<br />
See {{ic|man 5 tmpfiles.d}} for details.<br />
<br />
=== Units ===<br />
<br />
A unit configuration file encodes information about a service, a socket, a device, a mount point, an automount point, a swap file or partition, a start-up target, a file system path or a timer controlled and supervised by systemd. The syntax is inspired by XDG Desktop Entry Specification .desktop files, which are in turn inspired by Microsoft Windows .ini files.<br />
<br />
See {{ic|man 5 systemd.unit}} for details.<br />
<br />
== Transitioning from initscripts to systemd ==<br />
<br />
=== Initscripts emulation ===<br />
<br />
Integration with Arch's classic configuration is provided by the {{Pkg|initscripts}} package. When {{Pkg|initscripts}} are installed in parallel with systemd, with the system running on systemd, systemd will do the following:<br />
<br />
# Parse the {{ic|DAEMONS}} array of {{ic|/etc/rc.conf}} and start all listed daemons at boot<br />
# Execute {{ic|/etc/rc.local}} during boot<br />
# Execute {{ic|/etc/rc.local.shutdown}} during shutdown<br />
<br />
Initscripts emulation is simply meant as a transitional measure to ease users' move to systemd, and '''will eventually go away'''. Native systemd does not rely on {{ic|rc.conf}} centralised configuration, so it is recommended to use [[#Native configuration|native systemd configuration files]], which will take precedence over {{ic|/etc/rc.conf}}.<br />
<br />
{{Note|The recommended way to replace {{ic|/etc/rc.local}} is to write the custom service files for any things you want to run on the system startup. See the corresponding [[#Writing_custom_.service_files|section]].}}<br />
<br />
{{Note|If you disabled {{keypress|Ctrl+Alt+Del}} to reboot in {{ic|/etc/inittab}}, you will have to reconfigure this setting for systemd by running {{ic|systemctl mask ctrl-alt-del.target}} as root.}}<br />
<br />
=== Moving away from the DAEMONS array ===<br />
<br />
For a pure systemd setup, you should remove the {{ic|/etc/rc.conf}} file entirely and enable services only via {{ic|systemctl}}. For each {{ic|<service_name>}} in the {{ic|DAEMONS}} array in {{ic|/etc/rc.conf}}, run:<br />
<br />
# systemctl enable <service_name><br />
<br />
{{Tip|For a list of commonly used daemons with their initscripts and systemd equivalents, see [[Daemons List|this table]].}}<br />
<br />
If {{ic|<service_name>.service}} does not exist:<br />
<br />
* Most probably, systemd uses a different name. For example, {{ic|cronie.service}} replaces the {{ic|crond}} init daemon; {{ic|alsa-store.service}} and {{ic|alsa-restore.service}} replace the {{ic|alsa}} init daemon. Another important instance is the {{ic|network}} daemon, which is replaced with another set of service files (see [[Configuring Network]] for more details.)<br />
* Otherwise, a service file may not be available for systemd. In that case, you'll need to keep {{ic|rc.conf}} to start the service during boot up.<br />
<br />
{{Tip|You may look inside a package that contains daemon start scripts for service names. For instance:<br />
$ pacman -Ql cronie<br />
[...]<br />
cronie /etc/rc.d/crond #Daemon initscript listed in the DAEMONS array (unused in a "pure" systemd configuration)<br />
[...]<br />
cronie /usr/lib/systemd/system/cronie.service #Corresponding systemd daemon service<br />
[...]<br />
}}<br />
<br />
* Finally, some services do not need to be explicitly enabled by the user. For instance, {{ic|dbus.service}} will automatically be enabled when {{ic|dbus-core}} is installed. {{ic|alsa-store.service}} and {{ic|alsa-restore.service}} are also enabled automatically by systemd. Check the list of available services and their state using the {{ic|systemctl}} command like this: {{ic|systemctl status <service_name>}}.<br />
<br />
== Basic systemctl usage ==<br />
<br />
The main command used to introspect and control systemd is {{ic|systemctl}}. Some of its uses are examining the system state and managing the system and services. See {{ic|man 1 systemctl}} for more details.<br />
<br />
{{Tip|You can use all of the following {{ic|systemctl}} commands with the {{ic|-H <user>@<host>}} switch to control a systemd instance on a remote machine. This will use [[SSH]] to connect to the remote systemd instance.}}<br />
<br />
{{Note|{{ic|systemadm}} is the official graphical frontend for {{ic|systemctl}}. It is provided by the {{AUR|systemd-ui-git}} package from the [[AUR]].}}<br />
<br />
=== Analyzing the system state ===<br />
<br />
List running units:<br />
<br />
$ systemctl<br />
<br />
or:<br />
<br />
$ systemctl list-units<br />
<br />
List failed units:<br />
<br />
$ systemctl --failed<br />
<br />
The available unit files can be seen in {{ic|/usr/lib/systemd/system/}} and {{ic|/etc/systemd/system/}} (the latter takes precedence). You can see list installed unit files by:<br />
<br />
$ systemctl list-unit-files<br />
<br />
=== Using units ===<br />
<br />
Units can be, for example, services ({{ic|.service}}), mount points ({{ic|.mount}}), devices ({{ic|.device}}) or sockets ({{ic|.socket}}).<br />
<br />
When using {{ic|systemctl}}, you generally have to specify the complete name of the unit file, including its suffix, for example {{ic|sshd.socket}}. There are however a few shortforms when specifying the unit in the following {{ic|systemctl}} commands:<br />
<br />
* If you don't specify the suffix, systemctl will assume {{ic|.service}}. For example, {{ic|netcfg}} and {{ic|netcfg.service}} are treated equivalent.<br />
* Mount points will automatically be translated into the appropriate {{ic|.mount}} unit. For example, specifying {{ic|/home}} is equivalent to {{ic|home.mount}}.<br />
* Similiar to mount points, devices are automatically translated into the appropriate {{ic|.device}} unit, therefore specifying {{ic|/dev/sda2}} is equivalent to {{ic|dev-sda2.device}}.<br />
<br />
See {{ic|man systemd.unit}} for details.<br />
<br />
Activate a unit immediately:<br />
<br />
# systemctl start <unit><br />
<br />
Deactivate a unit immediately:<br />
<br />
# systemctl stop <unit><br />
<br />
Restart a unit:<br />
<br />
# systemctl restart <unit><br />
<br />
Ask a unit to reload its configuration:<br />
<br />
# systemctl reload <unit><br />
<br />
Show the status of a unit, including whether it is running or not:<br />
<br />
$ systemctl status <unit><br />
<br />
Check whether a unit is already enabled or not:<br />
<br />
$ systemctl is-enabled <unit><br />
<br />
Enable a unit to be started on bootup:<br />
<br />
# systemctl enable <unit><br />
<br />
{{Note|If services do not have an {{ic|Install}} section, it usually means they are called automatically by other services. But if you need to install them manually, use the following command, replacing {{ic|foo}} with the name of the service.<br />
# ln -s /usr/lib/systemd/system/''foo''.service /etc/systemd/system/graphical.target.wants/<br />
}}<br />
<br />
Disable a unit to not start during bootup:<br />
<br />
# systemctl disable <unit><br />
<br />
Show the manual page associated with a unit (this has to be supported by the unit file):<br />
<br />
$ systemctl help <unit><br />
<br />
=== Power management ===<br />
<br />
If you are in a local {{ic|systemd-logind}} user session and no other session is active, the following commands will work without root privileges. If not (for example, because another user is logged into a tty), systemd will automatically ask you for the root password.<br />
<br />
Shut down and reboot the system:<br />
<br />
$ systemctl reboot<br />
<br />
Shut down and power-off the system:<br />
<br />
$ systemctl poweroff<br />
<br />
Shut down and halt the system:<br />
<br />
$ systemctl halt<br />
<br />
Suspend the system:<br />
<br />
$ systemctl suspend<br />
<br />
Put the system into hibernation:<br />
<br />
$ systemctl hibernate<br />
<br />
== Running DEs under systemd ==<br />
<br />
To enable graphical login, run your preferred [[Display Manager]] daemon (e.g. [[KDM]]). At the moment, service files exist for [[GDM]], [[KDM]], [[SLiM]], [[XDM]], [[LXDM]] and [[LightDM]].<br />
<br />
# systemctl enable kdm<br />
<br />
This should work out of the box. If not, you might have a {{ic|default.target}} set manually or from a older install:<br />
<br />
{{hc|# ls -l /etc/systemd/system/default.target|<br />
/etc/systemd/system/default.target -> /usr/lib/systemd/system/graphical.target}}<br />
<br />
Simply delete the symlink and systemd will use its stock {{ic|default.target}} (i.e. {{ic|graphical.target}}).<br />
<br />
# rm /etc/systemd/system/default.target<br />
<br />
=== Using systemd-logind ===<br />
<br />
{{Note|As of 2012-10-30, [[ConsoleKit]] has been [https://www.archlinux.org/news/consolekit-replaced-by-logind/ replaced by systemd-logind] as the default mechanism to login to the DE.}}<br />
<br />
In order to check the status of your user session, you can use {{ic|loginctl}}. All [[PolicyKit]] actions like suspending the system or mounting external drives will work out of the box.<br />
<br />
$ loginctl show-session $XDG_SESSION_ID<br />
<br />
== Writing custom .service files ==<br />
<br />
=== Handling dependencies ===<br />
<br />
With systemd, dependencies can be resolved by designing the unit files correctly. The most typical case is that the unit {{ic|A}} requires the unit {{ic|B}} to be running before {{ic|A}} is started. In that case add {{ic|1=Requires=B}} and {{ic|1=After=B}} to the {{ic|[Unit]}} section of {{ic|A}}. If the dependency is optional, add {{ic|1=Wants=B}} and {{ic|1=After=B}} instead. Note that {{ic|1=Wants=}} and {{ic|1=Requires=}} do not imply {{ic|1=After=}}, meaning that if {{ic|1=After=}} is not specified, the two units will be started in parallel.<br />
<br />
Dependencies are typically placed on services and not on targets. For example, {{ic|network.target}} is pulled in by whatever service configures your network interfaces, therefore ordering your custom unit after it is sufficient since {{ic|network.target}} is started anyway.<br />
<br />
=== Type ===<br />
<br />
There are several different start-up types to consider when writing a custom service file. This is set with the {{ic|1=Type=}} parameter in the {{ic|[Service]}} section. See {{ic|man systemd.service}} for a more detailed explanation.<br />
<br />
* {{ic|1=Type=simple}}: systemd considers the service to be started up immediately. The process must not fork. Do not use this type if other services need to be ordered on this service, unless it is socket activated.<br />
* {{ic|1=Type=forking}}: systemd considers the service started up once the process forks and the parent has exited. For classic daemons use this type unless you know that it is not necessary. You should specify {{ic|1=PIDFile=}} as well so systemd can keep track of the main process.<br />
* {{ic|1=Type=oneshot}}: This is useful for scripts that do a single job and then exit. You may want to set {{ic|1=RemainAfterExit=}} as well so that systemd still considers the service as active after the process has exited.<br />
* {{ic|1=Type=notify}}: Identical to {{ic|1=Type=simple}}, but with the stipulation that the daemon will send a signal to systemd when it is ready. The reference implementation for this notification is provided by {{ic|libsystemd-daemon.so}}.<br />
* {{ic|1=Type=dbus}}: The service is considered ready when the specified {{ic|BusName}} appears on DBus's system bus.<br />
<br />
=== Replacing provided unit files ===<br />
<br />
The unit files in {{ic|/etc/systemd/system/}} take precedence over the ones in {{ic|/usr/lib/systemd/system/}}.<br />
To make your own version of a unit (which will not be destroyed by an upgrade), copy the old unit file from {{ic|/usr/lib/}} to {{ic|/etc/}} and make your changes there. Alternatively you can use {{ic|.include}} to parse an existing service file and then override or add new options. For example, if you simply want to add an additional dependency to a service file, you may use:<br />
<br />
{{hc|/etc/systemd/system/<service-name>.service|2=<br />
.include /usr/lib/systemd/system/<service-name>.service<br />
<br />
[Unit]<br />
Requires=<new dependency><br />
After=<new dependency>}}<br />
<br />
Then run the following for your changes to take effect:<br />
<br />
# systemctl reenable <unit><br />
# systemctl restart <unit><br />
<br />
{{Tip|You can use {{ic|systemd-delta}} to see which unit files have been overridden and what exactly has been changed.}}<br />
<br />
=== Syntax highlighting for units within Vim ===<br />
<br />
Syntax highlighting for systemd unit files within [[Vim]] can be enabled by installing {{AUR|vim-systemd}} from the [[Arch User Repository|AUR]].<br />
<br />
== Targets ==<br />
<br />
Systemd uses ''targets'' which serve a similar purpose as runlevels but act a little different. Each ''target'' is named instead of numbered and is intended to serve a specific purpose with the possibility of having multiple ones active at the same time. Some ''targets'' are implemented by inheriting all of the services of another ''target'' and adding additional services to it. There are systemd ''target''s that mimic the common SystemVinit runlevels so you can still switch ''target''s using the familiar {{ic|telinit RUNLEVEL}} command.<br />
<br />
=== Get current targets ===<br />
<br />
The following should be used under systemd instead of {{ic|runlevel}}:<br />
<br />
$ systemctl list-units --type=target<br />
<br />
=== Create custom target ===<br />
<br />
The runlevels that are assigned a specific purpose on vanilla Fedora installs; 0, 1, 3, 5, and 6; have a 1:1 mapping with a specific systemd ''target''. Unfortunately, there is no good way to do the same for the user-defined runlevels like 2 and 4. If you make use of those it is suggested that you make a new named systemd ''target'' as {{ic|/etc/systemd/system/<your target>}} that takes one of the existing runlevels as a base (you can look at {{ic|/usr/lib/systemd/system/graphical.target}} as an example), make a directory {{ic|/etc/systemd/system/<your target>.wants}}, and then symlink the additional services from {{ic|/usr/lib/systemd/system/}} that you wish to enable.<br />
<br />
=== Targets table ===<br />
<br />
{| border="1"<br />
! SysV Runlevel !! systemd Target !! Notes<br />
|-<br />
| 0 || runlevel0.target, poweroff.target || Halt the system.<br />
|-<br />
| 1, s, single || runlevel1.target, rescue.target || Single user mode.<br />
|-<br />
| 2, 4 || runlevel2.target, runlevel4.target, multi-user.target || User-defined/Site-specific runlevels. By default, identical to 3.<br />
|-<br />
| 3 || runlevel3.target, multi-user.target || Multi-user, non-graphical. Users can usually login via multiple consoles or via the network.<br />
|-<br />
| 5 || runlevel5.target, graphical.target || Multi-user, graphical. Usually has all the services of runlevel 3 plus a graphical login.<br />
|-<br />
| 6 || runlevel6.target, reboot.target || Reboot<br />
|-<br />
| emergency || emergency.target || Emergency shell<br />
|-<br />
|}<br />
<br />
=== Change current target ===<br />
<br />
In systemd targets are exposed via "target units". You can change them like this:<br />
<br />
# systemctl isolate graphical.target<br />
<br />
This will only change the current target, and has no effect on the next boot. This is equivalent to commands such as {{ic|telinit 3}} or {{ic|telinit 5}} in Sysvinit.<br />
<br />
=== Change default target to boot into ===<br />
<br />
The standard target is {{ic|default.target}}, which is aliased by default to {{ic|graphical.target}} (which roughly corresponds to the old runlevel 5). To change the default target at boot-time, append one of the following [[kernel parameters]] to your bootloader:<br />
<br />
{{Tip|The {{ic|.target}} extension can be left out.}}<br />
<br />
* {{ic|1=systemd.unit=multi-user.target}} (which roughly corresponds to the old runlevel 3),<br />
* {{ic|1=systemd.unit=rescue.target}} (which roughly corresponds to the old runlevel 1).<br />
<br />
Alternatively, you may leave the bootloader alone and change {{ic|default.target}}. This can be done using {{ic|systemctl}}:<br />
<br />
# systemctl enable multi-user.target<br />
<br />
The effect of this command is outputted by {{ic|systemctl}}; a symlink to the new default target is made at {{ic|/etc/systemd/system/default.target}}. This works if, and only if:<br />
<br />
[Install]<br />
Alias=default.target<br />
<br />
is in the target's configuration file. Currently, {{ic|multi-user.target}} and {{ic|graphical.target}} both have it.<br />
<br />
== Journal ==<br />
<br />
Since version 38, systemd has its own logging system, the journal. Therefore, running a syslog daemon is no longer required. To read the log, use:<br />
<br />
# journalctl<br />
<br />
By default (when {{ic|Storage&#61;}} is set to {{ic|auto}} in {{ic|/etc/systemd/journald.conf}}), the journal writes to {{ic|/var/log/journal/}}. If the directory {{ic|/var/log/journal/}} does not exist (e.g. if you or some program delete it), systemd will '''not''' create it automatically, but instead write its logs to {{ic|/run/systemd/journal}}. This means that logs will be lost on reboot.<br />
<br />
=== Filtering output ===<br />
<br />
{{ic|journalctl}} allows you to filter the output by specific fields.<br />
<br />
Examples:<br />
<br />
Show all messages from this boot:<br />
<br />
# journalctl -b<br />
<br />
Follow new messages:<br />
<br />
# journalctl -f<br />
<br />
Show all messages by a specific executable:<br />
<br />
# journalctl /usr/lib/systemd/systemd<br />
<br />
Show all messages by a specific process:<br />
<br />
# journalctl _PID=1<br />
<br />
Show all messages by a specific unit:<br />
<br />
# journalctl -u netcfg<br />
<br />
See {{ic|man journalctl}}, {{ic|systemd.journal-fields}} or Lennert's [http://0pointer.de/blog/projects/journalctl.html blog post] for details.<br />
<br />
=== Journal size limit ===<br />
<br />
If the journal is persistent (non-volatile), its size limit is set to a default value of 10% of the size of the respective file system. E.g. with {{ic|/var/log/journal}} located on a 50 GiB root partition this would lead to 5 GiB of journal data. The maximum size of the persistent journal can be controlled by {{ic|SystemMaxUse}} in {{ic|/etc/systemd/journald.conf}}, so to limit it for example to 50 MiB uncomment and edit the corresponding line to:<br />
<br />
SystemMaxUse=50M<br />
<br />
Refer to {{ic|man journald.conf}} for more info.<br />
<br />
=== Journald in conjunction with syslog ===<br />
<br />
Compatibility with classic syslog implementations is provided via a socket {{ic|/run/systemd/journal/syslog}}, to which all messages are forwarded. To make the syslog daemon work with the journal, it has to bind to this socket instead of {{ic|/dev/log}} ([http://lwn.net/Articles/474968/ official announcement]). The {{pkg|syslog-ng}} package in the repositories automatically provides the necessary configuration.<br />
<br />
# systemctl enable syslog-ng<br />
<br />
== Optimization ==<br />
<br />
=== Analyzing the boot process ===<br />
<br />
==== Using systemd-analyze ====<br />
<br />
Systemd provides a tool called {{ic|systemd-analyze}} that allows you to analyze your boot process so you can see which unit files are causing your boot process to slow down. You can then optimize your system accordingly. You have to install {{Pkg|python2-dbus}} and {{Pkg|python2-cairo}} to use it.<br />
<br />
To see how much time was spent in kernelspace and userspace on boot, simply use:<br />
<br />
$ systemd-analyze<br />
<br />
{{Tip|To see how much time was spent in the initramfs, append the {{ic|timestamp}} hook to your {{ic|HOOKS}} array in {{ic|/etc/[[mkinitcpio]].conf}} and as root, rebuild your initramfs with {{ic|mkinitcpio -p linux}} }}<br />
<br />
To list the started unit files, sorted by the time each of them took to start up:<br />
<br />
$ systemd-analyze blame<br />
<br />
You can also create a SVG file which describes your boot process graphically, similiar to [[Bootchart]]:<br />
<br />
$ systemd-analyze plot > plot.svg<br />
<br />
==== Using bootchart ====<br />
<br />
You could also use a version of bootchart to visualize the boot sequence. Since you are not able to put a second init into the kernel command line you won't be able to use any of the standard bootchart setups. However the {{AUR|bootchart2}} package from [[AUR]] comes with an undocumented systemd service. After you've installed bootchart2 do:<br />
<br />
# systemctl enable bootchart<br />
<br />
Read the [https://github.com/mmeeks/bootchart bootchart documentation] for further details on using this version of bootchart.<br />
<br />
=== Readahead ===<br />
<br />
Systemd comes with its own readahead implementation, this should in principle improve boot time. However, depending on your kernel version and the type of your hard drive, your mileage may vary (i.e. it might be slower). To enable, do:<br />
<br />
# systemctl enable systemd-readahead-collect systemd-readahead-replay<br />
<br />
Remember that in order for the readahead to work its magic, you should reboot a couple of times.<br />
<br />
=== Early start for services ===<br />
<br />
One central feature of systemd is [[D-Bus]] and socket activation. This causes services to be started when they are first accessed and is generally a good thing. However, if you know that a service (like [[UPower]]) will always be started during boot, then the overall boot time might be reduced by starting it as early as possible. This can be achieved (if the service file is set up for it, which in most cases it is) by issuing:<br />
<br />
# systemctl enable upower<br />
<br />
This will cause systemd to start UPower as soon as possible, without causing races with the socket or D-Bus activation.<br />
<br />
=== Less output during boot ===<br />
<br />
Change {{ic|verbose}} to {{ic|quiet}} on the bootloader's kernel line. For some systems, particularly those with an SSD, the slow performance of the TTY is actually a bottleneck, and so less output means faster booting.<br />
<br />
== Troubleshooting ==<br />
<br />
=== Shutdown/reboot takes terribly long ===<br />
<br />
If the shutdown process takes a very long time (or seems to freeze) most likely a service not exiting is to blame. Systemd waits some time for each service to exit before trying to kill it. To find out if you are affected, see [http://freedesktop.org/wiki/Software/systemd/Debugging#Shutdown_Completes_Eventually this article].<br />
<br />
== See also ==<br />
<br />
*[http://www.freedesktop.org/wiki/Software/systemd Official Web Site]<br />
*[http://0pointer.de/public/systemd-man/ Manual Pages]<br />
*[http://freedesktop.org/wiki/Software/systemd/Optimizations systemd Optimizations]<br />
*[http://www.freedesktop.org/wiki/Software/systemd/FrequentlyAskedQuestions FAQ]<br />
*[http://www.freedesktop.org/wiki/Software/systemd/TipsAndTricks Tips And Tricks]<br />
*[http://0pointer.de/public/systemd-ebook-psankar.pdf systemd for Administrators (PDF)]<br />
*[http://fedoraproject.org/wiki/Systemd About systemd on Fedora Project]<br />
*[http://fedoraproject.org/wiki/How_to_debug_Systemd_problems How to debug systemd problems]<br />
*[http://www.h-online.com/open/features/Booting-up-Tools-and-tips-for-systemd-1570630.html Booting up: Tools and tips for systemd, a Linux init tool. In The H]<br />
*[http://0pointer.de/blog/projects/systemd.html Lennart's blog story]<br />
*[http://0pointer.de/blog/projects/systemd-update.html status update]<br />
*[http://0pointer.de/blog/projects/systemd-update-2.html status update2]<br />
*[http://0pointer.de/blog/projects/systemd-update-3.html status update3]<br />
*[http://0pointer.de/blog/projects/why.html most recent summary]<br />
*[http://fedoraproject.org/wiki/SysVinit_to_Systemd_Cheatsheet Fedora's SysVinit to systemd cheatsheet]</div>Rasihttps://wiki.archlinux.org/index.php?title=Music_Player_Daemon&diff=182922Music Player Daemon2012-02-10T12:37:48Z<p>Rasi: /* Cue Files */</p>
<hr />
<div>[[Category:Audio/Video (English)]]<br />
[[Category:Daemons and system services (English)]]<br />
{{i18n|Music Player Daemon}}<br />
[[pl:Music Player Daemon]]<br />
[[fr:MPD]]<br />
<br />
[[Wikipedia:MPD|MPD]] (music player daemon) is an audio player that has a server-client architecture. MPD runs in the background as a daemon, manages playlists and a music database, and uses very few resources. In order to interface with it, a separate client is needed. More information can be found on their [http://mpd.wikia.com/wiki/Music_Player_Daemon_Wiki website].<br />
<br />
''Please'' have a look at the official page for setup and troubleshooting instructions, the main developer called this wiki page in its current state ''"full of symptom killers"'', hence the official pages should contain better instructions.<br />
<br />
== Installation ==<br />
[[pacman|Install]] {{Pkg|mpd}}, available in the [[Official Repositories]].<br />
<br />
== Setup ==<br />
MPD is able to run globally (settings apply to all users), locally (per user settings), and in multiple instances.<br />
<br />
=== Global Configuration (daemon) ===<br />
The way of setting up mpd depends on the way it is supposed to be used. It can be configured to run on a per-user basis or at system startup with a system-wide configuration. MPD's configuration is saved in {{ic|mpd.conf}}.<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]] or [[PulseAudio]] needs to be setup and working. Do not forget to unmute the required channels.<br />
<br />
==== Starting MPD on system boot ====<br />
<br />
* As root, check if {{ic|/etc/mpd.conf}} exists and delete the file if it does. This is safe.<br />
{{bc|rm /etc/mpd.conf}}<br />
<br />
MPD comes with an example configuration file, available at {{ic|/usr/share/mpd/mpd.conf.example}}. This file holds an abundance of information on MPD configuration, and holds default mixer values you can simply uncomment.<br />
<br />
* As root, copy this example file to {{ic|/etc/mpd.conf}}.<br />
{{bc|cp /usr/share/mpd/mpd.conf.example /etc/mpd.conf}}<br />
<br />
Since MPD is being set up to run as a daemon at boot, never put this file in the user's directory like some tutorials suggest, since it will not be read. Moreover, if you previously created a {{ic|.mpdconf}} file in your home, remove it now (to set up MPD to run with user privileges alone, pleaser refer to the section [[Music_Player_Daemon#Local_Configuration_(per_user) | Local Configuration (per user)]]). This is important to prevent conflicts.<br />
<br />
==== Editing {{ic|mpd.conf}} ====<br />
The default Arch install keeps the setup in /var and uses "mpd" as default user.<br />
Edit {{ic|/etc/mpd.conf}} to reflect as such:<br />
<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 "/var/run/mpd/mpd.pid"<br />
state_file "/var/lib/mpd/mpdstate"<br />
user "mpd"<br />
# Binding to address and port causing problems in mpd-0.14.2 best to leave<br />
# commented.<br />
# bind_to_address "127.0.0.1"<br />
# port "6600"<br />
}}<br />
<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 make the following modification:<br />
{{hc|/etc/mpd.conf|2=<br />
audio_output {<br />
type "alsa" #<- Change this to "pulse"<br />
name "Sound Card"<br />
}<br />
}}<br />
<br />
===== Music directory =====<br />
<br />
* MPD needs to have +x permissions on '''ALL''' parent directories to your music collection (ie. if it's located outside of "mpd" home directory {{ic|/var/lib/mpd}}). By default useradd sets permissions on home dir to 1700 drwx------. So you will most likely need to remount the music directory under a directory that mpd has access to.<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 mpd restart<br />
See also [https://bbs.archlinux.org/viewtopic.php?id=86449 the forum thread.]<br />
<br />
* Another simpler solution would be to just create a symbolic link into {{ic|/var/lib/mpd/music}}.<br />
# mkdir /var/lib/mpd/music<br />
# ln -s YOUR_MUSIC_FOLDER /var/lib/mpd/music/<br />
# rc.d mpd restart<br />
<br />
* If your music collection is contained under multiple directories, you can make symbolic links under 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 />
* As root, create the directories and files you specified in {{ic|/etc/mpd.conf}}:<br />
# mkdir -p /var/lib/mpd/playlists /var/run/mpd<br />
# touch /var/lib/mpd/{mpd.db,mpdstate} /var/run/mpd/mpd.pid<br />
<br />
* You then need to change the file's permissions so that the daemon can modify them.<br />
# chown -R mpd /var/lib/mpd /var/run/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 depicted 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. This way, uses of {{ic|~}} in the configuration file point correctly to the home user's directory, and not root's directory. 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). Though a less used method (but perhaps more sensible) 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}}) will contain all the MPD configuration files.<br />
* Easier to avoid unforeseen read/write permission errors.<br />
<br />
To run MPD as a normal user:<br />
<br />
{{Note|This approach will not work if you want multiple users to have access to MPD at the same time.}}<br />
<br />
* Create 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 your home directory:<br />
<br />
{{bc|cp /usr/share/mpd/mpd.conf.example ~/.mpd/mpd.conf}}<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|~/.mpd/mpd.conf}} to specify these files:<br />
<br />
{{hc|~/.mpd/mpd.conf|<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. To have MPD start with the X server add it to {{ic|~/.xinitrc}} or create a {{ic|.desktop}} if you are using a common desktop (save to {{ic|~/.config/autostart/mpd.desktop}}):<br />
<br />
{{hc|mpd.desktop|2=<br />
[Desktop Entry]<br />
Encoding=UTF-8<br />
Version=0.9.4<br />
Type=Application<br />
Name=Music Player Daemon<br />
Comment=<br />
Exec=mpd<br />
StartupNotify=false<br />
Terminal=false<br />
Hidden=false<br />
}}<br />
<br />
==== Scripted Configuration ====<br />
<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 />
<br />
'''Useful if you want to run for example an icecast server.'''<br />
If you want a second MPD daemon (e.g., with icecast output to share music over the network) to use 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 daemon would use the same music collection as your first one (e.g., creating and editing a playlist under the first daemon would affect the second daemon as well, so that you do not have to create the same playlists all over again for the second daemon). Then, call this second daemon the same way from your {{ic|~/.xinitrc}} above. (Just be sure to have a different port number, so as to not conflict with your first mpd daemon).<br />
<br />
== Clients ==<br />
To control mpd, you need a client program. 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 />
<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|Dpmc|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 />
==Tips and Tricks==<br />
===Last.fm scrobbling===<br />
To scrobble your songs to [http://www.last.fm Last.fm] when using MPD, there are several alternatives.<br />
<br />
====mpdscribble====<br />
mpdscribble is a daemon, available in the "community" repository (if you prefer, the "git" version is available in the [http://aur.archlinux.org/packages.php?ID=22274 AUR]). This is arguably the best alternative, because it's the semi-official MPD scrobbler and uses the new "idle" feature in MPD for more accurate scrobbling. Also, you do not need root access to configure it, because it doesn't need any changes to {{ic|/etc}} at all. Visit [http://mpd.wikia.com/wiki/Client:Mpdscribble the official website] for more information.<br />
<br />
After you have installed mpdscribble, do the following (not as root):<br />
<br />
{{bc|$ mkdir ~/.mpdscribble}}<br />
* Create the file {{ic|~/.mpdscribble/mpdscribble.conf}} and add the following:<br />
{{hc|~/.mpdscribble/mpdscribble.conf|2=<br />
[mpdscribble] <br />
host = <your mpd host> # optional, defaults to $MPD_HOST or localhost<br />
port = <your mpd port> # optional, defaults to $MPD_PORT or 6600<br />
log = /home/<YOUR_USERNAME>/.mpdscribble/mpdscribble.log<br />
verbose = 2<br />
sleep = 1<br />
musicdir = <your music directory><br />
proxy = <your proxy> # optional, e. g. http://your.proxy:8080, defaults to none<br />
<br />
[last.fm]<br />
# last.fm section, comment if you do not use last.fm<br />
url = http://post.audioscrobbler.com/<br />
username = <your last.fm username><br />
password = <your last.fm password> <br />
journal = /home/<YOUR_USERNAME>/.mpdscribble/lastfm.journal<br />
<br />
[libre.fm]<br />
# libre.fm section, comment if you do not use libre.fm<br />
url = http://turtle.libre.fm/<br />
username = <your libre.fm username><br />
password = <your libre.fm password><br />
journal = /home/<YOUR_USERNAME>/.mpdscribble/librefm.journal<br />
}}<br />
Please note that passwords can also be written down as MD5:<br />
echo -n 'PASSWORD' | md5sum | cut -f 1 -d " "<br />
<br />
* Add {{ic|mpdscribble}} to the file in which you start {{ic|mpd}} as well (e.g. {{ic|~/.xinitrc}}):<br />
{{bc|<br />
pidof mpdscribble >& /dev/null<br />
if [ $? -ne 0 ]; then<br />
mpdscribble &<br />
fi<br />
}}<br />
<br />
====Sonata & Ario====<br />
Sonata has built-in support for scrobbling, although that requires the program to run the whole time. Additionally, Sonata doesn't cache the songs if they cannot be forwarded to Last.fm at the time of playing, meaning they will not be added to the statistics.<br />
<br />
====lastfmsubmitd====<br />
The daemon lastfmsubmitd is a daemon which may be installed from the "community" repository as well. To install it, first edit {{ic|/etc/lastfmsubmitd.conf}} to reflect your requirements and add both {{ic|lastfmsubmitd}} and {{ic|lastmp}} to the {{ic|DAEMONS}} array in {{ic|/etc/rc.conf}}.<br />
<br />
====Last.fm playback====<br />
=====Native Last.fm playback=====<br />
Since version 0.16 mpd has a very well working method to [http://mpd.wikia.com/wiki/Last.fm_Radio play back last.fm streams].<br />
{{hc|/etc/mpd.conf|2=<br />
$ playlist_plugin {<br />
name "lastfm"<br />
user "my_username"<br />
password "my_password"<br />
}<br />
}}<br />
Then use e.g. mpc to load streams<br />
{{bc|$ mpc load "lastfm://artist/Beatles"}}<br />
<br />
=====Last.fm playback with lastfmproxy=====<br />
lastfmproxy is a python script that streams a last.fm music stream to another media player. To setup, install [http://aur.archlinux.org/packages.php?ID=14214 lastfmproxy] from the [[AUR]] and then edit {{ic|/usr/share/lastfmproxy/config.py}}. If you plan to only stream to MPD on the same host, just edit the login info.<br />
<br />
{{Note | Since it installs to a read only directory but it requires read/write access for features like saving previously listened to stations, it is useful to copy {{ic|/usr/share/lastfmproxy}} to your home directory.}}<br />
<br />
Start lastfmproxy with {{ic|lastfmproxy}} and visit {{ic|http://localhost:1881/}} in your web browser. To add a last.fm station navigate to {{ic|http://localhost:1881/}} followed by the lastfm:// (e.g. {{ic|http://localhost:1881/lastfm://globaltags/punk}}). Navigate back to {{ic|http://localhost:1881/}} and download the m3u file by selecting the ''Start Listening'' link. Simply add it to your music library path.<br />
<br />
===Never play on start===<br />
This feature has recently been added to mpd git by Martin Kellerman, see commits {{ic|b57330cf75bcb339e3f268f1019c63e40d305145}} and {{ic|2fb40fe728ac07574808c40034fc0f3d2254d49d}}. As of September 2011, this feature has not yet arrived in a mpd version in the official repositories. If support for this feature is still required, have a look at the following proposals.<br />
<br />
====Installing mpd from the AUR====<br />
This is the best method currently available, but is only currently (as of April 2011) enabled in the git version. Install [https://aur.archlinux.org/packages.php?ID=19676 mpd-git] from the [[AUR]] and add {{ic|restore_paused "yes"}} to your {{ic|mpd.conf}} file.<br />
<br />
If you have issues with connecting your client to [https://aur.archlinux.org/packages.php?ID=19676 mpd-git], see [[Music Player Daemon#Other issues when attempting to connect to mpd with a client]].<br />
<br />
====Method 1====<br />
If you do not want MPD to always play on your system start, but yet you want to preserve the other state information, add the following lines to your {{ic|/etc/rc.d/mpd}} file:<br />
=====Method 1.1=====<br />
Simpler, working method (disables playing on startup of mpd daemon):<br />
start)<br />
...<br />
mpc -q pause #add this line only<br />
add_daemon mpd<br />
stat_done<br />
=====Method 1.2=====<br />
This method was described here before Method 1.1 and is much more complicated:<br />
'' ...''<br />
'' stat_busy "Starting Music Player Daemon"''<br />
<br />
# always start in paused state<br />
awk '/^state_file[ \t]+"[^"]+"$/ {<br />
match($0, "\".+\"")<br />
sfile = substr($0, RSTART + 1, RLENGTH - 2)<br />
} /^user[ \t]+"[^"]+"$/ {<br />
match($0, "\".+\"")<br />
user = substr($0, RSTART + 1, RLENGTH - 2)<br />
} END {<br />
if (sfile == "")<br />
exit;<br />
if (user != "")<br />
sub(/^~/, "/home/" user, sfile)<br />
system("sed -i \x27s|^\\(state:[ \\t]\\{1,\\}\\)play$|\\1pause|\x27 \x27" sfile "\x27")<br />
}' /etc/mpd.conf<br />
<br />
'' /usr/bin/mpd /etc/mpd.conf &> /dev/null''<br />
'' ...''<br />
<br />
This will change the player status to "paused", if it was stopped while playing. Next, you want this file to be preserved, so MPD updates won't erase this edit. Add (or edit) this line to your {{ic|/etc/pacman.conf}}:<br />
NoUpgrade = etc/rc.d/mpd<br />
<br />
====Method 2====<br />
Another simpler method, would be to add mpd to your {{ic|[[rc.conf]]}} daemons array and add {{ic|mpc stop}} or {{ic|mpc pause}} to {{ic|/etc/rc.local.shutdown}} and to {{ic|/etc/rc.local}}. (Remember you must have mpc installed to use this method).<br />
<br />
Adding only the order in {{ic|/etc/rc.local}} cannot assure that mpd will play absolutely nothing, since there may be a delay before the stop command is executed. <br />
On the other hand, if you only add the order to {{ic|/etc/rc.local.shutdown}}, that will assure that mpd won't play at all, as long as you properly shutdown your system.<br />
Even though they are redundant, adding it to {{ic|/etc/rc.local}} would serve as a safety for those, presumably, rare occasions when you do not shutdown the system properly.<br />
<br />
====Method 3====<br />
The general idea is to ask mpd to pause music when the user logs out, so that mpd will stick to the "pause" state after a reboot. Sending such command can be achieved using [http://www.archlinux.org/packages/extra/x86_64/mpc/ mpc], the command line interface to MPD.<br />
<br />
GDM users can then add {{ic|/usr/bin/mpc pause}} to {{ic|/etc/gdm/PostSession/Default}} (be sure to add it before {{ic|exit 0}}):<br />
<br />
Non-GDM users can use their own login manager's method to launch the line at logout.<br />
<br />
===MPD & ALSA===<br />
Sometimes, when using other audio outputs, e.g: some web pages containing Flash applets, MPD is rendered unable to play (until it is restarted). The error comes up in mpd's log:<br />
<br />
Error opening alsa device "hw:0,0": Device or resource busy<br />
<br />
Reasons for this may be:<br />
* The sound card does not support hardware mixing (uses '''dmix''' plugin)<br />
* An application does not work with ALSA's default settings<br />
<br />
For a detailed description, it is recommended to take a look at [http://mpd.wikia.com/wiki/Alsa this] link. <br />
<br />
This problem may be solved by adding the following lines to {{ic|mpd.conf}}:<br />
{{hc|mpd.conf|2=<br />
audio_output {<br />
type "alsa"<br />
name "Sound Card"<br />
options "dev=dmixer"<br />
device "plug:dmix"<br />
}}<br />
<br />
To make the changes have effect, restart mpd (e.g. {{ic|/etc/rc.d/mpd restart}}, if it is a global configuration).<br />
<br />
====High CPU usage with ALSA====<br />
When using MPD with ALSA, users may experience MPD taking up lots of CPU (around 20-30%). This is caused by most sound cards supporting 48kHz and most music being 44kHz, thus forcing MPD to resample it. This operation takes lots of CPU cycles and results into high usage.<br />
<br />
For most users the problem should be solved by telling MPD not to use resampling by adding {{ic|auto_resample "no"}} into audio_output-part of {{ic|/etc/mpd.conf}}. This will degrade quality slightly, however.<br />
<br />
{{hc|mpd.conf|2=<br />
audio_output {<br />
type "alsa"<br />
name "My ALSA Device"<br />
auto_resample "no"<br />
}<br />
}}<br />
<br />
Although it may not give as drastic a speedup, enabling mmap may still speed things up:<br />
{{hc|mpd.conf|2=<br />
audio_output {<br />
type "alsa"<br />
name "My ALSA Device"<br />
use_mmap "yes"<br />
}<br />
}}<br />
<br />
Some users might also want to tell dmix to use 44kHz as well. More info about tuning performance of your MPD can be found on the [http://mpd.wikia.com/wiki/Tuning MPD wiki]<br />
<br />
====Example configuration: Output with 44.1 KHz at e. g. 16 bit depth, multiple programs at once====<br />
''Why these formats?'' Because they are standard CDA, because ALSA on its own allows more than one program "to sound" only with dmix — whose resampling algorithm is inferior — and because dmix by default resamples anything lower to 48 KHz (or whatever higher format is playing at the time). Also, some get clicking sounds if at least {{ic|mpd.conf}} is not changed this way.<br />
<br />
''What's the downside?'' These settings cause ''everything'' (if necessary) to be resampled to this format, such as material from DVD or TV which usually is at 48 KHz. But there is no known way to have ALSA dynamically change the format, and particularly if you listen to far more CDs than anything else the occasional 48 → 44.1 isn't too great a loss.<br />
<br />
The following assumes that there are not already other settings which conflict resp. overwrite it. This applies especially to the current user's potential {{ic|~/.asoundrc}} — which MPD as its own user ignores, therefore the following should go to {{ic|/etc/asound.conf}}:<br />
<br />
{{hc|/etc/asound.conf|<br />
defaults.pcm.dmix.rate 44100 # Force 44.1 KHz<br />
defaults.pcm.dmix.format S16_LE # Force 16 bits<br />
}}<br />
<br />
{{hc|/etc/mpd.conf|2=<br />
audio_output {<br />
type "alsa" # Use the ALSA output plugin.<br />
name "HDA Intel" # Can be called anything or nothing tmk, but must be present.<br />
options "dev=dmixer"<br />
device "plug:dmix" # Both lines cause MPD to output to dmix.<br />
format "44100:16:2" # the actual format<br />
auto_resample "no" # This bypasses ALSA's own algorithms, which generally are inferior. See below how to choose a different one.<br />
use_mmap "yes" # Minor speed improvement, should work with all modern cards.<br />
}<br />
<br />
samplerate_converter "0" # MPD's best, most CPU intensive algorithm. See 'man mpd.conf' for others — for anything other than the poorest "internal", libsamplerate must be installed.<br />
}}<br />
<br />
{{Note|MPD gives the mp3 format a special treatment at decoding: It's always outputted as 24 bit. (The conversion as forced by the ''format'' line only comes after that.)}}<br />
<br />
If one wants to leave the bit depth decision to ALSA resp. MPD, comment out resp. omit the ''dmix.format'' line and change the one for mpd with ''format'' to "44100:*:2".<br />
<br />
{{Note|''Crossfading'' between files decoded at two different bit depths (say, one mp3 and one 16 bit flac) does not work unless conversion is active.}}<br />
<br />
=== Control MPD with lirc ===<br />
There are already some clients designed for communications between lircd and MPD, however, as far as the practical use, they aren't very useful since their functions are limited.<br />
<br />
It's recommended to use mpc with irexec. mpc is a command line player which only sends the command to MPD and exits immediately, which is perfect for irexec, the command runner included in lirc. What irexec does is that it runs a specified command once received a remote control button.<br />
<br />
First of all, please setup your remotes as referred to the '''[[Lirc]]''' article.<br />
<br />
Edit your favored lirc startup configuration file, default location is {{ic|~/.lircrc}}.<br />
<br />
Fill the file with the following pattern:<br />
begin<br />
prog = irexec<br />
button = <button_name><br />
config = <command_to_run><br />
repeat = <0 or 1><br />
end<br />
<br />
An useful example:<br />
## irexec<br />
begin<br />
prog = irexec<br />
button = play_pause<br />
config = mpc toggle<br />
repeat = 0<br />
end<br />
<br />
begin<br />
prog = irexec<br />
button = stop<br />
config = mpc stop<br />
repeat = 0<br />
end<br />
begin<br />
prog = irexec<br />
button = previous<br />
config = mpc prev<br />
repeat = 0<br />
end<br />
begin<br />
prog = irexec<br />
button = next<br />
config = mpc next<br />
repeat = 0<br />
end<br />
begin<br />
prog = irexec<br />
button = volup<br />
config = mpc volume +2<br />
repeat = 1<br />
end<br />
begin<br />
prog = irexec<br />
button = voldown<br />
config = mpc volume -2<br />
repeat = 1<br />
end<br />
begin<br />
prog = irexec<br />
button = pbc<br />
config = mpc random<br />
repeat = 0<br />
end<br />
begin<br />
prog = irexec<br />
button = pdvd<br />
config = mpc update<br />
repeat = 0<br />
end<br />
begin<br />
prog = irexec<br />
button = right<br />
config = mpc seek +00:00:05<br />
repeat = 0<br />
end<br />
begin<br />
prog = irexec<br />
button = left<br />
config = mpc seek -00:00:05<br />
repeat = 0<br />
end<br />
begin<br />
prog = irexec<br />
button = up<br />
config = mpc seek +1%<br />
repeat = 0<br />
end<br />
begin<br />
prog = irexec<br />
button = down<br />
config = mpc seek -1%<br />
repeat = 0<br />
end<br />
<br />
There are more functions for mpc, run {{ic|man mpc}} for more info.<br />
<br />
===Control MPD with bluetooth phone===<br />
You can also control MPD (to a certain extent) using a bluetooth enabled phone. You need to do the following:<br />
<br />
* install [http://remuco.sourceforge.net/index.php/Remuco remuco] -- a wireless remote control for several Linux media players ([http://aur.archlinux.org/packages.php?ID=25072 aur])<br />
* transfer remuco client -- jar/jad files from {{ic|/usr/share/remuco/client/}} to your phone and install it<br />
* run {{ic|remuco-mpd}} (as current user)<br />
* run remuco on your phone, define a new bluetooth remuco connection (pair first if you haven't done this previously) and explore its capabilities<br />
<br />
More information about remuco including troubleshooting to be found at its [http://remuco.sourceforge.net/index.php/Remuco homepage]<br />
<br />
=== MPD & PulseAudio ===<br />
Edit {{ic|/etc/mpd.conf}}, and uncomment the audio_output section for the type "pulse". The server and sink lines of it should be commented unless you know what you're doing.<br />
<br />
Then, add the mpd user (and yours if you haven't done so already) to the necessary pulse groups. The pulse-access group should be sufficient but you may want to add pulse-rt as well. The group "pulse" doesn't appear to be necessary.<br />
# gpasswd -a mpd pulse-access<br />
# gpasswd -a mpd pulse-rt<br />
<br />
Lastly, you may or may not need to copy {{ic|~/.pulse-cookie}} from your current (pulse working) user's dir to your mpd user's home directory. It is likely to be {{ic|/var/lib/mpd}} if you followed the first part of this wiki. This would probably only allow your current user to listen in on MPD's pulse. You may consider running pulse system-wide if that's insufficient.<br />
<br />
=== Cue Files ===<br />
<br />
To make cue file support actually work, you have to work around a nasty libcue bug. Libcue copied some files directly from libcdio, making it conflict with it. Steps to do to get proper cue support:<br />
<br />
* remove {{Ic|libcdio}} temporary ({{Ic|pacman -Rdd libcdio}})<br />
* install {{Pkg|libcue}}<br />
* install mpd with [[ABS]] or from [[AUR]].<br />
* install {{Ic|libcdio}} again<br />
<br />
Version 0.17 will fix this issue, implementing its very own cue parser, which will then also allow parsing cuesheets, that are embedded into the files tags (CUESHEET tag). This will work for most, if not all relevant music files.<br />
<br />
=== HTTP Streaming ===<br />
Since version 0.15 there is a built-in HTTP streaming daemon/server that comes with MPD. To activate this server simply set it as output device in mpd.conf:<br />
<br />
audio_output { <br />
type "httpd" <br />
name "My HTTP Stream" <br />
encoder "vorbis" # optional, vorbis or lame <br />
port "8000" <br />
# quality "5.0" # do not define if bitrate is defined <br />
bitrate "128" # do not define if quality is defined <br />
format "44100:16:1" <br />
}<br />
<br />
Then to listen to this stream simply open the URL of your mpd server (along with the specified port) in your favorite music player. Note: You may have to specify the file format of the stream using an appropriate file extension in the URL. For example, using Winamp 5.5, You would use http://192.168.1.2:8000/mpd.ogg rather than http://192.168.1.2:8000/.<br />
<br />
To use mpd to connect to the stream from another computer.<br />
<br />
mpc add http://192.168.1.2:8000<br />
<br />
== Troubleshooting ==<br />
=== Autodetection failed ===<br />
During the start of MPD, it tries to autodetect your set-up and configure output and volume control accordingly. Though this mostly goes well, it will fail for some systems. It may help to tell MPD specifically what to use as output and mixer control. If you copied {{ic|/etc/mpd.conf}} over from {{ic|/etc/mpd.conf.example}} as mentioned above, you can simply uncomment:<br />
<br />
Example for alsa output type and alsa mixer:<br />
audio_output {<br />
type "alsa"<br />
name "My ALSA Device"<br />
device "hw:0,0" # optional<br />
format "44100:16:2" # optional<br />
mixer_type "hardware"<br />
mixer_device "default"<br />
mixer_control "PCM"<br />
}<br />
<br />
'''Note:''' in case of permission problems when using ESD with MPD run this as root:<br />
# chsh -s /bin/true mpd<br />
<br />
=== Avoiding timeouts ===<br />
To get rid of timeouts (i.e. when you paused music for long time) in gpmc and other clients uncomment and increase {{ic|connection_timeout}} option in {{ic|mpd.conf}}.<br />
<br />
If files and/or titles are shown in wrong encoding, uncomment and change {{ic|filesystem_charset}} and {{ic|id3v1_encoding}} options.<br />
Note that you cannot set encoding for ID3 v2 tags. To workaround this you may use [http://mpd.wikia.com/wiki/GenericDecoder#Generic_Tagreader external tag readers].<br />
<br />
If you want to use another computer to control MPD over a network, the {{ic|bind_to_address}} option in {{ic|mpd.conf}} will need to be set to either your IP address, or {{ic|any}} if your IP address changes frequently. <br />
<br />
'''Streaming'''<br><br />
With the latest version of MPD (0.15), built-in httpd streaming is now available.<br />
<br />
To activate this feature, you'll just need to add a new output of type httpd in {{ic|mpd.conf}}:<br />
audio_output {<br />
type "httpd"<br />
name "What you want"<br />
encoder "lame" # vorbis or lame supported<br />
port "8000"<br />
bitrate "128"<br />
format "44100:16:2" # change 2 to 1 for mono<br />
}<br />
<br />
Restart the mpd daemon and, from another computer, simply load the stream as any other url. <br />
$ mplayer http://<server's IP>:8000<br />
<br />
{{Note | You must open the port on your router / firewall for the stream to be connectible to from another computer.}}<br />
<br />
Most players (i.e. vlc or xmms2) should also be able to load the stream via their "add url..." menu option.<br />
<br />
This is a nice clean way to replace your current icecast setup with something natively supported within MPD.<br />
<br />
=== MPD hangs on first startup ===<br />
This is a common error that's caused by corrupt mp3 tags.<br />
Here is an experimental way to solve this issue.<br />
Requirements:<br />
* kid3<br />
* easytag<br />
<br />
This method is very tedious, especially with a huge database. Just as a baseline it took 2.5h to fix a 16Gb DB.<br />
<br />
==== Easy Tag ====<br />
The purpose of easytag here is that easytag detects the error in the tags, but like MPD it hangs and dies. The trick here is that easy tags actually tells you what file is causing the problem on the status bar.<br />
Before starting easytag make sure to have a terminal close to be ready to kill easy tag to avoid a hang. Once you are ready, on the tree view select the directory where all your music is located. By default easytag starts to search all subdirectories for mp3 files. Once you notice that easytag stopped scanning for songs, make note of the culprit and kill easytag.<br />
<br />
==== KID3 ====<br />
Here's where kid3 comes in handy. With kid3 go to the offending song and rewrite one of the tags. then save the file. This should force kid3 to rewrite the whole tag again fixing the problem with MPD and easy tag hanging.<br />
<br />
Repeat this procedure until your music library is done.<br />
<br />
=== Cannot connect to mpd: host "localhost" not found: Temporary failure in name resolution ===<br />
Cannot connect to MPD (with ncmpcpp), if you are disconnected from network. Solution is [[IPv6 - Disabling the Module|disable IPv6]] or add line to /etc/hosts<br />
::1 localhost.localdomain localhost<br />
<br />
=== Other issues when attempting to connect to mpd with a client ===<br />
Some have reported being unable to access mpd with various clients, for example seeing errors like these:<br />
$ ncmpcpp<br />
Cannot connect to mpd: Connection closed by the server<br />
$ sonata<br />
2011-02-13 18:33:05 Connection lost while reading MPD hello<br />
2011-02-13 18:33:05 Not connected<br />
2011-02-13 18:33:05 Not connected<br />
<br />
Please see posts on ncmpcpp on the Arch Forums [https://bbs.archlinux.org/viewtopic.php?id=109962 HERE] and [https://bbs.archlinux.org/viewtopic.php?id=113493 HERE]. Also see {{Bug|22071}}.<br />
<br />
==== First fix ====<br />
Check {{ic|mpd.conf}} for a line like {{ic|mpd.error}} and remove it. The mpd error file is deprecated and has been removed.<br />
<br />
==== Second fix ====<br />
{{Note|I'm not so sure this is a good idea. There is a warning about changing the address to bind to in the default mpd.conf. If this does not help, you might want to comment out the changes.}}<br />
If that doesn't help, add the following to {{ic|mpd.conf}}:<br />
{{bc|<br />
bind_to_address "127.0.0.1"<br />
port "6600"<br />
}}<br />
<br />
Afterwards, instruct your client to connect via 127.0.0.1. For example, add the following to the ncmpcpp config file:<br />
{{bc|<br />
mpd_host "127.0.0.1"<br />
mpd_port "6600"<br />
}}<br />
<br />
=== Port 6600 already in use ===<br />
MPD needs to bind to port 6600 and cannot start if it's already in use. The most common reason for this is that the user has started MPD once and then subsequently tried to start mpd again. In general, nothing should be done here.<br />
<br />
If port 6600 is tied up for some other reason, one can use the following command to find the offending process:<br />
# netstat -tulpan | grep 6600<br />
<br />
This will list IP:Port and the process name holding the connection (root privileges are required to see all processes).<br />
<br />
If you need to restart mpd for whatever reason, use:<br />
{{bc|<br />
$ mpd --kill<br />
$ mpd <br />
}}<br />
A more brute-force approach:<br />
{{bc|<br />
$ killall mpd<br />
$ mpd <br />
}}<br />
{{Note| If you typically run MPD as root, you will need to run the above commands as root.}}<br />
<br />
In the latest version of MPD, --create-db is completely deprecated. The database will be created automagically on first run and can subsequently be updated via your client (i.e. mpc update). You can now use inotify support to automatically update your music database. Add the following to {{hc|mpd.conf|auto_update "yes"}} to enable it.<br />
<br />
=== Binding to IPV6 before IPV4 ===<br />
If on startup, you see this message:<br />
listen: bind to '0.0.0.0:6600' failed: Address already in use (continuing anyway, because binding to '[::]:6600' succeeded)<br />
MPD is attempting to bind to the ipv6 interface before binding to ipv4. If you want to use your ipv4 interface, hardcode it in mpd.conf, like so:<br />
bind_to_address "127.0.0.1"<br />
Or, you could specify several binds, for example, to have MPD listen on localhost and the external IP of your network card:<br />
bind_to_address "127.0.0.1"<br />
bind_to_address "192.168.1.13"<br />
<br />
=== Crackling sound with some audio files ===<br />
This is usually a playback speed problem and can be fixed by uncommenting the audio_output_format line in:<br />
<br />
{{hc|/etc/mpd.conf|<br />
audio_output_format "44100:16:2"}}<br />
<br />
This is usually a sane value for most mp3 files.<br />
<br />
=== daemon: cannot setgid for user "mpd": Operation not permitted ===<br />
<br />
The error is stating that the user starting the process (you) does not have permissions to become another user (mpd) which the configuration has told that process to run as.<br />
<br />
To solve the issue, simply start mpd as root.<br />
{{bc|$ su -c "rc.d start mpd"}}<br />
or<br />
{{bc|# rc.d start mpd}}<br />
<br />
== External links ==<br />
* [http://mpd.wikia.com/wiki/Music_Player_Daemon_Wiki Official Web Site and wiki]<br />
* [http://mpd.wikia.com/wiki/Clients Sorted List of MPD Clients]<br />
* [http://www.musicpd.org/forum/ MPD forum]</div>Rasihttps://wiki.archlinux.org/index.php?title=Music_Player_Daemon&diff=182618Music Player Daemon2012-02-07T17:30:33Z<p>Rasi: /* Cue Files */</p>
<hr />
<div>[[Category:Audio/Video (English)]]<br />
[[Category:Daemons and system services (English)]]<br />
{{i18n|Music Player Daemon}}<br />
[[pl:Music Player Daemon]]<br />
[[fr:MPD]]<br />
<br />
[[Wikipedia:MPD|MPD]] (music player daemon) is an audio player that has a server-client architecture. MPD runs in the background as a daemon, manages playlists and a music database, and uses very few resources. In order to interface with it, a separate client is needed. More information can be found on their [http://mpd.wikia.com/wiki/Music_Player_Daemon_Wiki website].<br />
<br />
''Please'' have a look at the official page for setup and troubleshooting instructions, the main developer called this wiki page in its current state ''"full of symptom killers"'', hence the official pages should contain better instructions.<br />
<br />
== Installation ==<br />
[[pacman|Install]] {{Pkg|mpd}}, available in the [[Official Repositories]].<br />
<br />
== Setup ==<br />
MPD is able to run globally (settings apply to all users), locally (per user settings), and in multiple instances.<br />
<br />
=== Global Configuration (daemon) ===<br />
The way of setting up mpd depends on the way it is supposed to be used. It can be configured to run on a per-user basis or at system startup with a system-wide configuration. MPD's configuration is saved in {{ic|mpd.conf}}.<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]] or [[PulseAudio]] needs to be setup and working. Do not forget to unmute the required channels.<br />
<br />
==== Starting MPD on system boot ====<br />
<br />
* As root, check if {{ic|/etc/mpd.conf}} exists and delete the file if it does. This is safe.<br />
{{bc|rm /etc/mpd.conf}}<br />
<br />
MPD comes with an example configuration file, available at {{ic|/usr/share/mpd/mpd.conf.example}}. This file holds an abundance of information on MPD configuration, and holds default mixer values you can simply uncomment.<br />
<br />
* As root, copy this example file to {{ic|/etc/mpd.conf}}.<br />
{{bc|cp /usr/share/mpd/mpd.conf.example /etc/mpd.conf}}<br />
<br />
Since MPD is being set up to run as a daemon at boot, never put this file in the user's directory like some tutorials suggest, since it will not be read. Moreover, if you previously created a {{ic|.mpdconf}} file in your home, remove it now (to set up MPD to run with user privileges alone, pleaser refer to the section [[Music_Player_Daemon#Local_Configuration_(per_user) | Local Configuration (per user)]]). This is important to prevent conflicts.<br />
<br />
==== Editing {{ic|mpd.conf}} ====<br />
The default Arch install keeps the setup in /var and uses "mpd" as default user.<br />
Edit {{ic|/etc/mpd.conf}} to reflect as such:<br />
<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 "/var/run/mpd/mpd.pid"<br />
state_file "/var/lib/mpd/mpdstate"<br />
user "mpd"<br />
# Binding to address and port causing problems in mpd-0.14.2 best to leave<br />
# commented.<br />
# bind_to_address "127.0.0.1"<br />
# port "6600"<br />
}}<br />
<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 make the following modification:<br />
{{hc|/etc/mpd.conf|2=<br />
audio_output {<br />
type "alsa" #<- Change this to "pulse"<br />
name "Sound Card"<br />
}<br />
}}<br />
<br />
===== Music directory =====<br />
<br />
* MPD needs to have +x permissions on '''ALL''' parent directories to your music collection (ie. if it's located outside of "mpd" home directory {{ic|/var/lib/mpd}}). By default useradd sets permissions on home dir to 1700 drwx------. So you will most likely need to remount the music directory under a directory that mpd has access to.<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 mpd restart<br />
See also [https://bbs.archlinux.org/viewtopic.php?id=86449 the forum thread.]<br />
<br />
* Another simpler solution would be to just create a symbolic link into {{ic|/var/lib/mpd/music}}.<br />
# mkdir /var/lib/mpd/music<br />
# ln -s YOUR_MUSIC_FOLDER /var/lib/mpd/music/<br />
# rc.d mpd restart<br />
<br />
* If your music collection is contained under multiple directories, you can make symbolic links under 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 />
* As root, create the directories and files you specified in {{ic|/etc/mpd.conf}}:<br />
# mkdir -p /var/lib/mpd/playlists /var/run/mpd<br />
# touch /var/lib/mpd/{mpd.db,mpdstate} /var/run/mpd/mpd.pid<br />
<br />
* You then need to change the file's permissions so that the daemon can modify them.<br />
# chown -R mpd /var/lib/mpd /var/run/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 depicted 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. This way, uses of {{ic|~}} in the configuration file point correctly to the home user's directory, and not root's directory. 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). Though a less used method (but perhaps more sensible) 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}}) will contain all the MPD configuration files.<br />
* Easier to avoid unforeseen read/write permission errors.<br />
<br />
To run MPD as a normal user:<br />
<br />
{{Note|This approach will not work if you want multiple users to have access to MPD at the same time.}}<br />
<br />
* Create 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 your home directory:<br />
<br />
{{bc|cp /usr/share/mpd/mpd.conf.example ~/.mpd/mpd.conf}}<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|~/.mpd/mpd.conf}} to specify these files:<br />
<br />
{{hc|~/.mpd/mpd.conf|<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. To have MPD start with the X server add it to {{ic|~/.xinitrc}} or create a {{ic|.desktop}} if you are using a common desktop (save to {{ic|~/.config/autostart/mpd.desktop}}):<br />
<br />
{{hc|mpd.desktop|2=<br />
[Desktop Entry]<br />
Encoding=UTF-8<br />
Version=0.9.4<br />
Type=Application<br />
Name=Music Player Daemon<br />
Comment=<br />
Exec=mpd<br />
StartupNotify=false<br />
Terminal=false<br />
Hidden=false<br />
}}<br />
<br />
==== Scripted Configuration ====<br />
<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 />
<br />
'''Useful if you want to run for example an icecast server.'''<br />
If you want a second MPD daemon (e.g., with icecast output to share music over the network) to use 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 daemon would use the same music collection as your first one (e.g., creating and editing a playlist under the first daemon would affect the second daemon as well, so that you do not have to create the same playlists all over again for the second daemon). Then, call this second daemon the same way from your {{ic|~/.xinitrc}} above. (Just be sure to have a different port number, so as to not conflict with your first mpd daemon).<br />
<br />
== Clients ==<br />
To control mpd, you need a client program. 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 />
<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|Dpmc|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 />
==Tips and Tricks==<br />
===Last.fm scrobbling===<br />
To scrobble your songs to [http://www.last.fm Last.fm] when using MPD, there are several alternatives.<br />
<br />
====mpdscribble====<br />
mpdscribble is a daemon, available in the "community" repository (if you prefer, the "git" version is available in the [http://aur.archlinux.org/packages.php?ID=22274 AUR]). This is arguably the best alternative, because it's the semi-official MPD scrobbler and uses the new "idle" feature in MPD for more accurate scrobbling. Also, you do not need root access to configure it, because it doesn't need any changes to {{ic|/etc}} at all. Visit [http://mpd.wikia.com/wiki/Client:Mpdscribble the official website] for more information.<br />
<br />
After you have installed mpdscribble, do the following (not as root):<br />
<br />
{{bc|$ mkdir ~/.mpdscribble}}<br />
* Create the file {{ic|~/.mpdscribble/mpdscribble.conf}} and add the following:<br />
{{hc|~/.mpdscribble/mpdscribble.conf|2=<br />
[mpdscribble] <br />
host = <your mpd host> # optional, defaults to $MPD_HOST or localhost<br />
port = <your mpd port> # optional, defaults to $MPD_PORT or 6600<br />
log = /home/<YOUR_USERNAME>/.mpdscribble/mpdscribble.log<br />
verbose = 2<br />
sleep = 1<br />
musicdir = <your music directory><br />
proxy = <your proxy> # optional, e. g. http://your.proxy:8080, defaults to none<br />
<br />
[last.fm]<br />
# last.fm section, comment if you do not use last.fm<br />
url = http://post.audioscrobbler.com/<br />
username = <your last.fm username><br />
password = <your last.fm password> <br />
journal = /home/<YOUR_USERNAME>/.mpdscribble/lastfm.journal<br />
<br />
[libre.fm]<br />
# libre.fm section, comment if you do not use libre.fm<br />
url = http://turtle.libre.fm/<br />
username = <your libre.fm username><br />
password = <your libre.fm password><br />
journal = /home/<YOUR_USERNAME>/.mpdscribble/librefm.journal<br />
}}<br />
Please note that passwords can also be written down as MD5:<br />
echo -n 'PASSWORD' | md5sum | cut -f 1 -d " "<br />
<br />
* Add {{ic|mpdscribble}} to the file in which you start {{ic|mpd}} as well (e.g. {{ic|~/.xinitrc}}):<br />
{{bc|<br />
pidof mpdscribble >& /dev/null<br />
if [ $? -ne 0 ]; then<br />
mpdscribble &<br />
fi<br />
}}<br />
<br />
====Sonata & Ario====<br />
Sonata has built-in support for scrobbling, although that requires the program to run the whole time. Additionally, Sonata doesn't cache the songs if they cannot be forwarded to Last.fm at the time of playing, meaning they will not be added to the statistics.<br />
<br />
====lastfmsubmitd====<br />
The daemon lastfmsubmitd is a daemon which may be installed from the "community" repository as well. To install it, first edit {{ic|/etc/lastfmsubmitd.conf}} to reflect your requirements and add both {{ic|lastfmsubmitd}} and {{ic|lastmp}} to the {{ic|DAEMONS}} array in {{ic|/etc/rc.conf}}.<br />
<br />
====Last.fm playback====<br />
=====Native Last.fm playback=====<br />
Since version 0.16 mpd has a very well working method to [http://mpd.wikia.com/wiki/Last.fm_Radio play back last.fm streams].<br />
{{hc|/etc/mpd.conf|2=<br />
$ playlist_plugin {<br />
name "lastfm"<br />
user "my_username"<br />
password "my_password"<br />
}<br />
}}<br />
Then use e.g. mpc to load streams<br />
{{bc|$ mpc load "lastfm://artist/Beatles"}}<br />
<br />
=====Last.fm playback with lastfmproxy=====<br />
lastfmproxy is a python script that streams a last.fm music stream to another media player. To setup, install [http://aur.archlinux.org/packages.php?ID=14214 lastfmproxy] from the [[AUR]] and then edit {{ic|/usr/share/lastfmproxy/config.py}}. If you plan to only stream to MPD on the same host, just edit the login info.<br />
<br />
{{Note | Since it installs to a read only directory but it requires read/write access for features like saving previously listened to stations, it is useful to copy {{ic|/usr/share/lastfmproxy}} to your home directory.}}<br />
<br />
Start lastfmproxy with {{ic|lastfmproxy}} and visit {{ic|http://localhost:1881/}} in your web browser. To add a last.fm station navigate to {{ic|http://localhost:1881/}} followed by the lastfm:// (e.g. {{ic|http://localhost:1881/lastfm://globaltags/punk}}). Navigate back to {{ic|http://localhost:1881/}} and download the m3u file by selecting the ''Start Listening'' link. Simply add it to your music library path.<br />
<br />
===Never play on start===<br />
This feature has recently been added to mpd git by Martin Kellerman, see commits {{ic|b57330cf75bcb339e3f268f1019c63e40d305145}} and {{ic|2fb40fe728ac07574808c40034fc0f3d2254d49d}}. As of September 2011, this feature has not yet arrived in a mpd version in the official repositories. If support for this feature is still required, have a look at the following proposals.<br />
<br />
====Installing mpd from the AUR====<br />
This is the best method currently available, but is only currently (as of April 2011) enabled in the git version. Install [https://aur.archlinux.org/packages.php?ID=19676 mpd-git] from the [[AUR]] and add {{ic|restore_paused "yes"}} to your {{ic|mpd.conf}} file.<br />
<br />
If you have issues with connecting your client to [https://aur.archlinux.org/packages.php?ID=19676 mpd-git], see [[Music Player Daemon#Other issues when attempting to connect to mpd with a client]].<br />
<br />
====Method 1====<br />
If you do not want MPD to always play on your system start, but yet you want to preserve the other state information, add the following lines to your {{ic|/etc/rc.d/mpd}} file:<br />
=====Method 1.1=====<br />
Simpler, working method (disables playing on startup of mpd daemon):<br />
start)<br />
...<br />
mpc -q pause #add this line only<br />
add_daemon mpd<br />
stat_done<br />
=====Method 1.2=====<br />
This method was described here before Method 1.1 and is much more complicated:<br />
'' ...''<br />
'' stat_busy "Starting Music Player Daemon"''<br />
<br />
# always start in paused state<br />
awk '/^state_file[ \t]+"[^"]+"$/ {<br />
match($0, "\".+\"")<br />
sfile = substr($0, RSTART + 1, RLENGTH - 2)<br />
} /^user[ \t]+"[^"]+"$/ {<br />
match($0, "\".+\"")<br />
user = substr($0, RSTART + 1, RLENGTH - 2)<br />
} END {<br />
if (sfile == "")<br />
exit;<br />
if (user != "")<br />
sub(/^~/, "/home/" user, sfile)<br />
system("sed -i \x27s|^\\(state:[ \\t]\\{1,\\}\\)play$|\\1pause|\x27 \x27" sfile "\x27")<br />
}' /etc/mpd.conf<br />
<br />
'' /usr/bin/mpd /etc/mpd.conf &> /dev/null''<br />
'' ...''<br />
<br />
This will change the player status to "paused", if it was stopped while playing. Next, you want this file to be preserved, so MPD updates won't erase this edit. Add (or edit) this line to your {{ic|/etc/pacman.conf}}:<br />
NoUpgrade = etc/rc.d/mpd<br />
<br />
====Method 2====<br />
Another simpler method, would be to add mpd to your {{ic|[[rc.conf]]}} daemons array and add {{ic|mpc stop}} or {{ic|mpc pause}} to {{ic|/etc/rc.local.shutdown}} and to {{ic|/etc/rc.local}}. (Remember you must have mpc installed to use this method).<br />
<br />
Adding only the order in {{ic|/etc/rc.local}} cannot assure that mpd will play absolutely nothing, since there may be a delay before the stop command is executed. <br />
On the other hand, if you only add the order to {{ic|/etc/rc.local.shutdown}}, that will assure that mpd won't play at all, as long as you properly shutdown your system.<br />
Even though they are redundant, adding it to {{ic|/etc/rc.local}} would serve as a safety for those, presumably, rare occasions when you do not shutdown the system properly.<br />
<br />
====Method 3====<br />
The general idea is to ask mpd to pause music when the user logs out, so that mpd will stick to the "pause" state after a reboot. Sending such command can be achieved using [http://www.archlinux.org/packages/extra/x86_64/mpc/ mpc], the command line interface to MPD.<br />
<br />
GDM users can then add {{ic|/usr/bin/mpc pause}} to {{ic|/etc/gdm/PostSession/Default}} (be sure to add it before {{ic|exit 0}}):<br />
<br />
Non-GDM users can use their own login manager's method to launch the line at logout.<br />
<br />
===MPD & ALSA===<br />
Sometimes, when using other audio outputs, e.g: some web pages containing Flash applets, MPD is rendered unable to play (until it is restarted). The error comes up in mpd's log:<br />
<br />
Error opening alsa device "hw:0,0": Device or resource busy<br />
<br />
Reasons for this may be:<br />
* The sound card does not support hardware mixing (uses '''dmix''' plugin)<br />
* An application does not work with ALSA's default settings<br />
<br />
For a detailed description, it is recommended to take a look at [http://mpd.wikia.com/wiki/Alsa this] link. <br />
<br />
This problem may be solved by adding the following lines to {{ic|mpd.conf}}:<br />
{{hc|mpd.conf|2=<br />
audio_output {<br />
type "alsa"<br />
name "Sound Card"<br />
options "dev=dmixer"<br />
device "plug:dmix"<br />
}}<br />
<br />
To make the changes have effect, restart mpd (e.g. {{ic|/etc/rc.d/mpd restart}}, if it is a global configuration).<br />
<br />
====High CPU usage with ALSA====<br />
When using MPD with ALSA, users may experience MPD taking up lots of CPU (around 20-30%). This is caused by most sound cards supporting 48kHz and most music being 44kHz, thus forcing MPD to resample it. This operation takes lots of CPU cycles and results into high usage.<br />
<br />
For most users the problem should be solved by telling MPD not to use resampling by adding {{ic|auto_resample "no"}} into audio_output-part of {{ic|/etc/mpd.conf}}. This will degrade quality slightly, however.<br />
<br />
{{hc|mpd.conf|2=<br />
audio_output {<br />
type "alsa"<br />
name "My ALSA Device"<br />
auto_resample "no"<br />
}<br />
}}<br />
<br />
Although it may not give as drastic a speedup, enabling mmap may still speed things up:<br />
{{hc|mpd.conf|2=<br />
audio_output {<br />
type "alsa"<br />
name "My ALSA Device"<br />
use_mmap "yes"<br />
}<br />
}}<br />
<br />
Some users might also want to tell dmix to use 44kHz as well. More info about tuning performance of your MPD can be found on the [http://mpd.wikia.com/wiki/Tuning MPD wiki]<br />
<br />
====Example configuration: Output with 44.1 KHz at e. g. 16 bit depth, multiple programs at once====<br />
''Why these formats?'' Because they are standard CDA, because ALSA on its own allows more than one program "to sound" only with dmix — whose resampling algorithm is inferior — and because dmix by default resamples anything lower to 48 KHz (or whatever higher format is playing at the time). Also, some get clicking sounds if at least {{ic|mpd.conf}} is not changed this way.<br />
<br />
''What's the downside?'' These settings cause ''everything'' (if necessary) to be resampled to this format, such as material from DVD or TV which usually is at 48 KHz. But there is no known way to have ALSA dynamically change the format, and particularly if you listen to far more CDs than anything else the occasional 48 → 44.1 isn't too great a loss.<br />
<br />
The following assumes that there are not already other settings which conflict resp. overwrite it. This applies especially to the current user's potential {{ic|~/.asoundrc}} — which MPD as its own user ignores, therefore the following should go to {{ic|/etc/asound.conf}}:<br />
<br />
{{hc|/etc/asound.conf|<br />
defaults.pcm.dmix.rate 44100 # Force 44.1 KHz<br />
defaults.pcm.dmix.format S16_LE # Force 16 bits<br />
}}<br />
<br />
{{hc|/etc/mpd.conf|2=<br />
audio_output {<br />
type "alsa" # Use the ALSA output plugin.<br />
name "HDA Intel" # Can be called anything or nothing tmk, but must be present.<br />
options "dev=dmixer"<br />
device "plug:dmix" # Both lines cause MPD to output to dmix.<br />
format "44100:16:2" # the actual format<br />
auto_resample "no" # This bypasses ALSA's own algorithms, which generally are inferior. See below how to choose a different one.<br />
use_mmap "yes" # Minor speed improvement, should work with all modern cards.<br />
}<br />
<br />
samplerate_converter "0" # MPD's best, most CPU intensive algorithm. See 'man mpd.conf' for others — for anything other than the poorest "internal", libsamplerate must be installed.<br />
}}<br />
<br />
{{Note|MPD gives the mp3 format a special treatment at decoding: It's always outputted as 24 bit. (The conversion as forced by the ''format'' line only comes after that.)}}<br />
<br />
If one wants to leave the bit depth decision to ALSA resp. MPD, comment out resp. omit the ''dmix.format'' line and change the one for mpd with ''format'' to "44100:*:2".<br />
<br />
{{Note|''Crossfading'' between files decoded at two different bit depths (say, one mp3 and one 16 bit flac) does not work unless conversion is active.}}<br />
<br />
=== Control MPD with lirc ===<br />
There are already some clients designed for communications between lircd and MPD, however, as far as the practical use, they aren't very useful since their functions are limited.<br />
<br />
It's recommended to use mpc with irexec. mpc is a command line player which only sends the command to MPD and exits immediately, which is perfect for irexec, the command runner included in lirc. What irexec does is that it runs a specified command once received a remote control button.<br />
<br />
First of all, please setup your remotes as referred to the '''[[Lirc]]''' article.<br />
<br />
Edit your favored lirc startup configuration file, default location is {{ic|~/.lircrc}}.<br />
<br />
Fill the file with the following pattern:<br />
begin<br />
prog = irexec<br />
button = <button_name><br />
config = <command_to_run><br />
repeat = <0 or 1><br />
end<br />
<br />
An useful example:<br />
## irexec<br />
begin<br />
prog = irexec<br />
button = play_pause<br />
config = mpc toggle<br />
repeat = 0<br />
end<br />
<br />
begin<br />
prog = irexec<br />
button = stop<br />
config = mpc stop<br />
repeat = 0<br />
end<br />
begin<br />
prog = irexec<br />
button = previous<br />
config = mpc prev<br />
repeat = 0<br />
end<br />
begin<br />
prog = irexec<br />
button = next<br />
config = mpc next<br />
repeat = 0<br />
end<br />
begin<br />
prog = irexec<br />
button = volup<br />
config = mpc volume +2<br />
repeat = 1<br />
end<br />
begin<br />
prog = irexec<br />
button = voldown<br />
config = mpc volume -2<br />
repeat = 1<br />
end<br />
begin<br />
prog = irexec<br />
button = pbc<br />
config = mpc random<br />
repeat = 0<br />
end<br />
begin<br />
prog = irexec<br />
button = pdvd<br />
config = mpc update<br />
repeat = 0<br />
end<br />
begin<br />
prog = irexec<br />
button = right<br />
config = mpc seek +00:00:05<br />
repeat = 0<br />
end<br />
begin<br />
prog = irexec<br />
button = left<br />
config = mpc seek -00:00:05<br />
repeat = 0<br />
end<br />
begin<br />
prog = irexec<br />
button = up<br />
config = mpc seek +1%<br />
repeat = 0<br />
end<br />
begin<br />
prog = irexec<br />
button = down<br />
config = mpc seek -1%<br />
repeat = 0<br />
end<br />
<br />
There are more functions for mpc, run {{ic|man mpc}} for more info.<br />
<br />
===Control MPD with bluetooth phone===<br />
You can also control MPD (to a certain extent) using a bluetooth enabled phone. You need to do the following:<br />
<br />
* install [http://remuco.sourceforge.net/index.php/Remuco remuco] -- a wireless remote control for several Linux media players ([http://aur.archlinux.org/packages.php?ID=25072 aur])<br />
* transfer remuco client -- jar/jad files from {{ic|/usr/share/remuco/client/}} to your phone and install it<br />
* run {{ic|remuco-mpd}} (as current user)<br />
* run remuco on your phone, define a new bluetooth remuco connection (pair first if you haven't done this previously) and explore its capabilities<br />
<br />
More information about remuco including troubleshooting to be found at its [http://remuco.sourceforge.net/index.php/Remuco homepage]<br />
<br />
=== MPD & PulseAudio ===<br />
Edit {{ic|/etc/mpd.conf}}, and uncomment the audio_output section for the type "pulse". The server and sink lines of it should be commented unless you know what you're doing.<br />
<br />
Then, add the mpd user (and yours if you haven't done so already) to the necessary pulse groups. The pulse-access group should be sufficient but you may want to add pulse-rt as well. The group "pulse" doesn't appear to be necessary.<br />
# gpasswd -a mpd pulse-access<br />
# gpasswd -a mpd pulse-rt<br />
<br />
Lastly, you may or may not need to copy {{ic|~/.pulse-cookie}} from your current (pulse working) user's dir to your mpd user's home directory. It is likely to be {{ic|/var/lib/mpd}} if you followed the first part of this wiki. This would probably only allow your current user to listen in on MPD's pulse. You may consider running pulse system-wide if that's insufficient.<br />
<br />
=== Cue Files ===<br />
{{Out of date}}<br />
<br />
To make cue file support actually work, you have to work around a nasty libcue bug. Libcue copied some files directly from libcdio, making it conflict with it. Steps to do to get proper cue support:<br />
<br />
* remove {{Ic|libcdio}} temporary ({{Ic|pacman -Rdd libcdio}})<br />
* install {{Pkg|libcue}}<br />
* install mpd with [[ABS]] or from [[AUR]].<br />
* install {{Ic|libcdio}} again<br />
<br />
=== HTTP Streaming ===<br />
Since version 0.15 there is a built-in HTTP streaming daemon/server that comes with MPD. To activate this server simply set it as output device in mpd.conf:<br />
<br />
audio_output { <br />
type "httpd" <br />
name "My HTTP Stream" <br />
encoder "vorbis" # optional, vorbis or lame <br />
port "8000" <br />
# quality "5.0" # do not define if bitrate is defined <br />
bitrate "128" # do not define if quality is defined <br />
format "44100:16:1" <br />
}<br />
<br />
Then to listen to this stream simply open the URL of your mpd server (along with the specified port) in your favorite music player. Note: You may have to specify the file format of the stream using an appropriate file extension in the URL. For example, using Winamp 5.5, You would use http://192.168.1.2:8000/mpd.ogg rather than http://192.168.1.2:8000/.<br />
<br />
To use mpd to connect to the stream from another computer.<br />
<br />
mpc add http://192.168.1.2:8000<br />
<br />
== Troubleshooting ==<br />
=== Autodetection failed ===<br />
During the start of MPD, it tries to autodetect your set-up and configure output and volume control accordingly. Though this mostly goes well, it will fail for some systems. It may help to tell MPD specifically what to use as output and mixer control. If you copied {{ic|/etc/mpd.conf}} over from {{ic|/etc/mpd.conf.example}} as mentioned above, you can simply uncomment:<br />
<br />
Example for alsa output type and alsa mixer:<br />
audio_output {<br />
type "alsa"<br />
name "My ALSA Device"<br />
device "hw:0,0" # optional<br />
format "44100:16:2" # optional<br />
mixer_type "hardware"<br />
mixer_device "default"<br />
mixer_control "PCM"<br />
}<br />
<br />
'''Note:''' in case of permission problems when using ESD with MPD run this as root:<br />
# chsh -s /bin/true mpd<br />
<br />
=== Avoiding timeouts ===<br />
To get rid of timeouts (i.e. when you paused music for long time) in gpmc and other clients uncomment and increase {{ic|connection_timeout}} option in {{ic|mpd.conf}}.<br />
<br />
If files and/or titles are shown in wrong encoding, uncomment and change {{ic|filesystem_charset}} and {{ic|id3v1_encoding}} options.<br />
Note that you cannot set encoding for ID3 v2 tags. To workaround this you may use [http://mpd.wikia.com/wiki/GenericDecoder#Generic_Tagreader external tag readers].<br />
<br />
If you want to use another computer to control MPD over a network, the {{ic|bind_to_address}} option in {{ic|mpd.conf}} will need to be set to either your IP address, or {{ic|any}} if your IP address changes frequently. <br />
<br />
'''Streaming'''<br><br />
With the latest version of MPD (0.15), built-in httpd streaming is now available.<br />
<br />
To activate this feature, you'll just need to add a new output of type httpd in {{ic|mpd.conf}}:<br />
audio_output {<br />
type "httpd"<br />
name "What you want"<br />
encoder "lame" # vorbis or lame supported<br />
port "8000"<br />
bitrate "128"<br />
format "44100:16:2" # change 2 to 1 for mono<br />
}<br />
<br />
Restart the mpd daemon and, from another computer, simply load the stream as any other url. <br />
$ mplayer http://<server's IP>:8000<br />
<br />
{{Note | You must open the port on your router / firewall for the stream to be connectible to from another computer.}}<br />
<br />
Most players (i.e. vlc or xmms2) should also be able to load the stream via their "add url..." menu option.<br />
<br />
This is a nice clean way to replace your current icecast setup with something natively supported within MPD.<br />
<br />
=== MPD hangs on first startup ===<br />
This is a common error that's caused by corrupt mp3 tags.<br />
Here is an experimental way to solve this issue.<br />
Requirements:<br />
* kid3<br />
* easytag<br />
<br />
This method is very tedious, especially with a huge database. Just as a baseline it took 2.5h to fix a 16Gb DB.<br />
<br />
==== Easy Tag ====<br />
The purpose of easytag here is that easytag detects the error in the tags, but like MPD it hangs and dies. The trick here is that easy tags actually tells you what file is causing the problem on the status bar.<br />
Before starting easytag make sure to have a terminal close to be ready to kill easy tag to avoid a hang. Once you are ready, on the tree view select the directory where all your music is located. By default easytag starts to search all subdirectories for mp3 files. Once you notice that easytag stopped scanning for songs, make note of the culprit and kill easytag.<br />
<br />
==== KID3 ====<br />
Here's where kid3 comes in handy. With kid3 go to the offending song and rewrite one of the tags. then save the file. This should force kid3 to rewrite the whole tag again fixing the problem with MPD and easy tag hanging.<br />
<br />
Repeat this procedure until your music library is done.<br />
<br />
=== Cannot connect to mpd: host "localhost" not found: Temporary failure in name resolution ===<br />
Cannot connect to MPD (with ncmpcpp), if you are disconnected from network. Solution is [[IPv6 - Disabling the Module|disable IPv6]] or add line to /etc/hosts<br />
::1 localhost.localdomain localhost<br />
<br />
=== Other issues when attempting to connect to mpd with a client ===<br />
Some have reported being unable to access mpd with various clients, for example seeing errors like these:<br />
$ ncmpcpp<br />
Cannot connect to mpd: Connection closed by the server<br />
$ sonata<br />
2011-02-13 18:33:05 Connection lost while reading MPD hello<br />
2011-02-13 18:33:05 Not connected<br />
2011-02-13 18:33:05 Not connected<br />
<br />
Please see posts on ncmpcpp on the Arch Forums [https://bbs.archlinux.org/viewtopic.php?id=109962 HERE] and [https://bbs.archlinux.org/viewtopic.php?id=113493 HERE]. Also see {{Bug|22071}}.<br />
<br />
==== First fix ====<br />
Check {{ic|mpd.conf}} for a line like {{ic|mpd.error}} and remove it. The mpd error file is deprecated and has been removed.<br />
<br />
==== Second fix ====<br />
{{Note|I'm not so sure this is a good idea. There is a warning about changing the address to bind to in the default mpd.conf. If this does not help, you might want to comment out the changes.}}<br />
If that doesn't help, add the following to {{ic|mpd.conf}}:<br />
{{bc|<br />
bind_to_address "127.0.0.1"<br />
port "6600"<br />
}}<br />
<br />
Afterwards, instruct your client to connect via 127.0.0.1. For example, add the following to the ncmpcpp config file:<br />
{{bc|<br />
mpd_host "127.0.0.1"<br />
mpd_port "6600"<br />
}}<br />
<br />
=== Port 6600 already in use ===<br />
MPD needs to bind to port 6600 and cannot start if it's already in use. The most common reason for this is that the user has started MPD once and then subsequently tried to start mpd again. In general, nothing should be done here.<br />
<br />
If port 6600 is tied up for some other reason, one can use the following command to find the offending process:<br />
# netstat -tulpan | grep 6600<br />
<br />
This will list IP:Port and the process name holding the connection (root privileges are required to see all processes).<br />
<br />
If you need to restart mpd for whatever reason, use:<br />
{{bc|<br />
$ mpd --kill<br />
$ mpd <br />
}}<br />
A more brute-force approach:<br />
{{bc|<br />
$ killall mpd<br />
$ mpd <br />
}}<br />
{{Note| If you typically run MPD as root, you will need to run the above commands as root.}}<br />
<br />
In the latest version of MPD, --create-db is completely deprecated. The database will be created automagically on first run and can subsequently be updated via your client (i.e. mpc update). You can now use inotify support to automatically update your music database. Add the following to {{hc|mpd.conf|auto_update "yes"}} to enable it.<br />
<br />
=== Binding to IPV6 before IPV4 ===<br />
If on startup, you see this message:<br />
listen: bind to '0.0.0.0:6600' failed: Address already in use (continuing anyway, because binding to '[::]:6600' succeeded)<br />
MPD is attempting to bind to the ipv6 interface before binding to ipv4. If you want to use your ipv4 interface, hardcode it in mpd.conf, like so:<br />
bind_to_address "127.0.0.1"<br />
Or, you could specify several binds, for example, to have MPD listen on localhost and the external IP of your network card:<br />
bind_to_address "127.0.0.1"<br />
bind_to_address "192.168.1.13"<br />
<br />
=== Crackling sound with some audio files ===<br />
This is usually a playback speed problem and can be fixed by uncommenting the audio_output_format line in:<br />
<br />
{{hc|/etc/mpd.conf|<br />
audio_output_format "44100:16:2"}}<br />
<br />
This is usually a sane value for most mp3 files.<br />
<br />
=== daemon: cannot setgid for user "mpd": Operation not permitted ===<br />
<br />
The error is stating that the user starting the process (you) does not have permissions to become another user (mpd) which the configuration has told that process to run as.<br />
<br />
To solve the issue, simply start mpd as root.<br />
{{bc|$ su -c "rc.d start mpd"}}<br />
or<br />
{{bc|# rc.d start mpd}}<br />
<br />
== External links ==<br />
* [http://mpd.wikia.com/wiki/Music_Player_Daemon_Wiki Official Web Site and wiki]<br />
* [http://mpd.wikia.com/wiki/Clients Sorted List of MPD Clients]<br />
* [http://www.musicpd.org/forum/ MPD forum]</div>Rasihttps://wiki.archlinux.org/index.php?title=Music_Player_Daemon&diff=150770Music Player Daemon2011-08-06T01:11:50Z<p>Rasi: /* Native Last.fm playback */</p>
<hr />
<div>[[fr:MPD]]<br />
[[Category:Audio/Video (English)]]<br />
[[Category:Daemons and system services (English)]]<br />
{{i18n|Music Player Daemon}}<br />
[[pl:Music Player Daemon]]<br />
<br />
'''MPD''' (music player daemon) is an audio player that has a server-client architecture. MPD runs in the background as a daemon, manages playlists and a music database, and uses very few resources. In order to interface with it, you need a separate client. More information can be found on their [http://www.musicpd.org/ website].<br />
<br />
''Please'' have a look at the official page for setup and troubleshooting instructions, the main developer called our wiki page in its current state ''"full of symptom killers"'', hence the official pages should contain better instructions.<br />
<br />
==Installing mpd==<br />
Install with [[pacman]]:<br />
# pacman -S mpd<br />
<br />
==Daemon Setup: Starting at Boot==<br />
General information about MPD configuration may be found at http://mpd.wikia.com/wiki/Configuration.<br />
<br />
===Sound setup===<br />
To make audio output actually work ensure that you have setup audio card and mixer correctly. See [[ALSA]], and [[PulseAudio]] if you are using Gnome 3. Do not forget to unmute the required channels in alsamixer, raise the volume and save changes with alsactl store. Run mpd with {{Filename|/usr/bin/mpd --stdout --no-daemon --verbose}} if that still doesn't work.<br />
<br />
Make sure your card can do hardware mixing (most of them can, including onboard audio). Or else this could cause problems with multiple sound playback. For example, this can prevent Mplayer from playing back sound while the mpd daemon is running, returning an audio error message stating the device is busy.<br />
<br />
===Timeline of MPD's behavior on a typical working setup when started as a daemon===<br />
# MPD is started on boot by {{Filename|/etc/rc.conf}}, by including it in the {{Codeline|DAEMONS}} array. (Or, this can be done manually each session by running {{Codeline|/etc/rc.d/mpd start}} with root privileges).<br />
# Since MPD is now started as root, it first reads the {{Filename|/etc/mpd.conf}} file.<br />
# MPD reads the user variable in the {{Filename|/etc/mpd.conf}} file, and changes from root to this user.<br />
# MPD then reads the contents of the {{Filename|/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 {{Filename|/etc/mpd.conf}} file. This way, uses of {{Codeline|~}} in the configuration file point correctly to the home user's directory, and not root's directory. It may be worthwhile to change all uses of {{Codeline|~}} to {{Codeline|/home/username}} to avoid any confusion over this aspect of MPD's behavior.<br />
<br />
===A clean configuration file===<br />
* As root, check if {{Filename|/etc/mpd.conf}} exists and delete the file if it does. This is safe.<br />
<br />
MPD comes with an example configuration file, available at {{Filename|/usr/share/mpd/mpd.conf.example}}. This file holds an abundance of information on MPD configuration, and holds default mixer values you can simply uncomment.<br />
<br />
* As root, copy this example file to {{Filename|/etc/mpd.conf}}.<br />
# cp /usr/share/mpd/mpd.conf.example /etc/mpd.conf<br />
({{Filename|/usr/share/mpd/mpd.conf.example}} is good for userspace setup)<br />
<br />
Since MPD is being set up to run as a daemon at boot, never put this file in the user's directory like some tutorials suggest, since it will not be read. Moreover, if you previously created a {{Filename|.mpdconf}} file in your home, remove it now (to set up MPD to run with user privileges alone, pleaser refer to the section [[Music_Player_Daemon#Alternative_Setup:_Starting_as_a_User | Alternative_Setup:_Starting_as_a_User]]). This is important to prevent conflicts. The presence of the configuration file in {{Filename|/etc}}, like is the case here, is what will enable MPD to run as a daemon at boot. Otherwise, a script would be needed to run MPD ''after'' the user has logged (like kdm or {{Filename|~/.fluxbox/startup}}) or it would require a manual move each time. For a single music collection, the method used here is simply better, even while the collection is shared to multiple users. Also, don't be afraid about root privileges: even while MPD runs as a daemon, it never completely runs as root since it automatically drops its root privileges after execution.<br />
<br />
===Edit {{Filename|mpd.conf}}===<br />
<br />
The default arch install keeps the setup in /var and uses "mpd" as default user, instead of cluttering up ~/.<br />
Edit {{Filename|/etc/mpd.conf}} to reflect as such.<br />
<br />
{{File|name=/etc/mpd.conf|content=<br />
music_directory "/home/user/music" # Your music dir.<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 "/var/run/mpd/mpd.pid" # Omit this line for systemd<br />
state_file "/var/lib/mpd/mpdstate"<br />
user "mpd"<br />
# Binding to address and port causing problems in mpd-0.14.2 best to leave<br />
# commented.<br />
# bind_to_address "127.0.0.1"<br />
# port "6600"<br />
}}<br />
<br />
* If your music collection is contained under multiple directories, you can make symbolic links under /var/lib/mpd then set 'music_directory' to the directory holding the symbolic links. Remember to set permissions accordingly on the directories being linked.<br />
<br />
* To change the volume of audio from mpd independent of other programs, uncomment or add the switch in mpd.conf:<br />
<br />
{{File|name=/etc/mpd.conf|content=<br />
mixer_type "software"<br />
}}<br />
<br />
* Lastly, if you are running pulseaudio under Gnome 3, the default setting of "alsa" for the audio output will not work. Make the modification from:<br />
{{File|name=/etc/mpd.conf|content=<br />
audio_output {<br />
type "alsa"<br />
name "Sound Card"<br />
}<br />
}}<br />
<br />
to<br />
<br />
{{File|name=/etc/mpd.conf|content=<br />
audio_output {<br />
type "pulse"<br />
name "Sound Card"<br />
}<br />
}}<br />
<br />
===Create files===<br />
<br />
* As root, create the directories and files you specified in {{Filename|/etc/mpd.conf}}.<br />
# mkdir -p /var/lib/mpd/playlists /var/run/mpd<br />
# touch /var/lib/mpd/{mpd.db,mpdstate} && touch /var/run/mpd/mpd.pid<br />
<br />
* You then need to change the file's permissions so that the daemon can modify them.<br />
# chown -R mpd /var/lib/mpd /var/run/mpd<br />
<br />
===Create database===<br />
<br />
Creating the database is now accomplished via the update feature of the client, for example 'mpc update'. The previous method, creating the MPD database as root (# mpd --create-db), is deprecated.<br />
<br />
==Alternative Setup: Starting as a User==<br />
MPD need not be started with root permissions. The only reason why MPD needs to be started as root (by being called from {{Filename|/etc/rc.conf}}) is because the default files and folders in the default configuration file points to directories owned by root (the /var directory). A less common, but perhaps more sensible, approach is to make MPD work with files and directories owned by a normal user. Running MPD as a normal user has several advantages: <br />
# You can easily have a single directory ~/.mpd (or any other directory under /home/username) for all MPD configuration files<br />
# No read/write permission errors<br />
# More flexible calls to MPD by using {{Filename|~/.xinitrc}} instead of including 'mpd' in the {{Filename|/etc/rc.conf}} DAEMONS array.<br />
<br />
The following steps shows how to run MPD as a normal user. '''Note''': this approach will not work if you want multiple users to have access to MPD.<br />
<br />
* Copy the contents of the default MPD configuration file in {{Filename|/usr/share/mpd/mpd.conf.example}} to your home directory. A good place would be {{Filename|"/home/user/.mpd/mpd.conf"}}.<br />
* Follow the 'old setup instructions' from above, ignoring the first part about copying the config to {{Filename|/etc/mpd.conf}} and do not set a user variable. <br />
* Create all of the requisite files in {{filename|"/home/user/.mpd/"}}:<br />
"~/.mpd/playlists/"<br />
"~/.mpd/db"<br />
"~/.mpd/mpd.db"<br />
"~/.mpd/mpd.log"<br />
"~/.mpd/mpd.error"<br />
"~/.mpd/mpd.pid"<br />
"~/.mpd/mpdstate"<br />
<br />
* Let MPD start on bootup by calling it from your {{Filename|~/.xinitrc}} as follows:<br />
# this starts mpd as normal user<br />
mpd ~/.mpd/mpd.conf<br />
{{Note| that you don't have to put a "&" at the end of the line here, since MPD will automatically daemonize itself.}}<br />
<br />
Lastly, delete the entry 'mpd' from your DAEMONS array in {{Filename|/etc/rc.conf}}, as you are not running it as root anymore.<br />
<br />
===Quick setup===<br />
<br />
The fastest way to do set up the structure is to do this:<br />
<br />
$ mkdir -p ~/.mpd/playlists && touch ~/.mpd/database && cp /usr/share/doc/mpd/mpdconf.example ~/.mpd/mpd.conf<br />
<br />
Then edit mpd.conf to your liking, in a manner similar to [[Music_Player_Daemon#Edit_mpd.conf]]. Beware that you must uncomment the db_file entry if you do edit mpd.conf.<br />
<br />
Then, to run it:<br />
<br />
$ mpd ~/.mpd/mpd.conf<br />
<br />
<br />
===Even quicker setup===<br />
I created a little script that will only ask for the location of your music and then creates the needed files and folders for you.<br />
You can find the script here:<br />
[http://karif.server-speed.net/~carnager/mpdsetup.tar]<br />
extract it<br />
$ tar xf mpdsetup.tar<br />
and run it<br />
$ ./mpdsetup.sh<br />
<br />
If you want to use this config in daemon mode, open it (~/.mpdconf) in an editor and find the "user" line. remove the comment (#) and fill in your own user name. Then copy the file to /etc/mpd.conf. If running mpd as user is fine for you, make sure to remove "mpd" from the daemons list in /etc/rc.conf<br />
<br />
===Multi-mpd setup===<br />
'''Useful if you want to run for example an icecast server.'''<br />
If you want a second MPD daemon (e.g., with icecast output to share music over the network) to use the same music and playlist as the one above, simply copy the above configuration file and make a new file (e.g., {{Filename|/home/username/.mpd/config-icecast}}), and only change the log_file, error_file, pid_file, and state_file parameters (e.g., {{Filename|mpd-icecast.log}}, {{Filename|mpd-icecast.error}}, and so on); using the same directory paths for the music and playlist directories would ensure that this second mpd daemon would use the same music collection as your first one (e.g., creating and editing a playlist under the first daemon would affect the second daemon as well, so that you don't have to create the same playlists all over again for the second daemon). Then, call this second daemon the same way from your {{Filename|~/.xinitrc}} above. (Just be sure to have a different port number, so as to not conflict with your first mpd daemon).<br />
<br />
==Clients==<br />
Install a client program for MPD. Popular options are:<br />
<br />
===Console===<br />
* '''mpc''' &ndash; Command Line Client (you'll probably want this one no matter what)<br />
# pacman -S mpc<br />
* [http://mpd.wikia.com/wiki/Client:Ncmpc/ ncmpc] &ndash; NCurses Client (this one is very handy for running in a console)<br />
# pacman -S ncmpc<br />
* [http://unkart.ovh.org/ncmpcpp/ ncmpcpp] &ndash; Clone of ncmpc with some new features written in C++<br />
# pacman -S ncmpcpp<br />
* [http://pms.sourceforge.net/ pms] &ndash; NCurses Client (highly configurable and accessible)<br />
Install [http://aur.archlinux.org/packages.php?ID=24378 pmus] from the [[AUR]].<br />
<br />
===Graphical===<br />
* [http://ario-player.sourceforge.net ario] &ndash; GTK+ Client with a Rhythmbox like library browser<br />
# pacman -S ario<br />
* [http://gmpcwiki.sarine.nl/index.php?title=GMPC gmpc] &ndash; GNOME Client<br />
# pacman -S gmpc<br />
* [http://bitcheese.net/wiki/QMPDClient QMPDClient] &ndash; Client written with Qt 4.x.<br />
# pacman -S qmpdclient<br />
* [http://sonata.berlios.de/ sonata] &ndash; Python GTK+ Client<br />
# pacman -S sonata<br />
* [http://aur.archlinux.org/packages.php?ID=33380 dmpc] &ndash; Dmenu-based MPC client with a playlist manager and state-saving on playlist changes<br />
Install [http://aur.archlinux.org/packages.php?ID=33380 dmpc] from the [[AUR]].<br />
<br />
See a long list of clients at the [http://mpd.wikia.com/wiki/Clients mpd wiki].<br />
<br />
==Extra stuff==<br />
===Last.fm scrobbling===<br />
To scrobble your songs to [http://www.last.fm Last.fm] using MPD there are several alternatives.<br />
<br />
====mpdscribble====<br />
mpdscribble is another daemon, available in the "community" repository (if you prefer, the "git" version is available in the [http://aur.archlinux.org/packages.php?ID=22274 AUR]). This is arguably the best alternative, because it's the semi-official MPD scrobbler and uses the new "idle" feature in MPD for more accurate scrobbling. Also, you don't need root access to configure it, because it doesn't need any changes to <tt>/etc</tt> at all. Visit [http://mpd.wikia.com/wiki/Client:Mpdscribble the official website] for more information.<br />
<br />
After you have installed mpdscribble, do the following (not as root):<br />
<br />
* {{Codeline|$ mkdir ~/.mpdscribble}}<br />
* Create the file {{Filename|~/.mpdscribble/mpdscribble.conf}} and add the following:<br />
<pre><br />
[mpdscribble] <br />
host = <your mpd host> # optional, defaults to $MPD_HOST or localhost<br />
port = <your mpd port> # optional, defaults to $MPD_PORT or 6600<br />
log = /home/<YOUR_USERNAME>/.mpdscribble/mpdscribble.log<br />
verbose = 2<br />
sleep = 1<br />
musicdir = <your music directory><br />
proxy = <your proxy> # optional, e. g. http://your.proxy:8080, defaults to none<br />
<br />
[last.fm]<br />
# last.fm section, comment if you don't use last.fm<br />
url = http://post.audioscrobbler.com/<br />
username = <your last.fm username><br />
password = <your last.fm password> # md5sum also possible: echo -n 'PASSWORD' | md5sum | cut -f 1 -d " "<br />
journal = /home/<YOUR_USERNAME>/.mpdscribble/lastfm.journal<br />
<br />
[libre.fm]<br />
# libre.fm section, comment if you don't use libre.fm<br />
url = http://turtle.libre.fm/<br />
username = <your libre.fm username><br />
password = <your libre.fm password> # md5sum also possible: echo -n 'PASSWORD' | md5sum | cut -f 1 -d " "<br />
journal = /home/<YOUR_USERNAME>/.mpdscribble/librefm.journal<br />
</pre><br />
* Add {{Codeline|mpdscribble}} to your {{Filename|~/.xinitrc}}:<br />
pidof mpdscribble >& /dev/null<br />
if [ $? -ne 0 ]; then<br />
mpdscribble &<br />
fi<br />
<br />
====Sonata & Ario====<br />
The easiest way, if you don't care about having to have a program window open all the time, is using Sonata or Ario which are graphical frontends to MPD. They have built-in support for Last.fm scrobbling in their preferences. A downside of this is that Sonata doesn't cache your songs if for some reason you don't happen to have an Internet connection at the time of playing.<br />
<br />
====lastfmsubmitd====<br />
lastfmsubmitd is a daemon which is available in the "community" repository. To install it, first edit {{Filename|/etc/lastfmsubmitd.conf}} and add both {{Codeline|lastfmsubmitd}} and {{Codeline|lastmp}} to the {{Codeline|DAEMONS}} array in {{Filename|/etc/rc.conf}}.<br />
<br />
====Last.fm playback====<br />
<br />
=====Last.fm playback with lastfmproxy=====<br />
lastfmproxy is a python script that streams a last.fm music stream to another media player. To setup, install [http://aur.archlinux.org/packages.php?ID=14214 lastfmproxy] from the [[AUR]] and then edit {{Filename|/usr/share/lastfmproxy/config.py}}. If you plan to only stream to MPD on the same host, just edit the login info.<br />
<br />
{{Note | Since it installs to a read only directory but it requires read/write access for features like saving previously listened to stations, it would be wise to copy {{Filename|/usr/share/lastfmproxy}} to your home directory.}}<br />
<br />
Start lastfmproxy with {{Codeline|lastfmproxy}} and visit http://localhost:1881/ in your web browser. To add a last.fm station navigate to http://localhost:1881/ followed by the lastfm:// url. Example: http://localhost:1881/lastfm://globaltags/punk . Navigate back to http://localhost:1881/ and download the m3u file by selecting the ''Start Listening'' link. Simply add it to your music library path.<br />
<br />
=====Native Last.fm playback=====<br />
Since 0.16 mpd has a very well working method to play back last.fm streams.<br />
{{File|name=/etc/mpd.conf|content=<br />
$ playlist_plugin {<br />
name "lastfm"<br />
user "my_username"<br />
password "my_password"<br />
}<br />
}}<br />
Then use e.g. mpc to load streams<br />
$ mpc load "lastfm://artist/Beatles"<br />
<br />
===Never play on start===<br />
<br />
This feature has recently been added to mpd git by Martin Kellerman, see commits b57330cf75bcb339e3f268f1019c63e40d305145 and 2fb40fe728ac07574808c40034fc0f3d2254d49d.<br />
<br />
====[https://aur.archlinux.org/packages.php?ID=19676 mpd-git] Method====<br />
This is the best method currently available, but is only currently (April 2011) enabled in the git version. Install [https://aur.archlinux.org/packages.php?ID=19676 mpd-git] from the [[AUR]], then add {{Codeline|restore_paused "yes"}} to your {{Filename|mpd.conf}} file.<br />
<br />
If you have issues with connecting your client to [https://aur.archlinux.org/packages.php?ID=19676 mpd-git], see [[Music Player Daemon#Other issues when attempting to connect to mpd with a client]].<br />
<br />
====Method 1====<br />
If you don't want MPD to always play on your system start, but yet you want to preserve the other state information, add the following lines to your {{Filename|/etc/rc.d/mpd}} file:<br />
'' ...''<br />
'' stat_busy "Starting Music Player Daemon"''<br />
<br />
# always start in paused state<br />
awk '/^state_file[ \t]+"[^"]+"$/ {<br />
match($0, "\".+\"")<br />
sfile = substr($0, RSTART + 1, RLENGTH - 2)<br />
} /^user[ \t]+"[^"]+"$/ {<br />
match($0, "\".+\"")<br />
user = substr($0, RSTART + 1, RLENGTH - 2)<br />
} END {<br />
if (sfile == "")<br />
exit;<br />
if (user != "")<br />
sub(/^~/, "/home/" user, sfile)<br />
system("sed -i \x27s|^\\(state:[ \\t]\\{1,\\}\\)play$|\\1pause|\x27 \x27" sfile "\x27")<br />
}' /etc/mpd.conf<br />
<br />
'' /usr/bin/mpd /etc/mpd.conf &> /dev/null''<br />
'' ...''<br />
<br />
This will change the player status to "paused", if it was stopped while playing. Next, you want this file to be preserved, so MPD updates won't erase this edit. Add (or edit) this line to your {{Filename|/etc/pacman.conf}}:<br />
NoUpgrade = etc/rc.d/mpd<br />
<br />
====Method 2====<br />
<br />
Another simpler method, would be to add mpd to your {{Filename|[[rc.conf]]}} deamons array and add {{Codeline|mpc stop}} or {{Codeline|mpc pause}} to {{Filename|/etc/rc.local.shutdown}} and to {{Filename|/etc/rc.local}}. (Remember you must have mpc installed to use this method).<br />
<br />
Adding only the order in {{Filename|/etc/rc.local}} cannot assure that mpd will play absolutely nothing, since there may be a delay before the stop command is executed. <br />
On the other hand, if you only add the order to {{Filename|/etc/rc.local.shutdown}}, that will assure that mpd won't play at all, as long as you properly shutdown your system.<br />
Even though they are redundant, adding it to {{Filename|/etc/rc.local}} would serve as a safety for those, presumably, rare occasions when you do not shutdown the system properly.<br />
<br />
====Method 3====<br />
<br />
The general idea between this method is to ask mdp to pause music when user logs out so that during next restart, mdp will stick to that "pause" state. Sending such command can be achieve using [http://www.archlinux.org/packages/extra/x86_64/mpc/ mpc], the command line interface to MPD:<br />
pacman -S mpc<br />
<br />
GDM users can then add the next line to /etc/gdm/PostSession/Default (be sure to add it before "exit 0"):<br />
/usr/bin/mpc pause<br />
<br />
Non-GDM users can use their own login manager's method to launch the line at logout.<br />
<br />
===MPD & ALSA===<br />
Sometimes, when you use other audio output, e.g: some web pages containing Flash applets, MPD cannot reproduce anything anymore (until you restart). The error looks something like: (if you search the file {{Filename|/var/log/mpd/mpd.error}})<br />
<br />
Error opening alsa device "hw:0,0": Device or resource busy<br />
<br />
And here is the solution (dmix saving our life again). Apply these lines in your {{Filename|/etc/mpd.conf}}:<br />
<br />
<pre><br />
audio_output {<br />
type "alsa"<br />
name "Sound Card"<br />
options "dev=dmixer"<br />
device "plug:dmix"<br />
}<br />
</pre><br />
<br />
And then restart with {{Codeline|/etc/rc.d/mpd restart}}.<br />
<br />
Searching on Internet I found the reason for why that happens in Gentoo's wiki:<br />
* The sound card does not support hardware mixing (uses '''dmix''' plugin)<br />
* An application does not work with ALSA with it's default settings<br />
<br />
For a detailed description, it is recommended to take a look at [http://mpd.wikia.com/wiki/Alsa this] link. There you can find an example asound.conf which worked for me right out of the box.<br />
<br />
====High CPU usage with ALSA====<br />
When using MPD with ALSA, users may experience MPD taking up lots of CPU (around 20-30%). This is caused by most sound cards supporting 48kHz and most music being 44kHz, thus forcing MPD to resample it. This operation takes lots of CPU cycles and results into high usage.<br />
<br />
For most users the problem should be solved by telling MPD not to use resampling by adding {{Codeline|auto_resample "no"}} into audio_output-part of {{Filename|/etc/mpd.conf}}. This will degrade quality slightly, however.<br />
<br />
Example from {{Filename|mpd.conf}}:<br />
<br />
audio_output {<br />
type "alsa"<br />
name "My ALSA Device"<br />
auto_resample "no"<br />
}<br />
<br />
Although it may not give as drastic a speedup, enabling mmap may speed things up:<br />
<br />
audio_output {<br />
type "alsa"<br />
name "My ALSA Device"<br />
use_mmap "yes"<br />
}<br />
<br />
Some users might also want to tell dmix to use 44kHz as well. More info about tuning performance of your MPD can be found from: [http://mpd.wikia.com/wiki/Tuning MPD wiki]<br />
<br />
====Example configuration: Output with 44.1 KHz at e. g. 16 bit depth, multiple programs at once====<br />
<br />
''Why these formats?'' Because they are standard CDA, because ALSA on its own allows more than one program "to sound" only with dmix — whose resampling algorithm is inferior — and because dmix by default resamples anything lower to 48 KHz (or whatever higher format is playing at the time). Also, some get clicking sounds if at least {{Filename|mpd.conf}} is not changed this way.<br />
<br />
''What's the downside?'' These settings cause ''everything'' (if necessary) to be resampled to this format, such as material from DVD or TV which usually is at 48 KHz. But there is no known way to have ALSA dynamically change the format, and particularly if you listen to far more CDs than anything else the occasional 48 → 44.1 isn't too great a loss.<br />
<br />
The following assumes that there are not already other settings which conflict resp. overwrite it. This applies especially to the current user's potential {{Filename|~/.asoundrc}} — which MPD as its own user ignores, therefore the following should go to {{Filename|/etc/asound.conf}}:<br />
<br />
{{File|name=/etc/asound.conf|content=<br />
defaults.pcm.dmix.rate 44100 # Force 44.1 KHz<br />
defaults.pcm.dmix.format S16_LE # Force 16 bits<br />
}}<br />
<br />
{{File|name=/etc/mpd.conf|content=<br />
audio_output {<br />
type "alsa" # Use the ALSA output plugin.<br />
name "HDA Intel" # Can be called anything or nothing tmk, but must be present.<br />
options "dev=dmixer"<br />
device "plug:dmix" # Both lines cause MPD to output to dmix.<br />
format "44100:16:2" # the actual format<br />
auto_resample "no" # This bypasses ALSA's own algorithms, which generally are inferior. See below how to choose a different one.<br />
use_mmap "yes" # Minor speed improvement, should work with all modern cards.<br />
}<br />
<br />
samplerate_converter "0" # MPD's best, most CPU intensive algorithm. See 'man mpd.conf' for others — for anything other than the poorest "internal", libsamplerate must be installed.<br />
}}<br />
<br />
{{Note|MPD gives the mp3 format a special treatment at decoding: It's always outputted as 24 bit. (The conversion as forced by the ''format'' line only comes after that.)}}<br />
<br />
If one wants to leave the bit depth decision to ALSA resp. MPD, comment out resp. omit the ''dmix.format'' line and change the one for mpd with ''format'' to "44100:*:2".<br />
<br />
{{Note|''Crossfading'' between files decoded at two different bit depths (say, one mp3 and one 16 bit flac) does not work unless conversion is active.}}<br />
<br />
===Control MPD with lirc===<br />
There are already some clients designed for communications between lircd and MPD, however, as far as the practical use, they aren't very useful since their functions are limited.<br />
<br />
It's recommended to use mpc with irexec. mpc is a command line player which only sends the command to MPD and exits immediately, which is perfect for irexec, the command runner included in lirc. What irexec does is that it runs a specified command once received a remote control button.<br />
<br />
First of all, please setup your remotes as referred to the '''[[Lirc]]''' article.<br />
<br />
Edit your favored lirc startup configuration file, default location is {{Filename|~/.lircrc}}.<br />
<br />
Fill the file with the following pattern:<br />
begin<br />
prog = irexec<br />
button = <button_name><br />
config = <command_to_run><br />
repeat = <0 or 1><br />
end<br />
<br />
An useful example:<br />
## irexec<br />
begin<br />
prog = irexec<br />
button = play_pause<br />
config = mpc toggle<br />
repeat = 0<br />
end<br />
<br />
begin<br />
prog = irexec<br />
button = stop<br />
config = mpc stop<br />
repeat = 0<br />
end<br />
begin<br />
prog = irexec<br />
button = previous<br />
config = mpc prev<br />
repeat = 0<br />
end<br />
begin<br />
prog = irexec<br />
button = next<br />
config = mpc next<br />
repeat = 0<br />
end<br />
begin<br />
prog = irexec<br />
button = volup<br />
config = mpc volume +2<br />
repeat = 1<br />
end<br />
begin<br />
prog = irexec<br />
button = voldown<br />
config = mpc volume -2<br />
repeat = 1<br />
end<br />
begin<br />
prog = irexec<br />
button = pbc<br />
config = mpc random<br />
repeat = 0<br />
end<br />
begin<br />
prog = irexec<br />
button = pdvd<br />
config = mpc update<br />
repeat = 0<br />
end<br />
begin<br />
prog = irexec<br />
button = right<br />
config = mpc seek +00:00:05<br />
repeat = 0<br />
end<br />
begin<br />
prog = irexec<br />
button = left<br />
config = mpc seek -00:00:05<br />
repeat = 0<br />
end<br />
begin<br />
prog = irexec<br />
button = up<br />
config = mpc seek +1%<br />
repeat = 0<br />
end<br />
begin<br />
prog = irexec<br />
button = down<br />
config = mpc seek -1%<br />
repeat = 0<br />
end<br />
<br />
There are more functions for mpc, run {{Codeline|man mpc}} for more info.<br />
<br />
===Control MPD with bluetooth phone===<br />
You can also control MPD (to a certain extent) using a bluetooth enabled phone. You need to do the following:<br />
<br />
* install [http://remuco.sourceforge.net/index.php/Remuco remuco] -- a wireless remote control for several Linux media players ([http://aur.archlinux.org/packages.php?ID=25072 aur])<br />
* transfer remuco client -- jar/jad files from {{Filename|/usr/share/remuco/client/}} to your phone and install it<br />
* run {{Codeline|remuco-mpd}} (as current user)<br />
* run remuco on your phone, define a new bluetooth remuco connection (pair first if you haven't done this previously) and explore its capabilities<br />
<br />
More information about remuco including troubleshooting to be found at its [http://remuco.sourceforge.net/index.php/Remuco homepage]<br />
<br />
===MPD & PulseAudio===<br />
<br />
Edit {{Filename|/etc/mpd.conf}}, and uncomment the audio_output section for the type "pulse". The server and sink lines of it should be commented unless you know what you're doing.<br />
<br />
Then, add the mpd user (and yours if you haven't done so already) to the necessary pulse groups. The pulse-access group should be sufficient but you may want to add pulse-rt as well. The group "pulse" doesn't appear to be necessary.<br />
# gpasswd -a mpd pulse-access<br />
# gpasswd -a mpd pulse-rt<br />
<br />
Lastly, you may or may not need to copy {{Filename|~/.pulse-cookie}} from your current (pulse working) user's dir to your mpd user's home directory. It is likely to be {{Filename|/var/lib/mpd}} if you followed the first part of this wiki. This would probably only allow your current user to listen in on MPD's pulse. You may consider running pulse system-wide if that's insufficient.<br />
<br />
===Cue Files===<br />
<br />
To make cue file support actually work, you have to work around a nasty libcue bug. Libcue copied some files directly from libcdio, making it conflict with it. Steps to do to get proper cue support:<br />
<br />
* remove libcdio temporary (pacman -Rdd libcdio)<br />
* install libcue (pacman -S libcue)<br />
* install mpd with abs or from aur.<br />
* reinstall libcdio (pacman -S libcdio)<br />
<br />
At the point of writing mpd does not parse tracknumbers from cue sheets. There is a patch available (http://musicpd.org/mantis/view.php?id=3230)<br />
Once this patch is merged into mpd, i will remove this line :)<br />
<br />
==Troubleshooting==<br />
===Autodetection failed===<br />
During the start of MPD, it tries to autodetect your set-up and configure output and volume control accordingly. Though this mostly goes well, it will fail for some systems. It may help to tell MPD specifically what to use as output and mixer control. If you copied {{Filename|/etc/mpd.conf}} over from {{Filename|/etc/mpd.conf.example}} as mentioned above, you can simply uncomment:<br />
<br />
Example for alsa output type and alsa mixer:<br />
audio_output {<br />
type "alsa"<br />
name "My ALSA Device"<br />
device "hw:0,0" # optional<br />
format "44100:16:2" # optional<br />
mixer_type "hardware"<br />
mixer_device "default"<br />
mixer_control "PCM"<br />
}<br />
<br />
'''Note:''' in case of permission problems when using ESD with MPD run this as root:<br />
# chsh -s /bin/true mpd<br />
<br />
===Executable permissions===<br />
{{Warning|This is not good security practice and may be unnecessary.}}<br />
<br />
MPD needs to have +x permissions on '''ALL''' parent directories to your music collection (ie. if it's located outside of "mpd" home directory /var/lib/mpd). By default useradd sets permissions on home dir to 1700 drwx------. So if you're like me you will need to change permissions of /home/user. Example... my music collection is located /home/user/music. <br />
# chmod a+x /home/$USER<br />
# chmod -R a+X /home/$USER/music<br />
<br />
====Alternative solution====<br />
An alternative solution would be to use your group to share a selection of files, among them your music library. First remove all permissions for the group then add group permissions to read and execute home and music.<br />
# chmod -R g-rwx /home/$USER<br />
# chmod g+rx /home/$USER<br />
# chmod -R g+rX /home/$USER/music<br />
<br />
====Another alternative solution====<br />
Another alternative is to remount the music directory under a directory that mpd has access to. This does not entail the same security risks as modifying the permissions on one's home directory.<br />
# mkdir /var/lib/mpd/music<br />
# echo "/home/$USER/music /var/lib/mpd/music none bind" >> /etc/fstab<br />
# mount -a<br />
# /etc/rc.d/mpd restart<br />
And that should fix the problem. See also [https://bbs.archlinux.org/viewtopic.php?id=86449 the forum thread.]<br />
<br />
===Avoiding timeouts===<br />
To get rid of timeouts (i.e. when you paused music for long time) in gpmc and other clients uncomment and increase {{Codeline|connection_timeout}} option in {{Filename|mpd.conf}}.<br />
<br />
If files and/or titles are shown in wrong encoding, uncomment and change {{Codeline|filesystem_charset}} and {{Codeline|id3v1_encoding}} options.<br />
Note that you cannot set encoding for ID3 v2 tags. To workaround this you may use [http://mpd.wikia.com/wiki/GenericDecoder#Generic_Tagreader external tag readers].<br />
<br />
If you want to use another computer to control MPD over a network, the {{Codeline|bind_to_address}} option in {{Filename|mpd.conf}} will need to be set to either your IP address, or {{Codeline|any}} if your IP address changes frequently. <br />
<br />
'''Streaming'''<br><br />
With the latest version of MPD (0.15), built-in httpd streaming is now available.<br />
<br />
To activate this feature, you'll just need to add a new output of type httpd in {{Filename|mpd.conf}}:<br />
audio_output {<br />
type "httpd"<br />
name "What you want"<br />
encoder "lame" # vorbis or lame supported<br />
port "8000"<br />
bitrate "128"<br />
format "44100:16:2" # change 2 to 1 for mono<br />
}<br />
<br />
Restart the mpd deamon and, from another computer, simply load the stream as any other url. <br />
$ mplayer http://<server's IP>:8000<br />
<br />
{{Note | You must open the port on your router / firewall for the stream to be connectible to from another computer.}}<br />
<br />
Most players (i.e. vlc or xmms2) should also be able to load the stream via their "add url..." menu option.<br />
<br />
This is a nice clean way to replace your current icecast setup with something natively supported within MPD.<br />
<br />
===mpd hangs on first startup===<br />
This is a common error that's caused by corrupt mp3 tags.<br />
Here is an experimental way to solve this issue.<br />
Requirements:<br />
* kid3<br />
* easytag<br />
<br />
This method is very tedious, especially with a huge database. Just as a baseline it took 2.5h to fix a 16Gb DB.<br />
<br />
====Easy Tag====<br />
The purpose of easytag here is that easytag detects the error in the tags, but like MPD it hangs and dies. The trick here is that easy tags actually tells you what file is causing the problem on the status bar.<br />
Before starting easytag make sure to have a terminal close to be ready to kill easy tag to avoid a hang. Once you are ready, on the tree view select the directory where all your music is located. By default easytag starts to search all subdirectories for mp3 files. Once you notice that easytag stopped scanning for songs, make note of the culprit and kill easytag.<br />
<br />
====KID3====<br />
Here's where kid3 comes in handy. With kid3 go to the offending song and rewrite one of the tags. then save the file. This should force kid3 to rewrite the whole tag again fixing the problem with MPD and easy tag hanging.<br />
<br />
Repeat this procedure until your music library is done.<br />
<br />
===Cannot connect to mpd: host "localhost" not found: Temporary failure in name resolution===<br />
Cannot connect to MPD (with ncmpcpp), if you are disconnected from network. Solution is [[IPv6 - Disabling the Module|disable IPv6]] or add line to /etc/hosts<br />
::1 localhost.localdomain localhost<br />
<br />
===Other issues when attempting to connect to mpd with a client===<br />
Some have reported being unable to access mpd with various clients, for example seeing errors like these:<br />
$ ncmpcpp<br />
Cannot connect to mpd: Connection closed by the server<br />
$ sonata<br />
2011-02-13 18:33:05 Connection lost while reading MPD hello<br />
2011-02-13 18:33:05 Not connected<br />
2011-02-13 18:33:05 Not connected<br />
<br />
Please see posts on ncmpcpp on the Arch Forums [https://bbs.archlinux.org/viewtopic.php?id=109962 HERE] and [https://bbs.archlinux.org/viewtopic.php?id=113493 HERE]. Also see the Arch bug report on this issue [https://bugs.archlinux.org/task/22071 HERE]. <br />
<br />
====First fix====<br />
Check {{Filename|mpd.conf}} for a line like {{Codeline|mpd.error}} and remove it. The mpd error file is deprecated and has been removed.<br />
<br />
====Second fix====<br />
{{Note|I'm not so sure this is a good idea. There is a warning about changing the address to bind to in the default mpd.conf. If this does not help, you might want to comment out the changes.}}<br />
If that doesn't help, add the following to {{Filename|mpd.conf}}:<br />
<pre><br />
bind_to_address "127.0.0.1"<br />
port "6600"<br />
</pre><br />
<br />
Afterwards, instruct your client to connect via 127.0.0.1. For example, add the following to the ncmpcpp config file:<br />
<pre><br />
mpd_host "127.0.0.1"<br />
mpd_port "6600"<br />
</pre><br />
<br />
<br />
===Port 6600 already in use===<br />
MPD needs to bind to port 6600 and cannot start if it's already in use. The most common reason for this is that the user has started MPD once and then subsequently tried to start mpd again. In general, nothing should be done here.<br />
<br />
If port 6600 is tied up for some other reason, one can use the following command to find the offending process:<br />
# netstat -tulpan | grep 6600<br />
<br />
This will list IP:Port and the process name holding the connection (root privileges are required to see all processes).<br />
<br />
If you need to restart mpd for whatever reason, use:<br />
<pre><br />
$ mpd --kill<br />
$ mpd <br />
</pre><br />
A more brute-force approach:<br />
<pre><br />
$ killall mpd<br />
$ mpd <br />
</pre><br />
{{Note| If you typically run MPD as root, you will need to run the above commands as root.}}<br />
<br />
In the latest version of MPD, --create-db is completely deprecated. The database will be created automagically on first run and can subsequently be updated via your client (i.e. mpc update). You can now use inotify support to automatically update your music database. Add the following to {{File|name=mpd.conf|content=auto_update "yes"}} to enable it.<br />
<br />
===Binding to IPV6 before IPV4===<br />
If on startup, you see this message:<br />
listen: bind to '0.0.0.0:6600' failed: Address already in use (continuing anyway, because binding to '[::]:6600' succeeded)<br />
MPD is attempting to bind to the ipv6 interface before binding to ipv4. If you want to use your ipv4 interface, hardcode it in mpd.conf, like so:<br />
bind_to_address "127.0.0.1"<br />
Or, you could specify several binds, for example, to have MPD listen on localhost and the external IP of your network card:<br />
bind_to_address "127.0.0.1"<br />
bind_to_address "192.168.1.13"<br />
<br />
===Crackling sound with some audio files===<br />
This is usually a playback speed problem and can be fixed by uncommenting the audio_output_format line in:<br />
<br />
{{File|name=/etc/mpd.conf|content=<br />
audio_output_format "44100:16:2"}}<br />
<br />
This is usually a sane value for most mp3 files.<br />
<br />
===daemon: cannot setgid for user "mpd": Operation not permitted ===<br />
<br />
The error is stating that the user starting the process (you) does not have permissions to become another user (mpd) which the configuration has told that process to run as.<br />
<br />
To solve the issue, simply start mpd as root.<br />
su -c "/etc/rc.d/mpd start"<br />
or<br />
sudo /etc/rc.d/mpd start<br />
<br />
==External links==<br />
* [http://www.musicpd.org/ Official Web Site]<br />
* [http://mpd.wikia.com/wiki/Main_Page Official Wiki]<br />
* [http://mpd.wikia.com/wiki/Clients Sorted List of MPD Clients]<br />
* [http://www.musicpd.org/forum/ MPD forum]</div>Rasihttps://wiki.archlinux.org/index.php?title=Music_Player_Daemon&diff=150769Music Player Daemon2011-08-06T01:11:35Z<p>Rasi: /* Last.fm playback with lastfmproxy */</p>
<hr />
<div>[[fr:MPD]]<br />
[[Category:Audio/Video (English)]]<br />
[[Category:Daemons and system services (English)]]<br />
{{i18n|Music Player Daemon}}<br />
[[pl:Music Player Daemon]]<br />
<br />
'''MPD''' (music player daemon) is an audio player that has a server-client architecture. MPD runs in the background as a daemon, manages playlists and a music database, and uses very few resources. In order to interface with it, you need a separate client. More information can be found on their [http://www.musicpd.org/ website].<br />
<br />
''Please'' have a look at the official page for setup and troubleshooting instructions, the main developer called our wiki page in its current state ''"full of symptom killers"'', hence the official pages should contain better instructions.<br />
<br />
==Installing mpd==<br />
Install with [[pacman]]:<br />
# pacman -S mpd<br />
<br />
==Daemon Setup: Starting at Boot==<br />
General information about MPD configuration may be found at http://mpd.wikia.com/wiki/Configuration.<br />
<br />
===Sound setup===<br />
To make audio output actually work ensure that you have setup audio card and mixer correctly. See [[ALSA]], and [[PulseAudio]] if you are using Gnome 3. Do not forget to unmute the required channels in alsamixer, raise the volume and save changes with alsactl store. Run mpd with {{Filename|/usr/bin/mpd --stdout --no-daemon --verbose}} if that still doesn't work.<br />
<br />
Make sure your card can do hardware mixing (most of them can, including onboard audio). Or else this could cause problems with multiple sound playback. For example, this can prevent Mplayer from playing back sound while the mpd daemon is running, returning an audio error message stating the device is busy.<br />
<br />
===Timeline of MPD's behavior on a typical working setup when started as a daemon===<br />
# MPD is started on boot by {{Filename|/etc/rc.conf}}, by including it in the {{Codeline|DAEMONS}} array. (Or, this can be done manually each session by running {{Codeline|/etc/rc.d/mpd start}} with root privileges).<br />
# Since MPD is now started as root, it first reads the {{Filename|/etc/mpd.conf}} file.<br />
# MPD reads the user variable in the {{Filename|/etc/mpd.conf}} file, and changes from root to this user.<br />
# MPD then reads the contents of the {{Filename|/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 {{Filename|/etc/mpd.conf}} file. This way, uses of {{Codeline|~}} in the configuration file point correctly to the home user's directory, and not root's directory. It may be worthwhile to change all uses of {{Codeline|~}} to {{Codeline|/home/username}} to avoid any confusion over this aspect of MPD's behavior.<br />
<br />
===A clean configuration file===<br />
* As root, check if {{Filename|/etc/mpd.conf}} exists and delete the file if it does. This is safe.<br />
<br />
MPD comes with an example configuration file, available at {{Filename|/usr/share/mpd/mpd.conf.example}}. This file holds an abundance of information on MPD configuration, and holds default mixer values you can simply uncomment.<br />
<br />
* As root, copy this example file to {{Filename|/etc/mpd.conf}}.<br />
# cp /usr/share/mpd/mpd.conf.example /etc/mpd.conf<br />
({{Filename|/usr/share/mpd/mpd.conf.example}} is good for userspace setup)<br />
<br />
Since MPD is being set up to run as a daemon at boot, never put this file in the user's directory like some tutorials suggest, since it will not be read. Moreover, if you previously created a {{Filename|.mpdconf}} file in your home, remove it now (to set up MPD to run with user privileges alone, pleaser refer to the section [[Music_Player_Daemon#Alternative_Setup:_Starting_as_a_User | Alternative_Setup:_Starting_as_a_User]]). This is important to prevent conflicts. The presence of the configuration file in {{Filename|/etc}}, like is the case here, is what will enable MPD to run as a daemon at boot. Otherwise, a script would be needed to run MPD ''after'' the user has logged (like kdm or {{Filename|~/.fluxbox/startup}}) or it would require a manual move each time. For a single music collection, the method used here is simply better, even while the collection is shared to multiple users. Also, don't be afraid about root privileges: even while MPD runs as a daemon, it never completely runs as root since it automatically drops its root privileges after execution.<br />
<br />
===Edit {{Filename|mpd.conf}}===<br />
<br />
The default arch install keeps the setup in /var and uses "mpd" as default user, instead of cluttering up ~/.<br />
Edit {{Filename|/etc/mpd.conf}} to reflect as such.<br />
<br />
{{File|name=/etc/mpd.conf|content=<br />
music_directory "/home/user/music" # Your music dir.<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 "/var/run/mpd/mpd.pid" # Omit this line for systemd<br />
state_file "/var/lib/mpd/mpdstate"<br />
user "mpd"<br />
# Binding to address and port causing problems in mpd-0.14.2 best to leave<br />
# commented.<br />
# bind_to_address "127.0.0.1"<br />
# port "6600"<br />
}}<br />
<br />
* If your music collection is contained under multiple directories, you can make symbolic links under /var/lib/mpd then set 'music_directory' to the directory holding the symbolic links. Remember to set permissions accordingly on the directories being linked.<br />
<br />
* To change the volume of audio from mpd independent of other programs, uncomment or add the switch in mpd.conf:<br />
<br />
{{File|name=/etc/mpd.conf|content=<br />
mixer_type "software"<br />
}}<br />
<br />
* Lastly, if you are running pulseaudio under Gnome 3, the default setting of "alsa" for the audio output will not work. Make the modification from:<br />
{{File|name=/etc/mpd.conf|content=<br />
audio_output {<br />
type "alsa"<br />
name "Sound Card"<br />
}<br />
}}<br />
<br />
to<br />
<br />
{{File|name=/etc/mpd.conf|content=<br />
audio_output {<br />
type "pulse"<br />
name "Sound Card"<br />
}<br />
}}<br />
<br />
===Create files===<br />
<br />
* As root, create the directories and files you specified in {{Filename|/etc/mpd.conf}}.<br />
# mkdir -p /var/lib/mpd/playlists /var/run/mpd<br />
# touch /var/lib/mpd/{mpd.db,mpdstate} && touch /var/run/mpd/mpd.pid<br />
<br />
* You then need to change the file's permissions so that the daemon can modify them.<br />
# chown -R mpd /var/lib/mpd /var/run/mpd<br />
<br />
===Create database===<br />
<br />
Creating the database is now accomplished via the update feature of the client, for example 'mpc update'. The previous method, creating the MPD database as root (# mpd --create-db), is deprecated.<br />
<br />
==Alternative Setup: Starting as a User==<br />
MPD need not be started with root permissions. The only reason why MPD needs to be started as root (by being called from {{Filename|/etc/rc.conf}}) is because the default files and folders in the default configuration file points to directories owned by root (the /var directory). A less common, but perhaps more sensible, approach is to make MPD work with files and directories owned by a normal user. Running MPD as a normal user has several advantages: <br />
# You can easily have a single directory ~/.mpd (or any other directory under /home/username) for all MPD configuration files<br />
# No read/write permission errors<br />
# More flexible calls to MPD by using {{Filename|~/.xinitrc}} instead of including 'mpd' in the {{Filename|/etc/rc.conf}} DAEMONS array.<br />
<br />
The following steps shows how to run MPD as a normal user. '''Note''': this approach will not work if you want multiple users to have access to MPD.<br />
<br />
* Copy the contents of the default MPD configuration file in {{Filename|/usr/share/mpd/mpd.conf.example}} to your home directory. A good place would be {{Filename|"/home/user/.mpd/mpd.conf"}}.<br />
* Follow the 'old setup instructions' from above, ignoring the first part about copying the config to {{Filename|/etc/mpd.conf}} and do not set a user variable. <br />
* Create all of the requisite files in {{filename|"/home/user/.mpd/"}}:<br />
"~/.mpd/playlists/"<br />
"~/.mpd/db"<br />
"~/.mpd/mpd.db"<br />
"~/.mpd/mpd.log"<br />
"~/.mpd/mpd.error"<br />
"~/.mpd/mpd.pid"<br />
"~/.mpd/mpdstate"<br />
<br />
* Let MPD start on bootup by calling it from your {{Filename|~/.xinitrc}} as follows:<br />
# this starts mpd as normal user<br />
mpd ~/.mpd/mpd.conf<br />
{{Note| that you don't have to put a "&" at the end of the line here, since MPD will automatically daemonize itself.}}<br />
<br />
Lastly, delete the entry 'mpd' from your DAEMONS array in {{Filename|/etc/rc.conf}}, as you are not running it as root anymore.<br />
<br />
===Quick setup===<br />
<br />
The fastest way to do set up the structure is to do this:<br />
<br />
$ mkdir -p ~/.mpd/playlists && touch ~/.mpd/database && cp /usr/share/doc/mpd/mpdconf.example ~/.mpd/mpd.conf<br />
<br />
Then edit mpd.conf to your liking, in a manner similar to [[Music_Player_Daemon#Edit_mpd.conf]]. Beware that you must uncomment the db_file entry if you do edit mpd.conf.<br />
<br />
Then, to run it:<br />
<br />
$ mpd ~/.mpd/mpd.conf<br />
<br />
<br />
===Even quicker setup===<br />
I created a little script that will only ask for the location of your music and then creates the needed files and folders for you.<br />
You can find the script here:<br />
[http://karif.server-speed.net/~carnager/mpdsetup.tar]<br />
extract it<br />
$ tar xf mpdsetup.tar<br />
and run it<br />
$ ./mpdsetup.sh<br />
<br />
If you want to use this config in daemon mode, open it (~/.mpdconf) in an editor and find the "user" line. remove the comment (#) and fill in your own user name. Then copy the file to /etc/mpd.conf. If running mpd as user is fine for you, make sure to remove "mpd" from the daemons list in /etc/rc.conf<br />
<br />
===Multi-mpd setup===<br />
'''Useful if you want to run for example an icecast server.'''<br />
If you want a second MPD daemon (e.g., with icecast output to share music over the network) to use the same music and playlist as the one above, simply copy the above configuration file and make a new file (e.g., {{Filename|/home/username/.mpd/config-icecast}}), and only change the log_file, error_file, pid_file, and state_file parameters (e.g., {{Filename|mpd-icecast.log}}, {{Filename|mpd-icecast.error}}, and so on); using the same directory paths for the music and playlist directories would ensure that this second mpd daemon would use the same music collection as your first one (e.g., creating and editing a playlist under the first daemon would affect the second daemon as well, so that you don't have to create the same playlists all over again for the second daemon). Then, call this second daemon the same way from your {{Filename|~/.xinitrc}} above. (Just be sure to have a different port number, so as to not conflict with your first mpd daemon).<br />
<br />
==Clients==<br />
Install a client program for MPD. Popular options are:<br />
<br />
===Console===<br />
* '''mpc''' &ndash; Command Line Client (you'll probably want this one no matter what)<br />
# pacman -S mpc<br />
* [http://mpd.wikia.com/wiki/Client:Ncmpc/ ncmpc] &ndash; NCurses Client (this one is very handy for running in a console)<br />
# pacman -S ncmpc<br />
* [http://unkart.ovh.org/ncmpcpp/ ncmpcpp] &ndash; Clone of ncmpc with some new features written in C++<br />
# pacman -S ncmpcpp<br />
* [http://pms.sourceforge.net/ pms] &ndash; NCurses Client (highly configurable and accessible)<br />
Install [http://aur.archlinux.org/packages.php?ID=24378 pmus] from the [[AUR]].<br />
<br />
===Graphical===<br />
* [http://ario-player.sourceforge.net ario] &ndash; GTK+ Client with a Rhythmbox like library browser<br />
# pacman -S ario<br />
* [http://gmpcwiki.sarine.nl/index.php?title=GMPC gmpc] &ndash; GNOME Client<br />
# pacman -S gmpc<br />
* [http://bitcheese.net/wiki/QMPDClient QMPDClient] &ndash; Client written with Qt 4.x.<br />
# pacman -S qmpdclient<br />
* [http://sonata.berlios.de/ sonata] &ndash; Python GTK+ Client<br />
# pacman -S sonata<br />
* [http://aur.archlinux.org/packages.php?ID=33380 dmpc] &ndash; Dmenu-based MPC client with a playlist manager and state-saving on playlist changes<br />
Install [http://aur.archlinux.org/packages.php?ID=33380 dmpc] from the [[AUR]].<br />
<br />
See a long list of clients at the [http://mpd.wikia.com/wiki/Clients mpd wiki].<br />
<br />
==Extra stuff==<br />
===Last.fm scrobbling===<br />
To scrobble your songs to [http://www.last.fm Last.fm] using MPD there are several alternatives.<br />
<br />
====mpdscribble====<br />
mpdscribble is another daemon, available in the "community" repository (if you prefer, the "git" version is available in the [http://aur.archlinux.org/packages.php?ID=22274 AUR]). This is arguably the best alternative, because it's the semi-official MPD scrobbler and uses the new "idle" feature in MPD for more accurate scrobbling. Also, you don't need root access to configure it, because it doesn't need any changes to <tt>/etc</tt> at all. Visit [http://mpd.wikia.com/wiki/Client:Mpdscribble the official website] for more information.<br />
<br />
After you have installed mpdscribble, do the following (not as root):<br />
<br />
* {{Codeline|$ mkdir ~/.mpdscribble}}<br />
* Create the file {{Filename|~/.mpdscribble/mpdscribble.conf}} and add the following:<br />
<pre><br />
[mpdscribble] <br />
host = <your mpd host> # optional, defaults to $MPD_HOST or localhost<br />
port = <your mpd port> # optional, defaults to $MPD_PORT or 6600<br />
log = /home/<YOUR_USERNAME>/.mpdscribble/mpdscribble.log<br />
verbose = 2<br />
sleep = 1<br />
musicdir = <your music directory><br />
proxy = <your proxy> # optional, e. g. http://your.proxy:8080, defaults to none<br />
<br />
[last.fm]<br />
# last.fm section, comment if you don't use last.fm<br />
url = http://post.audioscrobbler.com/<br />
username = <your last.fm username><br />
password = <your last.fm password> # md5sum also possible: echo -n 'PASSWORD' | md5sum | cut -f 1 -d " "<br />
journal = /home/<YOUR_USERNAME>/.mpdscribble/lastfm.journal<br />
<br />
[libre.fm]<br />
# libre.fm section, comment if you don't use libre.fm<br />
url = http://turtle.libre.fm/<br />
username = <your libre.fm username><br />
password = <your libre.fm password> # md5sum also possible: echo -n 'PASSWORD' | md5sum | cut -f 1 -d " "<br />
journal = /home/<YOUR_USERNAME>/.mpdscribble/librefm.journal<br />
</pre><br />
* Add {{Codeline|mpdscribble}} to your {{Filename|~/.xinitrc}}:<br />
pidof mpdscribble >& /dev/null<br />
if [ $? -ne 0 ]; then<br />
mpdscribble &<br />
fi<br />
<br />
====Sonata & Ario====<br />
The easiest way, if you don't care about having to have a program window open all the time, is using Sonata or Ario which are graphical frontends to MPD. They have built-in support for Last.fm scrobbling in their preferences. A downside of this is that Sonata doesn't cache your songs if for some reason you don't happen to have an Internet connection at the time of playing.<br />
<br />
====lastfmsubmitd====<br />
lastfmsubmitd is a daemon which is available in the "community" repository. To install it, first edit {{Filename|/etc/lastfmsubmitd.conf}} and add both {{Codeline|lastfmsubmitd}} and {{Codeline|lastmp}} to the {{Codeline|DAEMONS}} array in {{Filename|/etc/rc.conf}}.<br />
<br />
====Last.fm playback====<br />
<br />
=====Last.fm playback with lastfmproxy=====<br />
lastfmproxy is a python script that streams a last.fm music stream to another media player. To setup, install [http://aur.archlinux.org/packages.php?ID=14214 lastfmproxy] from the [[AUR]] and then edit {{Filename|/usr/share/lastfmproxy/config.py}}. If you plan to only stream to MPD on the same host, just edit the login info.<br />
<br />
{{Note | Since it installs to a read only directory but it requires read/write access for features like saving previously listened to stations, it would be wise to copy {{Filename|/usr/share/lastfmproxy}} to your home directory.}}<br />
<br />
Start lastfmproxy with {{Codeline|lastfmproxy}} and visit http://localhost:1881/ in your web browser. To add a last.fm station navigate to http://localhost:1881/ followed by the lastfm:// url. Example: http://localhost:1881/lastfm://globaltags/punk . Navigate back to http://localhost:1881/ and download the m3u file by selecting the ''Start Listening'' link. Simply add it to your music library path.<br />
<br />
==Native Last.fm playback==<br />
Since 0.16 mpd has a very well working method to play back last.fm streams.<br />
{{File|name=/etc/mpd.conf|content=<br />
$ playlist_plugin {<br />
name "lastfm"<br />
user "my_username"<br />
password "my_password"<br />
}<br />
}}<br />
Then use e.g. mpc to load streams<br />
$ mpc load "lastfm://artist/Beatles"<br />
<br />
===Never play on start===<br />
<br />
This feature has recently been added to mpd git by Martin Kellerman, see commits b57330cf75bcb339e3f268f1019c63e40d305145 and 2fb40fe728ac07574808c40034fc0f3d2254d49d.<br />
<br />
====[https://aur.archlinux.org/packages.php?ID=19676 mpd-git] Method====<br />
This is the best method currently available, but is only currently (April 2011) enabled in the git version. Install [https://aur.archlinux.org/packages.php?ID=19676 mpd-git] from the [[AUR]], then add {{Codeline|restore_paused "yes"}} to your {{Filename|mpd.conf}} file.<br />
<br />
If you have issues with connecting your client to [https://aur.archlinux.org/packages.php?ID=19676 mpd-git], see [[Music Player Daemon#Other issues when attempting to connect to mpd with a client]].<br />
<br />
====Method 1====<br />
If you don't want MPD to always play on your system start, but yet you want to preserve the other state information, add the following lines to your {{Filename|/etc/rc.d/mpd}} file:<br />
'' ...''<br />
'' stat_busy "Starting Music Player Daemon"''<br />
<br />
# always start in paused state<br />
awk '/^state_file[ \t]+"[^"]+"$/ {<br />
match($0, "\".+\"")<br />
sfile = substr($0, RSTART + 1, RLENGTH - 2)<br />
} /^user[ \t]+"[^"]+"$/ {<br />
match($0, "\".+\"")<br />
user = substr($0, RSTART + 1, RLENGTH - 2)<br />
} END {<br />
if (sfile == "")<br />
exit;<br />
if (user != "")<br />
sub(/^~/, "/home/" user, sfile)<br />
system("sed -i \x27s|^\\(state:[ \\t]\\{1,\\}\\)play$|\\1pause|\x27 \x27" sfile "\x27")<br />
}' /etc/mpd.conf<br />
<br />
'' /usr/bin/mpd /etc/mpd.conf &> /dev/null''<br />
'' ...''<br />
<br />
This will change the player status to "paused", if it was stopped while playing. Next, you want this file to be preserved, so MPD updates won't erase this edit. Add (or edit) this line to your {{Filename|/etc/pacman.conf}}:<br />
NoUpgrade = etc/rc.d/mpd<br />
<br />
====Method 2====<br />
<br />
Another simpler method, would be to add mpd to your {{Filename|[[rc.conf]]}} deamons array and add {{Codeline|mpc stop}} or {{Codeline|mpc pause}} to {{Filename|/etc/rc.local.shutdown}} and to {{Filename|/etc/rc.local}}. (Remember you must have mpc installed to use this method).<br />
<br />
Adding only the order in {{Filename|/etc/rc.local}} cannot assure that mpd will play absolutely nothing, since there may be a delay before the stop command is executed. <br />
On the other hand, if you only add the order to {{Filename|/etc/rc.local.shutdown}}, that will assure that mpd won't play at all, as long as you properly shutdown your system.<br />
Even though they are redundant, adding it to {{Filename|/etc/rc.local}} would serve as a safety for those, presumably, rare occasions when you do not shutdown the system properly.<br />
<br />
====Method 3====<br />
<br />
The general idea between this method is to ask mdp to pause music when user logs out so that during next restart, mdp will stick to that "pause" state. Sending such command can be achieve using [http://www.archlinux.org/packages/extra/x86_64/mpc/ mpc], the command line interface to MPD:<br />
pacman -S mpc<br />
<br />
GDM users can then add the next line to /etc/gdm/PostSession/Default (be sure to add it before "exit 0"):<br />
/usr/bin/mpc pause<br />
<br />
Non-GDM users can use their own login manager's method to launch the line at logout.<br />
<br />
===MPD & ALSA===<br />
Sometimes, when you use other audio output, e.g: some web pages containing Flash applets, MPD cannot reproduce anything anymore (until you restart). The error looks something like: (if you search the file {{Filename|/var/log/mpd/mpd.error}})<br />
<br />
Error opening alsa device "hw:0,0": Device or resource busy<br />
<br />
And here is the solution (dmix saving our life again). Apply these lines in your {{Filename|/etc/mpd.conf}}:<br />
<br />
<pre><br />
audio_output {<br />
type "alsa"<br />
name "Sound Card"<br />
options "dev=dmixer"<br />
device "plug:dmix"<br />
}<br />
</pre><br />
<br />
And then restart with {{Codeline|/etc/rc.d/mpd restart}}.<br />
<br />
Searching on Internet I found the reason for why that happens in Gentoo's wiki:<br />
* The sound card does not support hardware mixing (uses '''dmix''' plugin)<br />
* An application does not work with ALSA with it's default settings<br />
<br />
For a detailed description, it is recommended to take a look at [http://mpd.wikia.com/wiki/Alsa this] link. There you can find an example asound.conf which worked for me right out of the box.<br />
<br />
====High CPU usage with ALSA====<br />
When using MPD with ALSA, users may experience MPD taking up lots of CPU (around 20-30%). This is caused by most sound cards supporting 48kHz and most music being 44kHz, thus forcing MPD to resample it. This operation takes lots of CPU cycles and results into high usage.<br />
<br />
For most users the problem should be solved by telling MPD not to use resampling by adding {{Codeline|auto_resample "no"}} into audio_output-part of {{Filename|/etc/mpd.conf}}. This will degrade quality slightly, however.<br />
<br />
Example from {{Filename|mpd.conf}}:<br />
<br />
audio_output {<br />
type "alsa"<br />
name "My ALSA Device"<br />
auto_resample "no"<br />
}<br />
<br />
Although it may not give as drastic a speedup, enabling mmap may speed things up:<br />
<br />
audio_output {<br />
type "alsa"<br />
name "My ALSA Device"<br />
use_mmap "yes"<br />
}<br />
<br />
Some users might also want to tell dmix to use 44kHz as well. More info about tuning performance of your MPD can be found from: [http://mpd.wikia.com/wiki/Tuning MPD wiki]<br />
<br />
====Example configuration: Output with 44.1 KHz at e. g. 16 bit depth, multiple programs at once====<br />
<br />
''Why these formats?'' Because they are standard CDA, because ALSA on its own allows more than one program "to sound" only with dmix — whose resampling algorithm is inferior — and because dmix by default resamples anything lower to 48 KHz (or whatever higher format is playing at the time). Also, some get clicking sounds if at least {{Filename|mpd.conf}} is not changed this way.<br />
<br />
''What's the downside?'' These settings cause ''everything'' (if necessary) to be resampled to this format, such as material from DVD or TV which usually is at 48 KHz. But there is no known way to have ALSA dynamically change the format, and particularly if you listen to far more CDs than anything else the occasional 48 → 44.1 isn't too great a loss.<br />
<br />
The following assumes that there are not already other settings which conflict resp. overwrite it. This applies especially to the current user's potential {{Filename|~/.asoundrc}} — which MPD as its own user ignores, therefore the following should go to {{Filename|/etc/asound.conf}}:<br />
<br />
{{File|name=/etc/asound.conf|content=<br />
defaults.pcm.dmix.rate 44100 # Force 44.1 KHz<br />
defaults.pcm.dmix.format S16_LE # Force 16 bits<br />
}}<br />
<br />
{{File|name=/etc/mpd.conf|content=<br />
audio_output {<br />
type "alsa" # Use the ALSA output plugin.<br />
name "HDA Intel" # Can be called anything or nothing tmk, but must be present.<br />
options "dev=dmixer"<br />
device "plug:dmix" # Both lines cause MPD to output to dmix.<br />
format "44100:16:2" # the actual format<br />
auto_resample "no" # This bypasses ALSA's own algorithms, which generally are inferior. See below how to choose a different one.<br />
use_mmap "yes" # Minor speed improvement, should work with all modern cards.<br />
}<br />
<br />
samplerate_converter "0" # MPD's best, most CPU intensive algorithm. See 'man mpd.conf' for others — for anything other than the poorest "internal", libsamplerate must be installed.<br />
}}<br />
<br />
{{Note|MPD gives the mp3 format a special treatment at decoding: It's always outputted as 24 bit. (The conversion as forced by the ''format'' line only comes after that.)}}<br />
<br />
If one wants to leave the bit depth decision to ALSA resp. MPD, comment out resp. omit the ''dmix.format'' line and change the one for mpd with ''format'' to "44100:*:2".<br />
<br />
{{Note|''Crossfading'' between files decoded at two different bit depths (say, one mp3 and one 16 bit flac) does not work unless conversion is active.}}<br />
<br />
===Control MPD with lirc===<br />
There are already some clients designed for communications between lircd and MPD, however, as far as the practical use, they aren't very useful since their functions are limited.<br />
<br />
It's recommended to use mpc with irexec. mpc is a command line player which only sends the command to MPD and exits immediately, which is perfect for irexec, the command runner included in lirc. What irexec does is that it runs a specified command once received a remote control button.<br />
<br />
First of all, please setup your remotes as referred to the '''[[Lirc]]''' article.<br />
<br />
Edit your favored lirc startup configuration file, default location is {{Filename|~/.lircrc}}.<br />
<br />
Fill the file with the following pattern:<br />
begin<br />
prog = irexec<br />
button = <button_name><br />
config = <command_to_run><br />
repeat = <0 or 1><br />
end<br />
<br />
An useful example:<br />
## irexec<br />
begin<br />
prog = irexec<br />
button = play_pause<br />
config = mpc toggle<br />
repeat = 0<br />
end<br />
<br />
begin<br />
prog = irexec<br />
button = stop<br />
config = mpc stop<br />
repeat = 0<br />
end<br />
begin<br />
prog = irexec<br />
button = previous<br />
config = mpc prev<br />
repeat = 0<br />
end<br />
begin<br />
prog = irexec<br />
button = next<br />
config = mpc next<br />
repeat = 0<br />
end<br />
begin<br />
prog = irexec<br />
button = volup<br />
config = mpc volume +2<br />
repeat = 1<br />
end<br />
begin<br />
prog = irexec<br />
button = voldown<br />
config = mpc volume -2<br />
repeat = 1<br />
end<br />
begin<br />
prog = irexec<br />
button = pbc<br />
config = mpc random<br />
repeat = 0<br />
end<br />
begin<br />
prog = irexec<br />
button = pdvd<br />
config = mpc update<br />
repeat = 0<br />
end<br />
begin<br />
prog = irexec<br />
button = right<br />
config = mpc seek +00:00:05<br />
repeat = 0<br />
end<br />
begin<br />
prog = irexec<br />
button = left<br />
config = mpc seek -00:00:05<br />
repeat = 0<br />
end<br />
begin<br />
prog = irexec<br />
button = up<br />
config = mpc seek +1%<br />
repeat = 0<br />
end<br />
begin<br />
prog = irexec<br />
button = down<br />
config = mpc seek -1%<br />
repeat = 0<br />
end<br />
<br />
There are more functions for mpc, run {{Codeline|man mpc}} for more info.<br />
<br />
===Control MPD with bluetooth phone===<br />
You can also control MPD (to a certain extent) using a bluetooth enabled phone. You need to do the following:<br />
<br />
* install [http://remuco.sourceforge.net/index.php/Remuco remuco] -- a wireless remote control for several Linux media players ([http://aur.archlinux.org/packages.php?ID=25072 aur])<br />
* transfer remuco client -- jar/jad files from {{Filename|/usr/share/remuco/client/}} to your phone and install it<br />
* run {{Codeline|remuco-mpd}} (as current user)<br />
* run remuco on your phone, define a new bluetooth remuco connection (pair first if you haven't done this previously) and explore its capabilities<br />
<br />
More information about remuco including troubleshooting to be found at its [http://remuco.sourceforge.net/index.php/Remuco homepage]<br />
<br />
===MPD & PulseAudio===<br />
<br />
Edit {{Filename|/etc/mpd.conf}}, and uncomment the audio_output section for the type "pulse". The server and sink lines of it should be commented unless you know what you're doing.<br />
<br />
Then, add the mpd user (and yours if you haven't done so already) to the necessary pulse groups. The pulse-access group should be sufficient but you may want to add pulse-rt as well. The group "pulse" doesn't appear to be necessary.<br />
# gpasswd -a mpd pulse-access<br />
# gpasswd -a mpd pulse-rt<br />
<br />
Lastly, you may or may not need to copy {{Filename|~/.pulse-cookie}} from your current (pulse working) user's dir to your mpd user's home directory. It is likely to be {{Filename|/var/lib/mpd}} if you followed the first part of this wiki. This would probably only allow your current user to listen in on MPD's pulse. You may consider running pulse system-wide if that's insufficient.<br />
<br />
===Cue Files===<br />
<br />
To make cue file support actually work, you have to work around a nasty libcue bug. Libcue copied some files directly from libcdio, making it conflict with it. Steps to do to get proper cue support:<br />
<br />
* remove libcdio temporary (pacman -Rdd libcdio)<br />
* install libcue (pacman -S libcue)<br />
* install mpd with abs or from aur.<br />
* reinstall libcdio (pacman -S libcdio)<br />
<br />
At the point of writing mpd does not parse tracknumbers from cue sheets. There is a patch available (http://musicpd.org/mantis/view.php?id=3230)<br />
Once this patch is merged into mpd, i will remove this line :)<br />
<br />
==Troubleshooting==<br />
===Autodetection failed===<br />
During the start of MPD, it tries to autodetect your set-up and configure output and volume control accordingly. Though this mostly goes well, it will fail for some systems. It may help to tell MPD specifically what to use as output and mixer control. If you copied {{Filename|/etc/mpd.conf}} over from {{Filename|/etc/mpd.conf.example}} as mentioned above, you can simply uncomment:<br />
<br />
Example for alsa output type and alsa mixer:<br />
audio_output {<br />
type "alsa"<br />
name "My ALSA Device"<br />
device "hw:0,0" # optional<br />
format "44100:16:2" # optional<br />
mixer_type "hardware"<br />
mixer_device "default"<br />
mixer_control "PCM"<br />
}<br />
<br />
'''Note:''' in case of permission problems when using ESD with MPD run this as root:<br />
# chsh -s /bin/true mpd<br />
<br />
===Executable permissions===<br />
{{Warning|This is not good security practice and may be unnecessary.}}<br />
<br />
MPD needs to have +x permissions on '''ALL''' parent directories to your music collection (ie. if it's located outside of "mpd" home directory /var/lib/mpd). By default useradd sets permissions on home dir to 1700 drwx------. So if you're like me you will need to change permissions of /home/user. Example... my music collection is located /home/user/music. <br />
# chmod a+x /home/$USER<br />
# chmod -R a+X /home/$USER/music<br />
<br />
====Alternative solution====<br />
An alternative solution would be to use your group to share a selection of files, among them your music library. First remove all permissions for the group then add group permissions to read and execute home and music.<br />
# chmod -R g-rwx /home/$USER<br />
# chmod g+rx /home/$USER<br />
# chmod -R g+rX /home/$USER/music<br />
<br />
====Another alternative solution====<br />
Another alternative is to remount the music directory under a directory that mpd has access to. This does not entail the same security risks as modifying the permissions on one's home directory.<br />
# mkdir /var/lib/mpd/music<br />
# echo "/home/$USER/music /var/lib/mpd/music none bind" >> /etc/fstab<br />
# mount -a<br />
# /etc/rc.d/mpd restart<br />
And that should fix the problem. See also [https://bbs.archlinux.org/viewtopic.php?id=86449 the forum thread.]<br />
<br />
===Avoiding timeouts===<br />
To get rid of timeouts (i.e. when you paused music for long time) in gpmc and other clients uncomment and increase {{Codeline|connection_timeout}} option in {{Filename|mpd.conf}}.<br />
<br />
If files and/or titles are shown in wrong encoding, uncomment and change {{Codeline|filesystem_charset}} and {{Codeline|id3v1_encoding}} options.<br />
Note that you cannot set encoding for ID3 v2 tags. To workaround this you may use [http://mpd.wikia.com/wiki/GenericDecoder#Generic_Tagreader external tag readers].<br />
<br />
If you want to use another computer to control MPD over a network, the {{Codeline|bind_to_address}} option in {{Filename|mpd.conf}} will need to be set to either your IP address, or {{Codeline|any}} if your IP address changes frequently. <br />
<br />
'''Streaming'''<br><br />
With the latest version of MPD (0.15), built-in httpd streaming is now available.<br />
<br />
To activate this feature, you'll just need to add a new output of type httpd in {{Filename|mpd.conf}}:<br />
audio_output {<br />
type "httpd"<br />
name "What you want"<br />
encoder "lame" # vorbis or lame supported<br />
port "8000"<br />
bitrate "128"<br />
format "44100:16:2" # change 2 to 1 for mono<br />
}<br />
<br />
Restart the mpd deamon and, from another computer, simply load the stream as any other url. <br />
$ mplayer http://<server's IP>:8000<br />
<br />
{{Note | You must open the port on your router / firewall for the stream to be connectible to from another computer.}}<br />
<br />
Most players (i.e. vlc or xmms2) should also be able to load the stream via their "add url..." menu option.<br />
<br />
This is a nice clean way to replace your current icecast setup with something natively supported within MPD.<br />
<br />
===mpd hangs on first startup===<br />
This is a common error that's caused by corrupt mp3 tags.<br />
Here is an experimental way to solve this issue.<br />
Requirements:<br />
* kid3<br />
* easytag<br />
<br />
This method is very tedious, especially with a huge database. Just as a baseline it took 2.5h to fix a 16Gb DB.<br />
<br />
====Easy Tag====<br />
The purpose of easytag here is that easytag detects the error in the tags, but like MPD it hangs and dies. The trick here is that easy tags actually tells you what file is causing the problem on the status bar.<br />
Before starting easytag make sure to have a terminal close to be ready to kill easy tag to avoid a hang. Once you are ready, on the tree view select the directory where all your music is located. By default easytag starts to search all subdirectories for mp3 files. Once you notice that easytag stopped scanning for songs, make note of the culprit and kill easytag.<br />
<br />
====KID3====<br />
Here's where kid3 comes in handy. With kid3 go to the offending song and rewrite one of the tags. then save the file. This should force kid3 to rewrite the whole tag again fixing the problem with MPD and easy tag hanging.<br />
<br />
Repeat this procedure until your music library is done.<br />
<br />
===Cannot connect to mpd: host "localhost" not found: Temporary failure in name resolution===<br />
Cannot connect to MPD (with ncmpcpp), if you are disconnected from network. Solution is [[IPv6 - Disabling the Module|disable IPv6]] or add line to /etc/hosts<br />
::1 localhost.localdomain localhost<br />
<br />
===Other issues when attempting to connect to mpd with a client===<br />
Some have reported being unable to access mpd with various clients, for example seeing errors like these:<br />
$ ncmpcpp<br />
Cannot connect to mpd: Connection closed by the server<br />
$ sonata<br />
2011-02-13 18:33:05 Connection lost while reading MPD hello<br />
2011-02-13 18:33:05 Not connected<br />
2011-02-13 18:33:05 Not connected<br />
<br />
Please see posts on ncmpcpp on the Arch Forums [https://bbs.archlinux.org/viewtopic.php?id=109962 HERE] and [https://bbs.archlinux.org/viewtopic.php?id=113493 HERE]. Also see the Arch bug report on this issue [https://bugs.archlinux.org/task/22071 HERE]. <br />
<br />
====First fix====<br />
Check {{Filename|mpd.conf}} for a line like {{Codeline|mpd.error}} and remove it. The mpd error file is deprecated and has been removed.<br />
<br />
====Second fix====<br />
{{Note|I'm not so sure this is a good idea. There is a warning about changing the address to bind to in the default mpd.conf. If this does not help, you might want to comment out the changes.}}<br />
If that doesn't help, add the following to {{Filename|mpd.conf}}:<br />
<pre><br />
bind_to_address "127.0.0.1"<br />
port "6600"<br />
</pre><br />
<br />
Afterwards, instruct your client to connect via 127.0.0.1. For example, add the following to the ncmpcpp config file:<br />
<pre><br />
mpd_host "127.0.0.1"<br />
mpd_port "6600"<br />
</pre><br />
<br />
<br />
===Port 6600 already in use===<br />
MPD needs to bind to port 6600 and cannot start if it's already in use. The most common reason for this is that the user has started MPD once and then subsequently tried to start mpd again. In general, nothing should be done here.<br />
<br />
If port 6600 is tied up for some other reason, one can use the following command to find the offending process:<br />
# netstat -tulpan | grep 6600<br />
<br />
This will list IP:Port and the process name holding the connection (root privileges are required to see all processes).<br />
<br />
If you need to restart mpd for whatever reason, use:<br />
<pre><br />
$ mpd --kill<br />
$ mpd <br />
</pre><br />
A more brute-force approach:<br />
<pre><br />
$ killall mpd<br />
$ mpd <br />
</pre><br />
{{Note| If you typically run MPD as root, you will need to run the above commands as root.}}<br />
<br />
In the latest version of MPD, --create-db is completely deprecated. The database will be created automagically on first run and can subsequently be updated via your client (i.e. mpc update). You can now use inotify support to automatically update your music database. Add the following to {{File|name=mpd.conf|content=auto_update "yes"}} to enable it.<br />
<br />
===Binding to IPV6 before IPV4===<br />
If on startup, you see this message:<br />
listen: bind to '0.0.0.0:6600' failed: Address already in use (continuing anyway, because binding to '[::]:6600' succeeded)<br />
MPD is attempting to bind to the ipv6 interface before binding to ipv4. If you want to use your ipv4 interface, hardcode it in mpd.conf, like so:<br />
bind_to_address "127.0.0.1"<br />
Or, you could specify several binds, for example, to have MPD listen on localhost and the external IP of your network card:<br />
bind_to_address "127.0.0.1"<br />
bind_to_address "192.168.1.13"<br />
<br />
===Crackling sound with some audio files===<br />
This is usually a playback speed problem and can be fixed by uncommenting the audio_output_format line in:<br />
<br />
{{File|name=/etc/mpd.conf|content=<br />
audio_output_format "44100:16:2"}}<br />
<br />
This is usually a sane value for most mp3 files.<br />
<br />
===daemon: cannot setgid for user "mpd": Operation not permitted ===<br />
<br />
The error is stating that the user starting the process (you) does not have permissions to become another user (mpd) which the configuration has told that process to run as.<br />
<br />
To solve the issue, simply start mpd as root.<br />
su -c "/etc/rc.d/mpd start"<br />
or<br />
sudo /etc/rc.d/mpd start<br />
<br />
==External links==<br />
* [http://www.musicpd.org/ Official Web Site]<br />
* [http://mpd.wikia.com/wiki/Main_Page Official Wiki]<br />
* [http://mpd.wikia.com/wiki/Clients Sorted List of MPD Clients]<br />
* [http://www.musicpd.org/forum/ MPD forum]</div>Rasihttps://wiki.archlinux.org/index.php?title=Music_Player_Daemon&diff=150768Music Player Daemon2011-08-06T01:11:03Z<p>Rasi: /* Last.fm playback with lastfmproxy */</p>
<hr />
<div>[[fr:MPD]]<br />
[[Category:Audio/Video (English)]]<br />
[[Category:Daemons and system services (English)]]<br />
{{i18n|Music Player Daemon}}<br />
[[pl:Music Player Daemon]]<br />
<br />
'''MPD''' (music player daemon) is an audio player that has a server-client architecture. MPD runs in the background as a daemon, manages playlists and a music database, and uses very few resources. In order to interface with it, you need a separate client. More information can be found on their [http://www.musicpd.org/ website].<br />
<br />
''Please'' have a look at the official page for setup and troubleshooting instructions, the main developer called our wiki page in its current state ''"full of symptom killers"'', hence the official pages should contain better instructions.<br />
<br />
==Installing mpd==<br />
Install with [[pacman]]:<br />
# pacman -S mpd<br />
<br />
==Daemon Setup: Starting at Boot==<br />
General information about MPD configuration may be found at http://mpd.wikia.com/wiki/Configuration.<br />
<br />
===Sound setup===<br />
To make audio output actually work ensure that you have setup audio card and mixer correctly. See [[ALSA]], and [[PulseAudio]] if you are using Gnome 3. Do not forget to unmute the required channels in alsamixer, raise the volume and save changes with alsactl store. Run mpd with {{Filename|/usr/bin/mpd --stdout --no-daemon --verbose}} if that still doesn't work.<br />
<br />
Make sure your card can do hardware mixing (most of them can, including onboard audio). Or else this could cause problems with multiple sound playback. For example, this can prevent Mplayer from playing back sound while the mpd daemon is running, returning an audio error message stating the device is busy.<br />
<br />
===Timeline of MPD's behavior on a typical working setup when started as a daemon===<br />
# MPD is started on boot by {{Filename|/etc/rc.conf}}, by including it in the {{Codeline|DAEMONS}} array. (Or, this can be done manually each session by running {{Codeline|/etc/rc.d/mpd start}} with root privileges).<br />
# Since MPD is now started as root, it first reads the {{Filename|/etc/mpd.conf}} file.<br />
# MPD reads the user variable in the {{Filename|/etc/mpd.conf}} file, and changes from root to this user.<br />
# MPD then reads the contents of the {{Filename|/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 {{Filename|/etc/mpd.conf}} file. This way, uses of {{Codeline|~}} in the configuration file point correctly to the home user's directory, and not root's directory. It may be worthwhile to change all uses of {{Codeline|~}} to {{Codeline|/home/username}} to avoid any confusion over this aspect of MPD's behavior.<br />
<br />
===A clean configuration file===<br />
* As root, check if {{Filename|/etc/mpd.conf}} exists and delete the file if it does. This is safe.<br />
<br />
MPD comes with an example configuration file, available at {{Filename|/usr/share/mpd/mpd.conf.example}}. This file holds an abundance of information on MPD configuration, and holds default mixer values you can simply uncomment.<br />
<br />
* As root, copy this example file to {{Filename|/etc/mpd.conf}}.<br />
# cp /usr/share/mpd/mpd.conf.example /etc/mpd.conf<br />
({{Filename|/usr/share/mpd/mpd.conf.example}} is good for userspace setup)<br />
<br />
Since MPD is being set up to run as a daemon at boot, never put this file in the user's directory like some tutorials suggest, since it will not be read. Moreover, if you previously created a {{Filename|.mpdconf}} file in your home, remove it now (to set up MPD to run with user privileges alone, pleaser refer to the section [[Music_Player_Daemon#Alternative_Setup:_Starting_as_a_User | Alternative_Setup:_Starting_as_a_User]]). This is important to prevent conflicts. The presence of the configuration file in {{Filename|/etc}}, like is the case here, is what will enable MPD to run as a daemon at boot. Otherwise, a script would be needed to run MPD ''after'' the user has logged (like kdm or {{Filename|~/.fluxbox/startup}}) or it would require a manual move each time. For a single music collection, the method used here is simply better, even while the collection is shared to multiple users. Also, don't be afraid about root privileges: even while MPD runs as a daemon, it never completely runs as root since it automatically drops its root privileges after execution.<br />
<br />
===Edit {{Filename|mpd.conf}}===<br />
<br />
The default arch install keeps the setup in /var and uses "mpd" as default user, instead of cluttering up ~/.<br />
Edit {{Filename|/etc/mpd.conf}} to reflect as such.<br />
<br />
{{File|name=/etc/mpd.conf|content=<br />
music_directory "/home/user/music" # Your music dir.<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 "/var/run/mpd/mpd.pid" # Omit this line for systemd<br />
state_file "/var/lib/mpd/mpdstate"<br />
user "mpd"<br />
# Binding to address and port causing problems in mpd-0.14.2 best to leave<br />
# commented.<br />
# bind_to_address "127.0.0.1"<br />
# port "6600"<br />
}}<br />
<br />
* If your music collection is contained under multiple directories, you can make symbolic links under /var/lib/mpd then set 'music_directory' to the directory holding the symbolic links. Remember to set permissions accordingly on the directories being linked.<br />
<br />
* To change the volume of audio from mpd independent of other programs, uncomment or add the switch in mpd.conf:<br />
<br />
{{File|name=/etc/mpd.conf|content=<br />
mixer_type "software"<br />
}}<br />
<br />
* Lastly, if you are running pulseaudio under Gnome 3, the default setting of "alsa" for the audio output will not work. Make the modification from:<br />
{{File|name=/etc/mpd.conf|content=<br />
audio_output {<br />
type "alsa"<br />
name "Sound Card"<br />
}<br />
}}<br />
<br />
to<br />
<br />
{{File|name=/etc/mpd.conf|content=<br />
audio_output {<br />
type "pulse"<br />
name "Sound Card"<br />
}<br />
}}<br />
<br />
===Create files===<br />
<br />
* As root, create the directories and files you specified in {{Filename|/etc/mpd.conf}}.<br />
# mkdir -p /var/lib/mpd/playlists /var/run/mpd<br />
# touch /var/lib/mpd/{mpd.db,mpdstate} && touch /var/run/mpd/mpd.pid<br />
<br />
* You then need to change the file's permissions so that the daemon can modify them.<br />
# chown -R mpd /var/lib/mpd /var/run/mpd<br />
<br />
===Create database===<br />
<br />
Creating the database is now accomplished via the update feature of the client, for example 'mpc update'. The previous method, creating the MPD database as root (# mpd --create-db), is deprecated.<br />
<br />
==Alternative Setup: Starting as a User==<br />
MPD need not be started with root permissions. The only reason why MPD needs to be started as root (by being called from {{Filename|/etc/rc.conf}}) is because the default files and folders in the default configuration file points to directories owned by root (the /var directory). A less common, but perhaps more sensible, approach is to make MPD work with files and directories owned by a normal user. Running MPD as a normal user has several advantages: <br />
# You can easily have a single directory ~/.mpd (or any other directory under /home/username) for all MPD configuration files<br />
# No read/write permission errors<br />
# More flexible calls to MPD by using {{Filename|~/.xinitrc}} instead of including 'mpd' in the {{Filename|/etc/rc.conf}} DAEMONS array.<br />
<br />
The following steps shows how to run MPD as a normal user. '''Note''': this approach will not work if you want multiple users to have access to MPD.<br />
<br />
* Copy the contents of the default MPD configuration file in {{Filename|/usr/share/mpd/mpd.conf.example}} to your home directory. A good place would be {{Filename|"/home/user/.mpd/mpd.conf"}}.<br />
* Follow the 'old setup instructions' from above, ignoring the first part about copying the config to {{Filename|/etc/mpd.conf}} and do not set a user variable. <br />
* Create all of the requisite files in {{filename|"/home/user/.mpd/"}}:<br />
"~/.mpd/playlists/"<br />
"~/.mpd/db"<br />
"~/.mpd/mpd.db"<br />
"~/.mpd/mpd.log"<br />
"~/.mpd/mpd.error"<br />
"~/.mpd/mpd.pid"<br />
"~/.mpd/mpdstate"<br />
<br />
* Let MPD start on bootup by calling it from your {{Filename|~/.xinitrc}} as follows:<br />
# this starts mpd as normal user<br />
mpd ~/.mpd/mpd.conf<br />
{{Note| that you don't have to put a "&" at the end of the line here, since MPD will automatically daemonize itself.}}<br />
<br />
Lastly, delete the entry 'mpd' from your DAEMONS array in {{Filename|/etc/rc.conf}}, as you are not running it as root anymore.<br />
<br />
===Quick setup===<br />
<br />
The fastest way to do set up the structure is to do this:<br />
<br />
$ mkdir -p ~/.mpd/playlists && touch ~/.mpd/database && cp /usr/share/doc/mpd/mpdconf.example ~/.mpd/mpd.conf<br />
<br />
Then edit mpd.conf to your liking, in a manner similar to [[Music_Player_Daemon#Edit_mpd.conf]]. Beware that you must uncomment the db_file entry if you do edit mpd.conf.<br />
<br />
Then, to run it:<br />
<br />
$ mpd ~/.mpd/mpd.conf<br />
<br />
<br />
===Even quicker setup===<br />
I created a little script that will only ask for the location of your music and then creates the needed files and folders for you.<br />
You can find the script here:<br />
[http://karif.server-speed.net/~carnager/mpdsetup.tar]<br />
extract it<br />
$ tar xf mpdsetup.tar<br />
and run it<br />
$ ./mpdsetup.sh<br />
<br />
If you want to use this config in daemon mode, open it (~/.mpdconf) in an editor and find the "user" line. remove the comment (#) and fill in your own user name. Then copy the file to /etc/mpd.conf. If running mpd as user is fine for you, make sure to remove "mpd" from the daemons list in /etc/rc.conf<br />
<br />
===Multi-mpd setup===<br />
'''Useful if you want to run for example an icecast server.'''<br />
If you want a second MPD daemon (e.g., with icecast output to share music over the network) to use the same music and playlist as the one above, simply copy the above configuration file and make a new file (e.g., {{Filename|/home/username/.mpd/config-icecast}}), and only change the log_file, error_file, pid_file, and state_file parameters (e.g., {{Filename|mpd-icecast.log}}, {{Filename|mpd-icecast.error}}, and so on); using the same directory paths for the music and playlist directories would ensure that this second mpd daemon would use the same music collection as your first one (e.g., creating and editing a playlist under the first daemon would affect the second daemon as well, so that you don't have to create the same playlists all over again for the second daemon). Then, call this second daemon the same way from your {{Filename|~/.xinitrc}} above. (Just be sure to have a different port number, so as to not conflict with your first mpd daemon).<br />
<br />
==Clients==<br />
Install a client program for MPD. Popular options are:<br />
<br />
===Console===<br />
* '''mpc''' &ndash; Command Line Client (you'll probably want this one no matter what)<br />
# pacman -S mpc<br />
* [http://mpd.wikia.com/wiki/Client:Ncmpc/ ncmpc] &ndash; NCurses Client (this one is very handy for running in a console)<br />
# pacman -S ncmpc<br />
* [http://unkart.ovh.org/ncmpcpp/ ncmpcpp] &ndash; Clone of ncmpc with some new features written in C++<br />
# pacman -S ncmpcpp<br />
* [http://pms.sourceforge.net/ pms] &ndash; NCurses Client (highly configurable and accessible)<br />
Install [http://aur.archlinux.org/packages.php?ID=24378 pmus] from the [[AUR]].<br />
<br />
===Graphical===<br />
* [http://ario-player.sourceforge.net ario] &ndash; GTK+ Client with a Rhythmbox like library browser<br />
# pacman -S ario<br />
* [http://gmpcwiki.sarine.nl/index.php?title=GMPC gmpc] &ndash; GNOME Client<br />
# pacman -S gmpc<br />
* [http://bitcheese.net/wiki/QMPDClient QMPDClient] &ndash; Client written with Qt 4.x.<br />
# pacman -S qmpdclient<br />
* [http://sonata.berlios.de/ sonata] &ndash; Python GTK+ Client<br />
# pacman -S sonata<br />
* [http://aur.archlinux.org/packages.php?ID=33380 dmpc] &ndash; Dmenu-based MPC client with a playlist manager and state-saving on playlist changes<br />
Install [http://aur.archlinux.org/packages.php?ID=33380 dmpc] from the [[AUR]].<br />
<br />
See a long list of clients at the [http://mpd.wikia.com/wiki/Clients mpd wiki].<br />
<br />
==Extra stuff==<br />
===Last.fm scrobbling===<br />
To scrobble your songs to [http://www.last.fm Last.fm] using MPD there are several alternatives.<br />
<br />
====mpdscribble====<br />
mpdscribble is another daemon, available in the "community" repository (if you prefer, the "git" version is available in the [http://aur.archlinux.org/packages.php?ID=22274 AUR]). This is arguably the best alternative, because it's the semi-official MPD scrobbler and uses the new "idle" feature in MPD for more accurate scrobbling. Also, you don't need root access to configure it, because it doesn't need any changes to <tt>/etc</tt> at all. Visit [http://mpd.wikia.com/wiki/Client:Mpdscribble the official website] for more information.<br />
<br />
After you have installed mpdscribble, do the following (not as root):<br />
<br />
* {{Codeline|$ mkdir ~/.mpdscribble}}<br />
* Create the file {{Filename|~/.mpdscribble/mpdscribble.conf}} and add the following:<br />
<pre><br />
[mpdscribble] <br />
host = <your mpd host> # optional, defaults to $MPD_HOST or localhost<br />
port = <your mpd port> # optional, defaults to $MPD_PORT or 6600<br />
log = /home/<YOUR_USERNAME>/.mpdscribble/mpdscribble.log<br />
verbose = 2<br />
sleep = 1<br />
musicdir = <your music directory><br />
proxy = <your proxy> # optional, e. g. http://your.proxy:8080, defaults to none<br />
<br />
[last.fm]<br />
# last.fm section, comment if you don't use last.fm<br />
url = http://post.audioscrobbler.com/<br />
username = <your last.fm username><br />
password = <your last.fm password> # md5sum also possible: echo -n 'PASSWORD' | md5sum | cut -f 1 -d " "<br />
journal = /home/<YOUR_USERNAME>/.mpdscribble/lastfm.journal<br />
<br />
[libre.fm]<br />
# libre.fm section, comment if you don't use libre.fm<br />
url = http://turtle.libre.fm/<br />
username = <your libre.fm username><br />
password = <your libre.fm password> # md5sum also possible: echo -n 'PASSWORD' | md5sum | cut -f 1 -d " "<br />
journal = /home/<YOUR_USERNAME>/.mpdscribble/librefm.journal<br />
</pre><br />
* Add {{Codeline|mpdscribble}} to your {{Filename|~/.xinitrc}}:<br />
pidof mpdscribble >& /dev/null<br />
if [ $? -ne 0 ]; then<br />
mpdscribble &<br />
fi<br />
<br />
====Sonata & Ario====<br />
The easiest way, if you don't care about having to have a program window open all the time, is using Sonata or Ario which are graphical frontends to MPD. They have built-in support for Last.fm scrobbling in their preferences. A downside of this is that Sonata doesn't cache your songs if for some reason you don't happen to have an Internet connection at the time of playing.<br />
<br />
====lastfmsubmitd====<br />
lastfmsubmitd is a daemon which is available in the "community" repository. To install it, first edit {{Filename|/etc/lastfmsubmitd.conf}} and add both {{Codeline|lastfmsubmitd}} and {{Codeline|lastmp}} to the {{Codeline|DAEMONS}} array in {{Filename|/etc/rc.conf}}.<br />
<br />
====Last.fm playback====<br />
<br />
===Last.fm playback with lastfmproxy===<br />
lastfmproxy is a python script that streams a last.fm music stream to another media player. To setup, install [http://aur.archlinux.org/packages.php?ID=14214 lastfmproxy] from the [[AUR]] and then edit {{Filename|/usr/share/lastfmproxy/config.py}}. If you plan to only stream to MPD on the same host, just edit the login info.<br />
<br />
{{Note | Since it installs to a read only directory but it requires read/write access for features like saving previously listened to stations, it would be wise to copy {{Filename|/usr/share/lastfmproxy}} to your home directory.}}<br />
<br />
Start lastfmproxy with {{Codeline|lastfmproxy}} and visit http://localhost:1881/ in your web browser. To add a last.fm station navigate to http://localhost:1881/ followed by the lastfm:// url. Example: http://localhost:1881/lastfm://globaltags/punk . Navigate back to http://localhost:1881/ and download the m3u file by selecting the ''Start Listening'' link. Simply add it to your music library path.<br />
<br />
==Native Last.fm playback==<br />
Since 0.16 mpd has a very well working method to play back last.fm streams.<br />
{{File|name=/etc/mpd.conf|content=<br />
$ playlist_plugin {<br />
name "lastfm"<br />
user "my_username"<br />
password "my_password"<br />
}<br />
}}<br />
Then use e.g. mpc to load streams<br />
$ mpc load "lastfm://artist/Beatles"<br />
<br />
===Never play on start===<br />
<br />
This feature has recently been added to mpd git by Martin Kellerman, see commits b57330cf75bcb339e3f268f1019c63e40d305145 and 2fb40fe728ac07574808c40034fc0f3d2254d49d.<br />
<br />
====[https://aur.archlinux.org/packages.php?ID=19676 mpd-git] Method====<br />
This is the best method currently available, but is only currently (April 2011) enabled in the git version. Install [https://aur.archlinux.org/packages.php?ID=19676 mpd-git] from the [[AUR]], then add {{Codeline|restore_paused "yes"}} to your {{Filename|mpd.conf}} file.<br />
<br />
If you have issues with connecting your client to [https://aur.archlinux.org/packages.php?ID=19676 mpd-git], see [[Music Player Daemon#Other issues when attempting to connect to mpd with a client]].<br />
<br />
====Method 1====<br />
If you don't want MPD to always play on your system start, but yet you want to preserve the other state information, add the following lines to your {{Filename|/etc/rc.d/mpd}} file:<br />
'' ...''<br />
'' stat_busy "Starting Music Player Daemon"''<br />
<br />
# always start in paused state<br />
awk '/^state_file[ \t]+"[^"]+"$/ {<br />
match($0, "\".+\"")<br />
sfile = substr($0, RSTART + 1, RLENGTH - 2)<br />
} /^user[ \t]+"[^"]+"$/ {<br />
match($0, "\".+\"")<br />
user = substr($0, RSTART + 1, RLENGTH - 2)<br />
} END {<br />
if (sfile == "")<br />
exit;<br />
if (user != "")<br />
sub(/^~/, "/home/" user, sfile)<br />
system("sed -i \x27s|^\\(state:[ \\t]\\{1,\\}\\)play$|\\1pause|\x27 \x27" sfile "\x27")<br />
}' /etc/mpd.conf<br />
<br />
'' /usr/bin/mpd /etc/mpd.conf &> /dev/null''<br />
'' ...''<br />
<br />
This will change the player status to "paused", if it was stopped while playing. Next, you want this file to be preserved, so MPD updates won't erase this edit. Add (or edit) this line to your {{Filename|/etc/pacman.conf}}:<br />
NoUpgrade = etc/rc.d/mpd<br />
<br />
====Method 2====<br />
<br />
Another simpler method, would be to add mpd to your {{Filename|[[rc.conf]]}} deamons array and add {{Codeline|mpc stop}} or {{Codeline|mpc pause}} to {{Filename|/etc/rc.local.shutdown}} and to {{Filename|/etc/rc.local}}. (Remember you must have mpc installed to use this method).<br />
<br />
Adding only the order in {{Filename|/etc/rc.local}} cannot assure that mpd will play absolutely nothing, since there may be a delay before the stop command is executed. <br />
On the other hand, if you only add the order to {{Filename|/etc/rc.local.shutdown}}, that will assure that mpd won't play at all, as long as you properly shutdown your system.<br />
Even though they are redundant, adding it to {{Filename|/etc/rc.local}} would serve as a safety for those, presumably, rare occasions when you do not shutdown the system properly.<br />
<br />
====Method 3====<br />
<br />
The general idea between this method is to ask mdp to pause music when user logs out so that during next restart, mdp will stick to that "pause" state. Sending such command can be achieve using [http://www.archlinux.org/packages/extra/x86_64/mpc/ mpc], the command line interface to MPD:<br />
pacman -S mpc<br />
<br />
GDM users can then add the next line to /etc/gdm/PostSession/Default (be sure to add it before "exit 0"):<br />
/usr/bin/mpc pause<br />
<br />
Non-GDM users can use their own login manager's method to launch the line at logout.<br />
<br />
===MPD & ALSA===<br />
Sometimes, when you use other audio output, e.g: some web pages containing Flash applets, MPD cannot reproduce anything anymore (until you restart). The error looks something like: (if you search the file {{Filename|/var/log/mpd/mpd.error}})<br />
<br />
Error opening alsa device "hw:0,0": Device or resource busy<br />
<br />
And here is the solution (dmix saving our life again). Apply these lines in your {{Filename|/etc/mpd.conf}}:<br />
<br />
<pre><br />
audio_output {<br />
type "alsa"<br />
name "Sound Card"<br />
options "dev=dmixer"<br />
device "plug:dmix"<br />
}<br />
</pre><br />
<br />
And then restart with {{Codeline|/etc/rc.d/mpd restart}}.<br />
<br />
Searching on Internet I found the reason for why that happens in Gentoo's wiki:<br />
* The sound card does not support hardware mixing (uses '''dmix''' plugin)<br />
* An application does not work with ALSA with it's default settings<br />
<br />
For a detailed description, it is recommended to take a look at [http://mpd.wikia.com/wiki/Alsa this] link. There you can find an example asound.conf which worked for me right out of the box.<br />
<br />
====High CPU usage with ALSA====<br />
When using MPD with ALSA, users may experience MPD taking up lots of CPU (around 20-30%). This is caused by most sound cards supporting 48kHz and most music being 44kHz, thus forcing MPD to resample it. This operation takes lots of CPU cycles and results into high usage.<br />
<br />
For most users the problem should be solved by telling MPD not to use resampling by adding {{Codeline|auto_resample "no"}} into audio_output-part of {{Filename|/etc/mpd.conf}}. This will degrade quality slightly, however.<br />
<br />
Example from {{Filename|mpd.conf}}:<br />
<br />
audio_output {<br />
type "alsa"<br />
name "My ALSA Device"<br />
auto_resample "no"<br />
}<br />
<br />
Although it may not give as drastic a speedup, enabling mmap may speed things up:<br />
<br />
audio_output {<br />
type "alsa"<br />
name "My ALSA Device"<br />
use_mmap "yes"<br />
}<br />
<br />
Some users might also want to tell dmix to use 44kHz as well. More info about tuning performance of your MPD can be found from: [http://mpd.wikia.com/wiki/Tuning MPD wiki]<br />
<br />
====Example configuration: Output with 44.1 KHz at e. g. 16 bit depth, multiple programs at once====<br />
<br />
''Why these formats?'' Because they are standard CDA, because ALSA on its own allows more than one program "to sound" only with dmix — whose resampling algorithm is inferior — and because dmix by default resamples anything lower to 48 KHz (or whatever higher format is playing at the time). Also, some get clicking sounds if at least {{Filename|mpd.conf}} is not changed this way.<br />
<br />
''What's the downside?'' These settings cause ''everything'' (if necessary) to be resampled to this format, such as material from DVD or TV which usually is at 48 KHz. But there is no known way to have ALSA dynamically change the format, and particularly if you listen to far more CDs than anything else the occasional 48 → 44.1 isn't too great a loss.<br />
<br />
The following assumes that there are not already other settings which conflict resp. overwrite it. This applies especially to the current user's potential {{Filename|~/.asoundrc}} — which MPD as its own user ignores, therefore the following should go to {{Filename|/etc/asound.conf}}:<br />
<br />
{{File|name=/etc/asound.conf|content=<br />
defaults.pcm.dmix.rate 44100 # Force 44.1 KHz<br />
defaults.pcm.dmix.format S16_LE # Force 16 bits<br />
}}<br />
<br />
{{File|name=/etc/mpd.conf|content=<br />
audio_output {<br />
type "alsa" # Use the ALSA output plugin.<br />
name "HDA Intel" # Can be called anything or nothing tmk, but must be present.<br />
options "dev=dmixer"<br />
device "plug:dmix" # Both lines cause MPD to output to dmix.<br />
format "44100:16:2" # the actual format<br />
auto_resample "no" # This bypasses ALSA's own algorithms, which generally are inferior. See below how to choose a different one.<br />
use_mmap "yes" # Minor speed improvement, should work with all modern cards.<br />
}<br />
<br />
samplerate_converter "0" # MPD's best, most CPU intensive algorithm. See 'man mpd.conf' for others — for anything other than the poorest "internal", libsamplerate must be installed.<br />
}}<br />
<br />
{{Note|MPD gives the mp3 format a special treatment at decoding: It's always outputted as 24 bit. (The conversion as forced by the ''format'' line only comes after that.)}}<br />
<br />
If one wants to leave the bit depth decision to ALSA resp. MPD, comment out resp. omit the ''dmix.format'' line and change the one for mpd with ''format'' to "44100:*:2".<br />
<br />
{{Note|''Crossfading'' between files decoded at two different bit depths (say, one mp3 and one 16 bit flac) does not work unless conversion is active.}}<br />
<br />
===Control MPD with lirc===<br />
There are already some clients designed for communications between lircd and MPD, however, as far as the practical use, they aren't very useful since their functions are limited.<br />
<br />
It's recommended to use mpc with irexec. mpc is a command line player which only sends the command to MPD and exits immediately, which is perfect for irexec, the command runner included in lirc. What irexec does is that it runs a specified command once received a remote control button.<br />
<br />
First of all, please setup your remotes as referred to the '''[[Lirc]]''' article.<br />
<br />
Edit your favored lirc startup configuration file, default location is {{Filename|~/.lircrc}}.<br />
<br />
Fill the file with the following pattern:<br />
begin<br />
prog = irexec<br />
button = <button_name><br />
config = <command_to_run><br />
repeat = <0 or 1><br />
end<br />
<br />
An useful example:<br />
## irexec<br />
begin<br />
prog = irexec<br />
button = play_pause<br />
config = mpc toggle<br />
repeat = 0<br />
end<br />
<br />
begin<br />
prog = irexec<br />
button = stop<br />
config = mpc stop<br />
repeat = 0<br />
end<br />
begin<br />
prog = irexec<br />
button = previous<br />
config = mpc prev<br />
repeat = 0<br />
end<br />
begin<br />
prog = irexec<br />
button = next<br />
config = mpc next<br />
repeat = 0<br />
end<br />
begin<br />
prog = irexec<br />
button = volup<br />
config = mpc volume +2<br />
repeat = 1<br />
end<br />
begin<br />
prog = irexec<br />
button = voldown<br />
config = mpc volume -2<br />
repeat = 1<br />
end<br />
begin<br />
prog = irexec<br />
button = pbc<br />
config = mpc random<br />
repeat = 0<br />
end<br />
begin<br />
prog = irexec<br />
button = pdvd<br />
config = mpc update<br />
repeat = 0<br />
end<br />
begin<br />
prog = irexec<br />
button = right<br />
config = mpc seek +00:00:05<br />
repeat = 0<br />
end<br />
begin<br />
prog = irexec<br />
button = left<br />
config = mpc seek -00:00:05<br />
repeat = 0<br />
end<br />
begin<br />
prog = irexec<br />
button = up<br />
config = mpc seek +1%<br />
repeat = 0<br />
end<br />
begin<br />
prog = irexec<br />
button = down<br />
config = mpc seek -1%<br />
repeat = 0<br />
end<br />
<br />
There are more functions for mpc, run {{Codeline|man mpc}} for more info.<br />
<br />
===Control MPD with bluetooth phone===<br />
You can also control MPD (to a certain extent) using a bluetooth enabled phone. You need to do the following:<br />
<br />
* install [http://remuco.sourceforge.net/index.php/Remuco remuco] -- a wireless remote control for several Linux media players ([http://aur.archlinux.org/packages.php?ID=25072 aur])<br />
* transfer remuco client -- jar/jad files from {{Filename|/usr/share/remuco/client/}} to your phone and install it<br />
* run {{Codeline|remuco-mpd}} (as current user)<br />
* run remuco on your phone, define a new bluetooth remuco connection (pair first if you haven't done this previously) and explore its capabilities<br />
<br />
More information about remuco including troubleshooting to be found at its [http://remuco.sourceforge.net/index.php/Remuco homepage]<br />
<br />
===MPD & PulseAudio===<br />
<br />
Edit {{Filename|/etc/mpd.conf}}, and uncomment the audio_output section for the type "pulse". The server and sink lines of it should be commented unless you know what you're doing.<br />
<br />
Then, add the mpd user (and yours if you haven't done so already) to the necessary pulse groups. The pulse-access group should be sufficient but you may want to add pulse-rt as well. The group "pulse" doesn't appear to be necessary.<br />
# gpasswd -a mpd pulse-access<br />
# gpasswd -a mpd pulse-rt<br />
<br />
Lastly, you may or may not need to copy {{Filename|~/.pulse-cookie}} from your current (pulse working) user's dir to your mpd user's home directory. It is likely to be {{Filename|/var/lib/mpd}} if you followed the first part of this wiki. This would probably only allow your current user to listen in on MPD's pulse. You may consider running pulse system-wide if that's insufficient.<br />
<br />
===Cue Files===<br />
<br />
To make cue file support actually work, you have to work around a nasty libcue bug. Libcue copied some files directly from libcdio, making it conflict with it. Steps to do to get proper cue support:<br />
<br />
* remove libcdio temporary (pacman -Rdd libcdio)<br />
* install libcue (pacman -S libcue)<br />
* install mpd with abs or from aur.<br />
* reinstall libcdio (pacman -S libcdio)<br />
<br />
At the point of writing mpd does not parse tracknumbers from cue sheets. There is a patch available (http://musicpd.org/mantis/view.php?id=3230)<br />
Once this patch is merged into mpd, i will remove this line :)<br />
<br />
==Troubleshooting==<br />
===Autodetection failed===<br />
During the start of MPD, it tries to autodetect your set-up and configure output and volume control accordingly. Though this mostly goes well, it will fail for some systems. It may help to tell MPD specifically what to use as output and mixer control. If you copied {{Filename|/etc/mpd.conf}} over from {{Filename|/etc/mpd.conf.example}} as mentioned above, you can simply uncomment:<br />
<br />
Example for alsa output type and alsa mixer:<br />
audio_output {<br />
type "alsa"<br />
name "My ALSA Device"<br />
device "hw:0,0" # optional<br />
format "44100:16:2" # optional<br />
mixer_type "hardware"<br />
mixer_device "default"<br />
mixer_control "PCM"<br />
}<br />
<br />
'''Note:''' in case of permission problems when using ESD with MPD run this as root:<br />
# chsh -s /bin/true mpd<br />
<br />
===Executable permissions===<br />
{{Warning|This is not good security practice and may be unnecessary.}}<br />
<br />
MPD needs to have +x permissions on '''ALL''' parent directories to your music collection (ie. if it's located outside of "mpd" home directory /var/lib/mpd). By default useradd sets permissions on home dir to 1700 drwx------. So if you're like me you will need to change permissions of /home/user. Example... my music collection is located /home/user/music. <br />
# chmod a+x /home/$USER<br />
# chmod -R a+X /home/$USER/music<br />
<br />
====Alternative solution====<br />
An alternative solution would be to use your group to share a selection of files, among them your music library. First remove all permissions for the group then add group permissions to read and execute home and music.<br />
# chmod -R g-rwx /home/$USER<br />
# chmod g+rx /home/$USER<br />
# chmod -R g+rX /home/$USER/music<br />
<br />
====Another alternative solution====<br />
Another alternative is to remount the music directory under a directory that mpd has access to. This does not entail the same security risks as modifying the permissions on one's home directory.<br />
# mkdir /var/lib/mpd/music<br />
# echo "/home/$USER/music /var/lib/mpd/music none bind" >> /etc/fstab<br />
# mount -a<br />
# /etc/rc.d/mpd restart<br />
And that should fix the problem. See also [https://bbs.archlinux.org/viewtopic.php?id=86449 the forum thread.]<br />
<br />
===Avoiding timeouts===<br />
To get rid of timeouts (i.e. when you paused music for long time) in gpmc and other clients uncomment and increase {{Codeline|connection_timeout}} option in {{Filename|mpd.conf}}.<br />
<br />
If files and/or titles are shown in wrong encoding, uncomment and change {{Codeline|filesystem_charset}} and {{Codeline|id3v1_encoding}} options.<br />
Note that you cannot set encoding for ID3 v2 tags. To workaround this you may use [http://mpd.wikia.com/wiki/GenericDecoder#Generic_Tagreader external tag readers].<br />
<br />
If you want to use another computer to control MPD over a network, the {{Codeline|bind_to_address}} option in {{Filename|mpd.conf}} will need to be set to either your IP address, or {{Codeline|any}} if your IP address changes frequently. <br />
<br />
'''Streaming'''<br><br />
With the latest version of MPD (0.15), built-in httpd streaming is now available.<br />
<br />
To activate this feature, you'll just need to add a new output of type httpd in {{Filename|mpd.conf}}:<br />
audio_output {<br />
type "httpd"<br />
name "What you want"<br />
encoder "lame" # vorbis or lame supported<br />
port "8000"<br />
bitrate "128"<br />
format "44100:16:2" # change 2 to 1 for mono<br />
}<br />
<br />
Restart the mpd deamon and, from another computer, simply load the stream as any other url. <br />
$ mplayer http://<server's IP>:8000<br />
<br />
{{Note | You must open the port on your router / firewall for the stream to be connectible to from another computer.}}<br />
<br />
Most players (i.e. vlc or xmms2) should also be able to load the stream via their "add url..." menu option.<br />
<br />
This is a nice clean way to replace your current icecast setup with something natively supported within MPD.<br />
<br />
===mpd hangs on first startup===<br />
This is a common error that's caused by corrupt mp3 tags.<br />
Here is an experimental way to solve this issue.<br />
Requirements:<br />
* kid3<br />
* easytag<br />
<br />
This method is very tedious, especially with a huge database. Just as a baseline it took 2.5h to fix a 16Gb DB.<br />
<br />
====Easy Tag====<br />
The purpose of easytag here is that easytag detects the error in the tags, but like MPD it hangs and dies. The trick here is that easy tags actually tells you what file is causing the problem on the status bar.<br />
Before starting easytag make sure to have a terminal close to be ready to kill easy tag to avoid a hang. Once you are ready, on the tree view select the directory where all your music is located. By default easytag starts to search all subdirectories for mp3 files. Once you notice that easytag stopped scanning for songs, make note of the culprit and kill easytag.<br />
<br />
====KID3====<br />
Here's where kid3 comes in handy. With kid3 go to the offending song and rewrite one of the tags. then save the file. This should force kid3 to rewrite the whole tag again fixing the problem with MPD and easy tag hanging.<br />
<br />
Repeat this procedure until your music library is done.<br />
<br />
===Cannot connect to mpd: host "localhost" not found: Temporary failure in name resolution===<br />
Cannot connect to MPD (with ncmpcpp), if you are disconnected from network. Solution is [[IPv6 - Disabling the Module|disable IPv6]] or add line to /etc/hosts<br />
::1 localhost.localdomain localhost<br />
<br />
===Other issues when attempting to connect to mpd with a client===<br />
Some have reported being unable to access mpd with various clients, for example seeing errors like these:<br />
$ ncmpcpp<br />
Cannot connect to mpd: Connection closed by the server<br />
$ sonata<br />
2011-02-13 18:33:05 Connection lost while reading MPD hello<br />
2011-02-13 18:33:05 Not connected<br />
2011-02-13 18:33:05 Not connected<br />
<br />
Please see posts on ncmpcpp on the Arch Forums [https://bbs.archlinux.org/viewtopic.php?id=109962 HERE] and [https://bbs.archlinux.org/viewtopic.php?id=113493 HERE]. Also see the Arch bug report on this issue [https://bugs.archlinux.org/task/22071 HERE]. <br />
<br />
====First fix====<br />
Check {{Filename|mpd.conf}} for a line like {{Codeline|mpd.error}} and remove it. The mpd error file is deprecated and has been removed.<br />
<br />
====Second fix====<br />
{{Note|I'm not so sure this is a good idea. There is a warning about changing the address to bind to in the default mpd.conf. If this does not help, you might want to comment out the changes.}}<br />
If that doesn't help, add the following to {{Filename|mpd.conf}}:<br />
<pre><br />
bind_to_address "127.0.0.1"<br />
port "6600"<br />
</pre><br />
<br />
Afterwards, instruct your client to connect via 127.0.0.1. For example, add the following to the ncmpcpp config file:<br />
<pre><br />
mpd_host "127.0.0.1"<br />
mpd_port "6600"<br />
</pre><br />
<br />
<br />
===Port 6600 already in use===<br />
MPD needs to bind to port 6600 and cannot start if it's already in use. The most common reason for this is that the user has started MPD once and then subsequently tried to start mpd again. In general, nothing should be done here.<br />
<br />
If port 6600 is tied up for some other reason, one can use the following command to find the offending process:<br />
# netstat -tulpan | grep 6600<br />
<br />
This will list IP:Port and the process name holding the connection (root privileges are required to see all processes).<br />
<br />
If you need to restart mpd for whatever reason, use:<br />
<pre><br />
$ mpd --kill<br />
$ mpd <br />
</pre><br />
A more brute-force approach:<br />
<pre><br />
$ killall mpd<br />
$ mpd <br />
</pre><br />
{{Note| If you typically run MPD as root, you will need to run the above commands as root.}}<br />
<br />
In the latest version of MPD, --create-db is completely deprecated. The database will be created automagically on first run and can subsequently be updated via your client (i.e. mpc update). You can now use inotify support to automatically update your music database. Add the following to {{File|name=mpd.conf|content=auto_update "yes"}} to enable it.<br />
<br />
===Binding to IPV6 before IPV4===<br />
If on startup, you see this message:<br />
listen: bind to '0.0.0.0:6600' failed: Address already in use (continuing anyway, because binding to '[::]:6600' succeeded)<br />
MPD is attempting to bind to the ipv6 interface before binding to ipv4. If you want to use your ipv4 interface, hardcode it in mpd.conf, like so:<br />
bind_to_address "127.0.0.1"<br />
Or, you could specify several binds, for example, to have MPD listen on localhost and the external IP of your network card:<br />
bind_to_address "127.0.0.1"<br />
bind_to_address "192.168.1.13"<br />
<br />
===Crackling sound with some audio files===<br />
This is usually a playback speed problem and can be fixed by uncommenting the audio_output_format line in:<br />
<br />
{{File|name=/etc/mpd.conf|content=<br />
audio_output_format "44100:16:2"}}<br />
<br />
This is usually a sane value for most mp3 files.<br />
<br />
===daemon: cannot setgid for user "mpd": Operation not permitted ===<br />
<br />
The error is stating that the user starting the process (you) does not have permissions to become another user (mpd) which the configuration has told that process to run as.<br />
<br />
To solve the issue, simply start mpd as root.<br />
su -c "/etc/rc.d/mpd start"<br />
or<br />
sudo /etc/rc.d/mpd start<br />
<br />
==External links==<br />
* [http://www.musicpd.org/ Official Web Site]<br />
* [http://mpd.wikia.com/wiki/Main_Page Official Wiki]<br />
* [http://mpd.wikia.com/wiki/Clients Sorted List of MPD Clients]<br />
* [http://www.musicpd.org/forum/ MPD forum]</div>Rasihttps://wiki.archlinux.org/index.php?title=Music_Player_Daemon&diff=150767Music Player Daemon2011-08-06T01:10:49Z<p>Rasi: /* Last.fm playback */</p>
<hr />
<div>[[fr:MPD]]<br />
[[Category:Audio/Video (English)]]<br />
[[Category:Daemons and system services (English)]]<br />
{{i18n|Music Player Daemon}}<br />
[[pl:Music Player Daemon]]<br />
<br />
'''MPD''' (music player daemon) is an audio player that has a server-client architecture. MPD runs in the background as a daemon, manages playlists and a music database, and uses very few resources. In order to interface with it, you need a separate client. More information can be found on their [http://www.musicpd.org/ website].<br />
<br />
''Please'' have a look at the official page for setup and troubleshooting instructions, the main developer called our wiki page in its current state ''"full of symptom killers"'', hence the official pages should contain better instructions.<br />
<br />
==Installing mpd==<br />
Install with [[pacman]]:<br />
# pacman -S mpd<br />
<br />
==Daemon Setup: Starting at Boot==<br />
General information about MPD configuration may be found at http://mpd.wikia.com/wiki/Configuration.<br />
<br />
===Sound setup===<br />
To make audio output actually work ensure that you have setup audio card and mixer correctly. See [[ALSA]], and [[PulseAudio]] if you are using Gnome 3. Do not forget to unmute the required channels in alsamixer, raise the volume and save changes with alsactl store. Run mpd with {{Filename|/usr/bin/mpd --stdout --no-daemon --verbose}} if that still doesn't work.<br />
<br />
Make sure your card can do hardware mixing (most of them can, including onboard audio). Or else this could cause problems with multiple sound playback. For example, this can prevent Mplayer from playing back sound while the mpd daemon is running, returning an audio error message stating the device is busy.<br />
<br />
===Timeline of MPD's behavior on a typical working setup when started as a daemon===<br />
# MPD is started on boot by {{Filename|/etc/rc.conf}}, by including it in the {{Codeline|DAEMONS}} array. (Or, this can be done manually each session by running {{Codeline|/etc/rc.d/mpd start}} with root privileges).<br />
# Since MPD is now started as root, it first reads the {{Filename|/etc/mpd.conf}} file.<br />
# MPD reads the user variable in the {{Filename|/etc/mpd.conf}} file, and changes from root to this user.<br />
# MPD then reads the contents of the {{Filename|/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 {{Filename|/etc/mpd.conf}} file. This way, uses of {{Codeline|~}} in the configuration file point correctly to the home user's directory, and not root's directory. It may be worthwhile to change all uses of {{Codeline|~}} to {{Codeline|/home/username}} to avoid any confusion over this aspect of MPD's behavior.<br />
<br />
===A clean configuration file===<br />
* As root, check if {{Filename|/etc/mpd.conf}} exists and delete the file if it does. This is safe.<br />
<br />
MPD comes with an example configuration file, available at {{Filename|/usr/share/mpd/mpd.conf.example}}. This file holds an abundance of information on MPD configuration, and holds default mixer values you can simply uncomment.<br />
<br />
* As root, copy this example file to {{Filename|/etc/mpd.conf}}.<br />
# cp /usr/share/mpd/mpd.conf.example /etc/mpd.conf<br />
({{Filename|/usr/share/mpd/mpd.conf.example}} is good for userspace setup)<br />
<br />
Since MPD is being set up to run as a daemon at boot, never put this file in the user's directory like some tutorials suggest, since it will not be read. Moreover, if you previously created a {{Filename|.mpdconf}} file in your home, remove it now (to set up MPD to run with user privileges alone, pleaser refer to the section [[Music_Player_Daemon#Alternative_Setup:_Starting_as_a_User | Alternative_Setup:_Starting_as_a_User]]). This is important to prevent conflicts. The presence of the configuration file in {{Filename|/etc}}, like is the case here, is what will enable MPD to run as a daemon at boot. Otherwise, a script would be needed to run MPD ''after'' the user has logged (like kdm or {{Filename|~/.fluxbox/startup}}) or it would require a manual move each time. For a single music collection, the method used here is simply better, even while the collection is shared to multiple users. Also, don't be afraid about root privileges: even while MPD runs as a daemon, it never completely runs as root since it automatically drops its root privileges after execution.<br />
<br />
===Edit {{Filename|mpd.conf}}===<br />
<br />
The default arch install keeps the setup in /var and uses "mpd" as default user, instead of cluttering up ~/.<br />
Edit {{Filename|/etc/mpd.conf}} to reflect as such.<br />
<br />
{{File|name=/etc/mpd.conf|content=<br />
music_directory "/home/user/music" # Your music dir.<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 "/var/run/mpd/mpd.pid" # Omit this line for systemd<br />
state_file "/var/lib/mpd/mpdstate"<br />
user "mpd"<br />
# Binding to address and port causing problems in mpd-0.14.2 best to leave<br />
# commented.<br />
# bind_to_address "127.0.0.1"<br />
# port "6600"<br />
}}<br />
<br />
* If your music collection is contained under multiple directories, you can make symbolic links under /var/lib/mpd then set 'music_directory' to the directory holding the symbolic links. Remember to set permissions accordingly on the directories being linked.<br />
<br />
* To change the volume of audio from mpd independent of other programs, uncomment or add the switch in mpd.conf:<br />
<br />
{{File|name=/etc/mpd.conf|content=<br />
mixer_type "software"<br />
}}<br />
<br />
* Lastly, if you are running pulseaudio under Gnome 3, the default setting of "alsa" for the audio output will not work. Make the modification from:<br />
{{File|name=/etc/mpd.conf|content=<br />
audio_output {<br />
type "alsa"<br />
name "Sound Card"<br />
}<br />
}}<br />
<br />
to<br />
<br />
{{File|name=/etc/mpd.conf|content=<br />
audio_output {<br />
type "pulse"<br />
name "Sound Card"<br />
}<br />
}}<br />
<br />
===Create files===<br />
<br />
* As root, create the directories and files you specified in {{Filename|/etc/mpd.conf}}.<br />
# mkdir -p /var/lib/mpd/playlists /var/run/mpd<br />
# touch /var/lib/mpd/{mpd.db,mpdstate} && touch /var/run/mpd/mpd.pid<br />
<br />
* You then need to change the file's permissions so that the daemon can modify them.<br />
# chown -R mpd /var/lib/mpd /var/run/mpd<br />
<br />
===Create database===<br />
<br />
Creating the database is now accomplished via the update feature of the client, for example 'mpc update'. The previous method, creating the MPD database as root (# mpd --create-db), is deprecated.<br />
<br />
==Alternative Setup: Starting as a User==<br />
MPD need not be started with root permissions. The only reason why MPD needs to be started as root (by being called from {{Filename|/etc/rc.conf}}) is because the default files and folders in the default configuration file points to directories owned by root (the /var directory). A less common, but perhaps more sensible, approach is to make MPD work with files and directories owned by a normal user. Running MPD as a normal user has several advantages: <br />
# You can easily have a single directory ~/.mpd (or any other directory under /home/username) for all MPD configuration files<br />
# No read/write permission errors<br />
# More flexible calls to MPD by using {{Filename|~/.xinitrc}} instead of including 'mpd' in the {{Filename|/etc/rc.conf}} DAEMONS array.<br />
<br />
The following steps shows how to run MPD as a normal user. '''Note''': this approach will not work if you want multiple users to have access to MPD.<br />
<br />
* Copy the contents of the default MPD configuration file in {{Filename|/usr/share/mpd/mpd.conf.example}} to your home directory. A good place would be {{Filename|"/home/user/.mpd/mpd.conf"}}.<br />
* Follow the 'old setup instructions' from above, ignoring the first part about copying the config to {{Filename|/etc/mpd.conf}} and do not set a user variable. <br />
* Create all of the requisite files in {{filename|"/home/user/.mpd/"}}:<br />
"~/.mpd/playlists/"<br />
"~/.mpd/db"<br />
"~/.mpd/mpd.db"<br />
"~/.mpd/mpd.log"<br />
"~/.mpd/mpd.error"<br />
"~/.mpd/mpd.pid"<br />
"~/.mpd/mpdstate"<br />
<br />
* Let MPD start on bootup by calling it from your {{Filename|~/.xinitrc}} as follows:<br />
# this starts mpd as normal user<br />
mpd ~/.mpd/mpd.conf<br />
{{Note| that you don't have to put a "&" at the end of the line here, since MPD will automatically daemonize itself.}}<br />
<br />
Lastly, delete the entry 'mpd' from your DAEMONS array in {{Filename|/etc/rc.conf}}, as you are not running it as root anymore.<br />
<br />
===Quick setup===<br />
<br />
The fastest way to do set up the structure is to do this:<br />
<br />
$ mkdir -p ~/.mpd/playlists && touch ~/.mpd/database && cp /usr/share/doc/mpd/mpdconf.example ~/.mpd/mpd.conf<br />
<br />
Then edit mpd.conf to your liking, in a manner similar to [[Music_Player_Daemon#Edit_mpd.conf]]. Beware that you must uncomment the db_file entry if you do edit mpd.conf.<br />
<br />
Then, to run it:<br />
<br />
$ mpd ~/.mpd/mpd.conf<br />
<br />
<br />
===Even quicker setup===<br />
I created a little script that will only ask for the location of your music and then creates the needed files and folders for you.<br />
You can find the script here:<br />
[http://karif.server-speed.net/~carnager/mpdsetup.tar]<br />
extract it<br />
$ tar xf mpdsetup.tar<br />
and run it<br />
$ ./mpdsetup.sh<br />
<br />
If you want to use this config in daemon mode, open it (~/.mpdconf) in an editor and find the "user" line. remove the comment (#) and fill in your own user name. Then copy the file to /etc/mpd.conf. If running mpd as user is fine for you, make sure to remove "mpd" from the daemons list in /etc/rc.conf<br />
<br />
===Multi-mpd setup===<br />
'''Useful if you want to run for example an icecast server.'''<br />
If you want a second MPD daemon (e.g., with icecast output to share music over the network) to use the same music and playlist as the one above, simply copy the above configuration file and make a new file (e.g., {{Filename|/home/username/.mpd/config-icecast}}), and only change the log_file, error_file, pid_file, and state_file parameters (e.g., {{Filename|mpd-icecast.log}}, {{Filename|mpd-icecast.error}}, and so on); using the same directory paths for the music and playlist directories would ensure that this second mpd daemon would use the same music collection as your first one (e.g., creating and editing a playlist under the first daemon would affect the second daemon as well, so that you don't have to create the same playlists all over again for the second daemon). Then, call this second daemon the same way from your {{Filename|~/.xinitrc}} above. (Just be sure to have a different port number, so as to not conflict with your first mpd daemon).<br />
<br />
==Clients==<br />
Install a client program for MPD. Popular options are:<br />
<br />
===Console===<br />
* '''mpc''' &ndash; Command Line Client (you'll probably want this one no matter what)<br />
# pacman -S mpc<br />
* [http://mpd.wikia.com/wiki/Client:Ncmpc/ ncmpc] &ndash; NCurses Client (this one is very handy for running in a console)<br />
# pacman -S ncmpc<br />
* [http://unkart.ovh.org/ncmpcpp/ ncmpcpp] &ndash; Clone of ncmpc with some new features written in C++<br />
# pacman -S ncmpcpp<br />
* [http://pms.sourceforge.net/ pms] &ndash; NCurses Client (highly configurable and accessible)<br />
Install [http://aur.archlinux.org/packages.php?ID=24378 pmus] from the [[AUR]].<br />
<br />
===Graphical===<br />
* [http://ario-player.sourceforge.net ario] &ndash; GTK+ Client with a Rhythmbox like library browser<br />
# pacman -S ario<br />
* [http://gmpcwiki.sarine.nl/index.php?title=GMPC gmpc] &ndash; GNOME Client<br />
# pacman -S gmpc<br />
* [http://bitcheese.net/wiki/QMPDClient QMPDClient] &ndash; Client written with Qt 4.x.<br />
# pacman -S qmpdclient<br />
* [http://sonata.berlios.de/ sonata] &ndash; Python GTK+ Client<br />
# pacman -S sonata<br />
* [http://aur.archlinux.org/packages.php?ID=33380 dmpc] &ndash; Dmenu-based MPC client with a playlist manager and state-saving on playlist changes<br />
Install [http://aur.archlinux.org/packages.php?ID=33380 dmpc] from the [[AUR]].<br />
<br />
See a long list of clients at the [http://mpd.wikia.com/wiki/Clients mpd wiki].<br />
<br />
==Extra stuff==<br />
===Last.fm scrobbling===<br />
To scrobble your songs to [http://www.last.fm Last.fm] using MPD there are several alternatives.<br />
<br />
====mpdscribble====<br />
mpdscribble is another daemon, available in the "community" repository (if you prefer, the "git" version is available in the [http://aur.archlinux.org/packages.php?ID=22274 AUR]). This is arguably the best alternative, because it's the semi-official MPD scrobbler and uses the new "idle" feature in MPD for more accurate scrobbling. Also, you don't need root access to configure it, because it doesn't need any changes to <tt>/etc</tt> at all. Visit [http://mpd.wikia.com/wiki/Client:Mpdscribble the official website] for more information.<br />
<br />
After you have installed mpdscribble, do the following (not as root):<br />
<br />
* {{Codeline|$ mkdir ~/.mpdscribble}}<br />
* Create the file {{Filename|~/.mpdscribble/mpdscribble.conf}} and add the following:<br />
<pre><br />
[mpdscribble] <br />
host = <your mpd host> # optional, defaults to $MPD_HOST or localhost<br />
port = <your mpd port> # optional, defaults to $MPD_PORT or 6600<br />
log = /home/<YOUR_USERNAME>/.mpdscribble/mpdscribble.log<br />
verbose = 2<br />
sleep = 1<br />
musicdir = <your music directory><br />
proxy = <your proxy> # optional, e. g. http://your.proxy:8080, defaults to none<br />
<br />
[last.fm]<br />
# last.fm section, comment if you don't use last.fm<br />
url = http://post.audioscrobbler.com/<br />
username = <your last.fm username><br />
password = <your last.fm password> # md5sum also possible: echo -n 'PASSWORD' | md5sum | cut -f 1 -d " "<br />
journal = /home/<YOUR_USERNAME>/.mpdscribble/lastfm.journal<br />
<br />
[libre.fm]<br />
# libre.fm section, comment if you don't use libre.fm<br />
url = http://turtle.libre.fm/<br />
username = <your libre.fm username><br />
password = <your libre.fm password> # md5sum also possible: echo -n 'PASSWORD' | md5sum | cut -f 1 -d " "<br />
journal = /home/<YOUR_USERNAME>/.mpdscribble/librefm.journal<br />
</pre><br />
* Add {{Codeline|mpdscribble}} to your {{Filename|~/.xinitrc}}:<br />
pidof mpdscribble >& /dev/null<br />
if [ $? -ne 0 ]; then<br />
mpdscribble &<br />
fi<br />
<br />
====Sonata & Ario====<br />
The easiest way, if you don't care about having to have a program window open all the time, is using Sonata or Ario which are graphical frontends to MPD. They have built-in support for Last.fm scrobbling in their preferences. A downside of this is that Sonata doesn't cache your songs if for some reason you don't happen to have an Internet connection at the time of playing.<br />
<br />
====lastfmsubmitd====<br />
lastfmsubmitd is a daemon which is available in the "community" repository. To install it, first edit {{Filename|/etc/lastfmsubmitd.conf}} and add both {{Codeline|lastfmsubmitd}} and {{Codeline|lastmp}} to the {{Codeline|DAEMONS}} array in {{Filename|/etc/rc.conf}}.<br />
<br />
====Last.fm playback====<br />
<br />
==Last.fm playback with lastfmproxy==<br />
lastfmproxy is a python script that streams a last.fm music stream to another media player. To setup, install [http://aur.archlinux.org/packages.php?ID=14214 lastfmproxy] from the [[AUR]] and then edit {{Filename|/usr/share/lastfmproxy/config.py}}. If you plan to only stream to MPD on the same host, just edit the login info.<br />
<br />
{{Note | Since it installs to a read only directory but it requires read/write access for features like saving previously listened to stations, it would be wise to copy {{Filename|/usr/share/lastfmproxy}} to your home directory.}}<br />
<br />
Start lastfmproxy with {{Codeline|lastfmproxy}} and visit http://localhost:1881/ in your web browser. To add a last.fm station navigate to http://localhost:1881/ followed by the lastfm:// url. Example: http://localhost:1881/lastfm://globaltags/punk . Navigate back to http://localhost:1881/ and download the m3u file by selecting the ''Start Listening'' link. Simply add it to your music library path.<br />
<br />
==Native Last.fm playback==<br />
Since 0.16 mpd has a very well working method to play back last.fm streams.<br />
{{File|name=/etc/mpd.conf|content=<br />
$ playlist_plugin {<br />
name "lastfm"<br />
user "my_username"<br />
password "my_password"<br />
}<br />
}}<br />
Then use e.g. mpc to load streams<br />
$ mpc load "lastfm://artist/Beatles"<br />
<br />
===Never play on start===<br />
<br />
This feature has recently been added to mpd git by Martin Kellerman, see commits b57330cf75bcb339e3f268f1019c63e40d305145 and 2fb40fe728ac07574808c40034fc0f3d2254d49d.<br />
<br />
====[https://aur.archlinux.org/packages.php?ID=19676 mpd-git] Method====<br />
This is the best method currently available, but is only currently (April 2011) enabled in the git version. Install [https://aur.archlinux.org/packages.php?ID=19676 mpd-git] from the [[AUR]], then add {{Codeline|restore_paused "yes"}} to your {{Filename|mpd.conf}} file.<br />
<br />
If you have issues with connecting your client to [https://aur.archlinux.org/packages.php?ID=19676 mpd-git], see [[Music Player Daemon#Other issues when attempting to connect to mpd with a client]].<br />
<br />
====Method 1====<br />
If you don't want MPD to always play on your system start, but yet you want to preserve the other state information, add the following lines to your {{Filename|/etc/rc.d/mpd}} file:<br />
'' ...''<br />
'' stat_busy "Starting Music Player Daemon"''<br />
<br />
# always start in paused state<br />
awk '/^state_file[ \t]+"[^"]+"$/ {<br />
match($0, "\".+\"")<br />
sfile = substr($0, RSTART + 1, RLENGTH - 2)<br />
} /^user[ \t]+"[^"]+"$/ {<br />
match($0, "\".+\"")<br />
user = substr($0, RSTART + 1, RLENGTH - 2)<br />
} END {<br />
if (sfile == "")<br />
exit;<br />
if (user != "")<br />
sub(/^~/, "/home/" user, sfile)<br />
system("sed -i \x27s|^\\(state:[ \\t]\\{1,\\}\\)play$|\\1pause|\x27 \x27" sfile "\x27")<br />
}' /etc/mpd.conf<br />
<br />
'' /usr/bin/mpd /etc/mpd.conf &> /dev/null''<br />
'' ...''<br />
<br />
This will change the player status to "paused", if it was stopped while playing. Next, you want this file to be preserved, so MPD updates won't erase this edit. Add (or edit) this line to your {{Filename|/etc/pacman.conf}}:<br />
NoUpgrade = etc/rc.d/mpd<br />
<br />
====Method 2====<br />
<br />
Another simpler method, would be to add mpd to your {{Filename|[[rc.conf]]}} deamons array and add {{Codeline|mpc stop}} or {{Codeline|mpc pause}} to {{Filename|/etc/rc.local.shutdown}} and to {{Filename|/etc/rc.local}}. (Remember you must have mpc installed to use this method).<br />
<br />
Adding only the order in {{Filename|/etc/rc.local}} cannot assure that mpd will play absolutely nothing, since there may be a delay before the stop command is executed. <br />
On the other hand, if you only add the order to {{Filename|/etc/rc.local.shutdown}}, that will assure that mpd won't play at all, as long as you properly shutdown your system.<br />
Even though they are redundant, adding it to {{Filename|/etc/rc.local}} would serve as a safety for those, presumably, rare occasions when you do not shutdown the system properly.<br />
<br />
====Method 3====<br />
<br />
The general idea between this method is to ask mdp to pause music when user logs out so that during next restart, mdp will stick to that "pause" state. Sending such command can be achieve using [http://www.archlinux.org/packages/extra/x86_64/mpc/ mpc], the command line interface to MPD:<br />
pacman -S mpc<br />
<br />
GDM users can then add the next line to /etc/gdm/PostSession/Default (be sure to add it before "exit 0"):<br />
/usr/bin/mpc pause<br />
<br />
Non-GDM users can use their own login manager's method to launch the line at logout.<br />
<br />
===MPD & ALSA===<br />
Sometimes, when you use other audio output, e.g: some web pages containing Flash applets, MPD cannot reproduce anything anymore (until you restart). The error looks something like: (if you search the file {{Filename|/var/log/mpd/mpd.error}})<br />
<br />
Error opening alsa device "hw:0,0": Device or resource busy<br />
<br />
And here is the solution (dmix saving our life again). Apply these lines in your {{Filename|/etc/mpd.conf}}:<br />
<br />
<pre><br />
audio_output {<br />
type "alsa"<br />
name "Sound Card"<br />
options "dev=dmixer"<br />
device "plug:dmix"<br />
}<br />
</pre><br />
<br />
And then restart with {{Codeline|/etc/rc.d/mpd restart}}.<br />
<br />
Searching on Internet I found the reason for why that happens in Gentoo's wiki:<br />
* The sound card does not support hardware mixing (uses '''dmix''' plugin)<br />
* An application does not work with ALSA with it's default settings<br />
<br />
For a detailed description, it is recommended to take a look at [http://mpd.wikia.com/wiki/Alsa this] link. There you can find an example asound.conf which worked for me right out of the box.<br />
<br />
====High CPU usage with ALSA====<br />
When using MPD with ALSA, users may experience MPD taking up lots of CPU (around 20-30%). This is caused by most sound cards supporting 48kHz and most music being 44kHz, thus forcing MPD to resample it. This operation takes lots of CPU cycles and results into high usage.<br />
<br />
For most users the problem should be solved by telling MPD not to use resampling by adding {{Codeline|auto_resample "no"}} into audio_output-part of {{Filename|/etc/mpd.conf}}. This will degrade quality slightly, however.<br />
<br />
Example from {{Filename|mpd.conf}}:<br />
<br />
audio_output {<br />
type "alsa"<br />
name "My ALSA Device"<br />
auto_resample "no"<br />
}<br />
<br />
Although it may not give as drastic a speedup, enabling mmap may speed things up:<br />
<br />
audio_output {<br />
type "alsa"<br />
name "My ALSA Device"<br />
use_mmap "yes"<br />
}<br />
<br />
Some users might also want to tell dmix to use 44kHz as well. More info about tuning performance of your MPD can be found from: [http://mpd.wikia.com/wiki/Tuning MPD wiki]<br />
<br />
====Example configuration: Output with 44.1 KHz at e. g. 16 bit depth, multiple programs at once====<br />
<br />
''Why these formats?'' Because they are standard CDA, because ALSA on its own allows more than one program "to sound" only with dmix — whose resampling algorithm is inferior — and because dmix by default resamples anything lower to 48 KHz (or whatever higher format is playing at the time). Also, some get clicking sounds if at least {{Filename|mpd.conf}} is not changed this way.<br />
<br />
''What's the downside?'' These settings cause ''everything'' (if necessary) to be resampled to this format, such as material from DVD or TV which usually is at 48 KHz. But there is no known way to have ALSA dynamically change the format, and particularly if you listen to far more CDs than anything else the occasional 48 → 44.1 isn't too great a loss.<br />
<br />
The following assumes that there are not already other settings which conflict resp. overwrite it. This applies especially to the current user's potential {{Filename|~/.asoundrc}} — which MPD as its own user ignores, therefore the following should go to {{Filename|/etc/asound.conf}}:<br />
<br />
{{File|name=/etc/asound.conf|content=<br />
defaults.pcm.dmix.rate 44100 # Force 44.1 KHz<br />
defaults.pcm.dmix.format S16_LE # Force 16 bits<br />
}}<br />
<br />
{{File|name=/etc/mpd.conf|content=<br />
audio_output {<br />
type "alsa" # Use the ALSA output plugin.<br />
name "HDA Intel" # Can be called anything or nothing tmk, but must be present.<br />
options "dev=dmixer"<br />
device "plug:dmix" # Both lines cause MPD to output to dmix.<br />
format "44100:16:2" # the actual format<br />
auto_resample "no" # This bypasses ALSA's own algorithms, which generally are inferior. See below how to choose a different one.<br />
use_mmap "yes" # Minor speed improvement, should work with all modern cards.<br />
}<br />
<br />
samplerate_converter "0" # MPD's best, most CPU intensive algorithm. See 'man mpd.conf' for others — for anything other than the poorest "internal", libsamplerate must be installed.<br />
}}<br />
<br />
{{Note|MPD gives the mp3 format a special treatment at decoding: It's always outputted as 24 bit. (The conversion as forced by the ''format'' line only comes after that.)}}<br />
<br />
If one wants to leave the bit depth decision to ALSA resp. MPD, comment out resp. omit the ''dmix.format'' line and change the one for mpd with ''format'' to "44100:*:2".<br />
<br />
{{Note|''Crossfading'' between files decoded at two different bit depths (say, one mp3 and one 16 bit flac) does not work unless conversion is active.}}<br />
<br />
===Control MPD with lirc===<br />
There are already some clients designed for communications between lircd and MPD, however, as far as the practical use, they aren't very useful since their functions are limited.<br />
<br />
It's recommended to use mpc with irexec. mpc is a command line player which only sends the command to MPD and exits immediately, which is perfect for irexec, the command runner included in lirc. What irexec does is that it runs a specified command once received a remote control button.<br />
<br />
First of all, please setup your remotes as referred to the '''[[Lirc]]''' article.<br />
<br />
Edit your favored lirc startup configuration file, default location is {{Filename|~/.lircrc}}.<br />
<br />
Fill the file with the following pattern:<br />
begin<br />
prog = irexec<br />
button = <button_name><br />
config = <command_to_run><br />
repeat = <0 or 1><br />
end<br />
<br />
An useful example:<br />
## irexec<br />
begin<br />
prog = irexec<br />
button = play_pause<br />
config = mpc toggle<br />
repeat = 0<br />
end<br />
<br />
begin<br />
prog = irexec<br />
button = stop<br />
config = mpc stop<br />
repeat = 0<br />
end<br />
begin<br />
prog = irexec<br />
button = previous<br />
config = mpc prev<br />
repeat = 0<br />
end<br />
begin<br />
prog = irexec<br />
button = next<br />
config = mpc next<br />
repeat = 0<br />
end<br />
begin<br />
prog = irexec<br />
button = volup<br />
config = mpc volume +2<br />
repeat = 1<br />
end<br />
begin<br />
prog = irexec<br />
button = voldown<br />
config = mpc volume -2<br />
repeat = 1<br />
end<br />
begin<br />
prog = irexec<br />
button = pbc<br />
config = mpc random<br />
repeat = 0<br />
end<br />
begin<br />
prog = irexec<br />
button = pdvd<br />
config = mpc update<br />
repeat = 0<br />
end<br />
begin<br />
prog = irexec<br />
button = right<br />
config = mpc seek +00:00:05<br />
repeat = 0<br />
end<br />
begin<br />
prog = irexec<br />
button = left<br />
config = mpc seek -00:00:05<br />
repeat = 0<br />
end<br />
begin<br />
prog = irexec<br />
button = up<br />
config = mpc seek +1%<br />
repeat = 0<br />
end<br />
begin<br />
prog = irexec<br />
button = down<br />
config = mpc seek -1%<br />
repeat = 0<br />
end<br />
<br />
There are more functions for mpc, run {{Codeline|man mpc}} for more info.<br />
<br />
===Control MPD with bluetooth phone===<br />
You can also control MPD (to a certain extent) using a bluetooth enabled phone. You need to do the following:<br />
<br />
* install [http://remuco.sourceforge.net/index.php/Remuco remuco] -- a wireless remote control for several Linux media players ([http://aur.archlinux.org/packages.php?ID=25072 aur])<br />
* transfer remuco client -- jar/jad files from {{Filename|/usr/share/remuco/client/}} to your phone and install it<br />
* run {{Codeline|remuco-mpd}} (as current user)<br />
* run remuco on your phone, define a new bluetooth remuco connection (pair first if you haven't done this previously) and explore its capabilities<br />
<br />
More information about remuco including troubleshooting to be found at its [http://remuco.sourceforge.net/index.php/Remuco homepage]<br />
<br />
===MPD & PulseAudio===<br />
<br />
Edit {{Filename|/etc/mpd.conf}}, and uncomment the audio_output section for the type "pulse". The server and sink lines of it should be commented unless you know what you're doing.<br />
<br />
Then, add the mpd user (and yours if you haven't done so already) to the necessary pulse groups. The pulse-access group should be sufficient but you may want to add pulse-rt as well. The group "pulse" doesn't appear to be necessary.<br />
# gpasswd -a mpd pulse-access<br />
# gpasswd -a mpd pulse-rt<br />
<br />
Lastly, you may or may not need to copy {{Filename|~/.pulse-cookie}} from your current (pulse working) user's dir to your mpd user's home directory. It is likely to be {{Filename|/var/lib/mpd}} if you followed the first part of this wiki. This would probably only allow your current user to listen in on MPD's pulse. You may consider running pulse system-wide if that's insufficient.<br />
<br />
===Cue Files===<br />
<br />
To make cue file support actually work, you have to work around a nasty libcue bug. Libcue copied some files directly from libcdio, making it conflict with it. Steps to do to get proper cue support:<br />
<br />
* remove libcdio temporary (pacman -Rdd libcdio)<br />
* install libcue (pacman -S libcue)<br />
* install mpd with abs or from aur.<br />
* reinstall libcdio (pacman -S libcdio)<br />
<br />
At the point of writing mpd does not parse tracknumbers from cue sheets. There is a patch available (http://musicpd.org/mantis/view.php?id=3230)<br />
Once this patch is merged into mpd, i will remove this line :)<br />
<br />
==Troubleshooting==<br />
===Autodetection failed===<br />
During the start of MPD, it tries to autodetect your set-up and configure output and volume control accordingly. Though this mostly goes well, it will fail for some systems. It may help to tell MPD specifically what to use as output and mixer control. If you copied {{Filename|/etc/mpd.conf}} over from {{Filename|/etc/mpd.conf.example}} as mentioned above, you can simply uncomment:<br />
<br />
Example for alsa output type and alsa mixer:<br />
audio_output {<br />
type "alsa"<br />
name "My ALSA Device"<br />
device "hw:0,0" # optional<br />
format "44100:16:2" # optional<br />
mixer_type "hardware"<br />
mixer_device "default"<br />
mixer_control "PCM"<br />
}<br />
<br />
'''Note:''' in case of permission problems when using ESD with MPD run this as root:<br />
# chsh -s /bin/true mpd<br />
<br />
===Executable permissions===<br />
{{Warning|This is not good security practice and may be unnecessary.}}<br />
<br />
MPD needs to have +x permissions on '''ALL''' parent directories to your music collection (ie. if it's located outside of "mpd" home directory /var/lib/mpd). By default useradd sets permissions on home dir to 1700 drwx------. So if you're like me you will need to change permissions of /home/user. Example... my music collection is located /home/user/music. <br />
# chmod a+x /home/$USER<br />
# chmod -R a+X /home/$USER/music<br />
<br />
====Alternative solution====<br />
An alternative solution would be to use your group to share a selection of files, among them your music library. First remove all permissions for the group then add group permissions to read and execute home and music.<br />
# chmod -R g-rwx /home/$USER<br />
# chmod g+rx /home/$USER<br />
# chmod -R g+rX /home/$USER/music<br />
<br />
====Another alternative solution====<br />
Another alternative is to remount the music directory under a directory that mpd has access to. This does not entail the same security risks as modifying the permissions on one's home directory.<br />
# mkdir /var/lib/mpd/music<br />
# echo "/home/$USER/music /var/lib/mpd/music none bind" >> /etc/fstab<br />
# mount -a<br />
# /etc/rc.d/mpd restart<br />
And that should fix the problem. See also [https://bbs.archlinux.org/viewtopic.php?id=86449 the forum thread.]<br />
<br />
===Avoiding timeouts===<br />
To get rid of timeouts (i.e. when you paused music for long time) in gpmc and other clients uncomment and increase {{Codeline|connection_timeout}} option in {{Filename|mpd.conf}}.<br />
<br />
If files and/or titles are shown in wrong encoding, uncomment and change {{Codeline|filesystem_charset}} and {{Codeline|id3v1_encoding}} options.<br />
Note that you cannot set encoding for ID3 v2 tags. To workaround this you may use [http://mpd.wikia.com/wiki/GenericDecoder#Generic_Tagreader external tag readers].<br />
<br />
If you want to use another computer to control MPD over a network, the {{Codeline|bind_to_address}} option in {{Filename|mpd.conf}} will need to be set to either your IP address, or {{Codeline|any}} if your IP address changes frequently. <br />
<br />
'''Streaming'''<br><br />
With the latest version of MPD (0.15), built-in httpd streaming is now available.<br />
<br />
To activate this feature, you'll just need to add a new output of type httpd in {{Filename|mpd.conf}}:<br />
audio_output {<br />
type "httpd"<br />
name "What you want"<br />
encoder "lame" # vorbis or lame supported<br />
port "8000"<br />
bitrate "128"<br />
format "44100:16:2" # change 2 to 1 for mono<br />
}<br />
<br />
Restart the mpd deamon and, from another computer, simply load the stream as any other url. <br />
$ mplayer http://<server's IP>:8000<br />
<br />
{{Note | You must open the port on your router / firewall for the stream to be connectible to from another computer.}}<br />
<br />
Most players (i.e. vlc or xmms2) should also be able to load the stream via their "add url..." menu option.<br />
<br />
This is a nice clean way to replace your current icecast setup with something natively supported within MPD.<br />
<br />
===mpd hangs on first startup===<br />
This is a common error that's caused by corrupt mp3 tags.<br />
Here is an experimental way to solve this issue.<br />
Requirements:<br />
* kid3<br />
* easytag<br />
<br />
This method is very tedious, especially with a huge database. Just as a baseline it took 2.5h to fix a 16Gb DB.<br />
<br />
====Easy Tag====<br />
The purpose of easytag here is that easytag detects the error in the tags, but like MPD it hangs and dies. The trick here is that easy tags actually tells you what file is causing the problem on the status bar.<br />
Before starting easytag make sure to have a terminal close to be ready to kill easy tag to avoid a hang. Once you are ready, on the tree view select the directory where all your music is located. By default easytag starts to search all subdirectories for mp3 files. Once you notice that easytag stopped scanning for songs, make note of the culprit and kill easytag.<br />
<br />
====KID3====<br />
Here's where kid3 comes in handy. With kid3 go to the offending song and rewrite one of the tags. then save the file. This should force kid3 to rewrite the whole tag again fixing the problem with MPD and easy tag hanging.<br />
<br />
Repeat this procedure until your music library is done.<br />
<br />
===Cannot connect to mpd: host "localhost" not found: Temporary failure in name resolution===<br />
Cannot connect to MPD (with ncmpcpp), if you are disconnected from network. Solution is [[IPv6 - Disabling the Module|disable IPv6]] or add line to /etc/hosts<br />
::1 localhost.localdomain localhost<br />
<br />
===Other issues when attempting to connect to mpd with a client===<br />
Some have reported being unable to access mpd with various clients, for example seeing errors like these:<br />
$ ncmpcpp<br />
Cannot connect to mpd: Connection closed by the server<br />
$ sonata<br />
2011-02-13 18:33:05 Connection lost while reading MPD hello<br />
2011-02-13 18:33:05 Not connected<br />
2011-02-13 18:33:05 Not connected<br />
<br />
Please see posts on ncmpcpp on the Arch Forums [https://bbs.archlinux.org/viewtopic.php?id=109962 HERE] and [https://bbs.archlinux.org/viewtopic.php?id=113493 HERE]. Also see the Arch bug report on this issue [https://bugs.archlinux.org/task/22071 HERE]. <br />
<br />
====First fix====<br />
Check {{Filename|mpd.conf}} for a line like {{Codeline|mpd.error}} and remove it. The mpd error file is deprecated and has been removed.<br />
<br />
====Second fix====<br />
{{Note|I'm not so sure this is a good idea. There is a warning about changing the address to bind to in the default mpd.conf. If this does not help, you might want to comment out the changes.}}<br />
If that doesn't help, add the following to {{Filename|mpd.conf}}:<br />
<pre><br />
bind_to_address "127.0.0.1"<br />
port "6600"<br />
</pre><br />
<br />
Afterwards, instruct your client to connect via 127.0.0.1. For example, add the following to the ncmpcpp config file:<br />
<pre><br />
mpd_host "127.0.0.1"<br />
mpd_port "6600"<br />
</pre><br />
<br />
<br />
===Port 6600 already in use===<br />
MPD needs to bind to port 6600 and cannot start if it's already in use. The most common reason for this is that the user has started MPD once and then subsequently tried to start mpd again. In general, nothing should be done here.<br />
<br />
If port 6600 is tied up for some other reason, one can use the following command to find the offending process:<br />
# netstat -tulpan | grep 6600<br />
<br />
This will list IP:Port and the process name holding the connection (root privileges are required to see all processes).<br />
<br />
If you need to restart mpd for whatever reason, use:<br />
<pre><br />
$ mpd --kill<br />
$ mpd <br />
</pre><br />
A more brute-force approach:<br />
<pre><br />
$ killall mpd<br />
$ mpd <br />
</pre><br />
{{Note| If you typically run MPD as root, you will need to run the above commands as root.}}<br />
<br />
In the latest version of MPD, --create-db is completely deprecated. The database will be created automagically on first run and can subsequently be updated via your client (i.e. mpc update). You can now use inotify support to automatically update your music database. Add the following to {{File|name=mpd.conf|content=auto_update "yes"}} to enable it.<br />
<br />
===Binding to IPV6 before IPV4===<br />
If on startup, you see this message:<br />
listen: bind to '0.0.0.0:6600' failed: Address already in use (continuing anyway, because binding to '[::]:6600' succeeded)<br />
MPD is attempting to bind to the ipv6 interface before binding to ipv4. If you want to use your ipv4 interface, hardcode it in mpd.conf, like so:<br />
bind_to_address "127.0.0.1"<br />
Or, you could specify several binds, for example, to have MPD listen on localhost and the external IP of your network card:<br />
bind_to_address "127.0.0.1"<br />
bind_to_address "192.168.1.13"<br />
<br />
===Crackling sound with some audio files===<br />
This is usually a playback speed problem and can be fixed by uncommenting the audio_output_format line in:<br />
<br />
{{File|name=/etc/mpd.conf|content=<br />
audio_output_format "44100:16:2"}}<br />
<br />
This is usually a sane value for most mp3 files.<br />
<br />
===daemon: cannot setgid for user "mpd": Operation not permitted ===<br />
<br />
The error is stating that the user starting the process (you) does not have permissions to become another user (mpd) which the configuration has told that process to run as.<br />
<br />
To solve the issue, simply start mpd as root.<br />
su -c "/etc/rc.d/mpd start"<br />
or<br />
sudo /etc/rc.d/mpd start<br />
<br />
==External links==<br />
* [http://www.musicpd.org/ Official Web Site]<br />
* [http://mpd.wikia.com/wiki/Main_Page Official Wiki]<br />
* [http://mpd.wikia.com/wiki/Clients Sorted List of MPD Clients]<br />
* [http://www.musicpd.org/forum/ MPD forum]</div>Rasihttps://wiki.archlinux.org/index.php?title=Music_Player_Daemon&diff=150766Music Player Daemon2011-08-06T01:10:19Z<p>Rasi: /* Last.fm playback */</p>
<hr />
<div>[[fr:MPD]]<br />
[[Category:Audio/Video (English)]]<br />
[[Category:Daemons and system services (English)]]<br />
{{i18n|Music Player Daemon}}<br />
[[pl:Music Player Daemon]]<br />
<br />
'''MPD''' (music player daemon) is an audio player that has a server-client architecture. MPD runs in the background as a daemon, manages playlists and a music database, and uses very few resources. In order to interface with it, you need a separate client. More information can be found on their [http://www.musicpd.org/ website].<br />
<br />
''Please'' have a look at the official page for setup and troubleshooting instructions, the main developer called our wiki page in its current state ''"full of symptom killers"'', hence the official pages should contain better instructions.<br />
<br />
==Installing mpd==<br />
Install with [[pacman]]:<br />
# pacman -S mpd<br />
<br />
==Daemon Setup: Starting at Boot==<br />
General information about MPD configuration may be found at http://mpd.wikia.com/wiki/Configuration.<br />
<br />
===Sound setup===<br />
To make audio output actually work ensure that you have setup audio card and mixer correctly. See [[ALSA]], and [[PulseAudio]] if you are using Gnome 3. Do not forget to unmute the required channels in alsamixer, raise the volume and save changes with alsactl store. Run mpd with {{Filename|/usr/bin/mpd --stdout --no-daemon --verbose}} if that still doesn't work.<br />
<br />
Make sure your card can do hardware mixing (most of them can, including onboard audio). Or else this could cause problems with multiple sound playback. For example, this can prevent Mplayer from playing back sound while the mpd daemon is running, returning an audio error message stating the device is busy.<br />
<br />
===Timeline of MPD's behavior on a typical working setup when started as a daemon===<br />
# MPD is started on boot by {{Filename|/etc/rc.conf}}, by including it in the {{Codeline|DAEMONS}} array. (Or, this can be done manually each session by running {{Codeline|/etc/rc.d/mpd start}} with root privileges).<br />
# Since MPD is now started as root, it first reads the {{Filename|/etc/mpd.conf}} file.<br />
# MPD reads the user variable in the {{Filename|/etc/mpd.conf}} file, and changes from root to this user.<br />
# MPD then reads the contents of the {{Filename|/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 {{Filename|/etc/mpd.conf}} file. This way, uses of {{Codeline|~}} in the configuration file point correctly to the home user's directory, and not root's directory. It may be worthwhile to change all uses of {{Codeline|~}} to {{Codeline|/home/username}} to avoid any confusion over this aspect of MPD's behavior.<br />
<br />
===A clean configuration file===<br />
* As root, check if {{Filename|/etc/mpd.conf}} exists and delete the file if it does. This is safe.<br />
<br />
MPD comes with an example configuration file, available at {{Filename|/usr/share/mpd/mpd.conf.example}}. This file holds an abundance of information on MPD configuration, and holds default mixer values you can simply uncomment.<br />
<br />
* As root, copy this example file to {{Filename|/etc/mpd.conf}}.<br />
# cp /usr/share/mpd/mpd.conf.example /etc/mpd.conf<br />
({{Filename|/usr/share/mpd/mpd.conf.example}} is good for userspace setup)<br />
<br />
Since MPD is being set up to run as a daemon at boot, never put this file in the user's directory like some tutorials suggest, since it will not be read. Moreover, if you previously created a {{Filename|.mpdconf}} file in your home, remove it now (to set up MPD to run with user privileges alone, pleaser refer to the section [[Music_Player_Daemon#Alternative_Setup:_Starting_as_a_User | Alternative_Setup:_Starting_as_a_User]]). This is important to prevent conflicts. The presence of the configuration file in {{Filename|/etc}}, like is the case here, is what will enable MPD to run as a daemon at boot. Otherwise, a script would be needed to run MPD ''after'' the user has logged (like kdm or {{Filename|~/.fluxbox/startup}}) or it would require a manual move each time. For a single music collection, the method used here is simply better, even while the collection is shared to multiple users. Also, don't be afraid about root privileges: even while MPD runs as a daemon, it never completely runs as root since it automatically drops its root privileges after execution.<br />
<br />
===Edit {{Filename|mpd.conf}}===<br />
<br />
The default arch install keeps the setup in /var and uses "mpd" as default user, instead of cluttering up ~/.<br />
Edit {{Filename|/etc/mpd.conf}} to reflect as such.<br />
<br />
{{File|name=/etc/mpd.conf|content=<br />
music_directory "/home/user/music" # Your music dir.<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 "/var/run/mpd/mpd.pid" # Omit this line for systemd<br />
state_file "/var/lib/mpd/mpdstate"<br />
user "mpd"<br />
# Binding to address and port causing problems in mpd-0.14.2 best to leave<br />
# commented.<br />
# bind_to_address "127.0.0.1"<br />
# port "6600"<br />
}}<br />
<br />
* If your music collection is contained under multiple directories, you can make symbolic links under /var/lib/mpd then set 'music_directory' to the directory holding the symbolic links. Remember to set permissions accordingly on the directories being linked.<br />
<br />
* To change the volume of audio from mpd independent of other programs, uncomment or add the switch in mpd.conf:<br />
<br />
{{File|name=/etc/mpd.conf|content=<br />
mixer_type "software"<br />
}}<br />
<br />
* Lastly, if you are running pulseaudio under Gnome 3, the default setting of "alsa" for the audio output will not work. Make the modification from:<br />
{{File|name=/etc/mpd.conf|content=<br />
audio_output {<br />
type "alsa"<br />
name "Sound Card"<br />
}<br />
}}<br />
<br />
to<br />
<br />
{{File|name=/etc/mpd.conf|content=<br />
audio_output {<br />
type "pulse"<br />
name "Sound Card"<br />
}<br />
}}<br />
<br />
===Create files===<br />
<br />
* As root, create the directories and files you specified in {{Filename|/etc/mpd.conf}}.<br />
# mkdir -p /var/lib/mpd/playlists /var/run/mpd<br />
# touch /var/lib/mpd/{mpd.db,mpdstate} && touch /var/run/mpd/mpd.pid<br />
<br />
* You then need to change the file's permissions so that the daemon can modify them.<br />
# chown -R mpd /var/lib/mpd /var/run/mpd<br />
<br />
===Create database===<br />
<br />
Creating the database is now accomplished via the update feature of the client, for example 'mpc update'. The previous method, creating the MPD database as root (# mpd --create-db), is deprecated.<br />
<br />
==Alternative Setup: Starting as a User==<br />
MPD need not be started with root permissions. The only reason why MPD needs to be started as root (by being called from {{Filename|/etc/rc.conf}}) is because the default files and folders in the default configuration file points to directories owned by root (the /var directory). A less common, but perhaps more sensible, approach is to make MPD work with files and directories owned by a normal user. Running MPD as a normal user has several advantages: <br />
# You can easily have a single directory ~/.mpd (or any other directory under /home/username) for all MPD configuration files<br />
# No read/write permission errors<br />
# More flexible calls to MPD by using {{Filename|~/.xinitrc}} instead of including 'mpd' in the {{Filename|/etc/rc.conf}} DAEMONS array.<br />
<br />
The following steps shows how to run MPD as a normal user. '''Note''': this approach will not work if you want multiple users to have access to MPD.<br />
<br />
* Copy the contents of the default MPD configuration file in {{Filename|/usr/share/mpd/mpd.conf.example}} to your home directory. A good place would be {{Filename|"/home/user/.mpd/mpd.conf"}}.<br />
* Follow the 'old setup instructions' from above, ignoring the first part about copying the config to {{Filename|/etc/mpd.conf}} and do not set a user variable. <br />
* Create all of the requisite files in {{filename|"/home/user/.mpd/"}}:<br />
"~/.mpd/playlists/"<br />
"~/.mpd/db"<br />
"~/.mpd/mpd.db"<br />
"~/.mpd/mpd.log"<br />
"~/.mpd/mpd.error"<br />
"~/.mpd/mpd.pid"<br />
"~/.mpd/mpdstate"<br />
<br />
* Let MPD start on bootup by calling it from your {{Filename|~/.xinitrc}} as follows:<br />
# this starts mpd as normal user<br />
mpd ~/.mpd/mpd.conf<br />
{{Note| that you don't have to put a "&" at the end of the line here, since MPD will automatically daemonize itself.}}<br />
<br />
Lastly, delete the entry 'mpd' from your DAEMONS array in {{Filename|/etc/rc.conf}}, as you are not running it as root anymore.<br />
<br />
===Quick setup===<br />
<br />
The fastest way to do set up the structure is to do this:<br />
<br />
$ mkdir -p ~/.mpd/playlists && touch ~/.mpd/database && cp /usr/share/doc/mpd/mpdconf.example ~/.mpd/mpd.conf<br />
<br />
Then edit mpd.conf to your liking, in a manner similar to [[Music_Player_Daemon#Edit_mpd.conf]]. Beware that you must uncomment the db_file entry if you do edit mpd.conf.<br />
<br />
Then, to run it:<br />
<br />
$ mpd ~/.mpd/mpd.conf<br />
<br />
<br />
===Even quicker setup===<br />
I created a little script that will only ask for the location of your music and then creates the needed files and folders for you.<br />
You can find the script here:<br />
[http://karif.server-speed.net/~carnager/mpdsetup.tar]<br />
extract it<br />
$ tar xf mpdsetup.tar<br />
and run it<br />
$ ./mpdsetup.sh<br />
<br />
If you want to use this config in daemon mode, open it (~/.mpdconf) in an editor and find the "user" line. remove the comment (#) and fill in your own user name. Then copy the file to /etc/mpd.conf. If running mpd as user is fine for you, make sure to remove "mpd" from the daemons list in /etc/rc.conf<br />
<br />
===Multi-mpd setup===<br />
'''Useful if you want to run for example an icecast server.'''<br />
If you want a second MPD daemon (e.g., with icecast output to share music over the network) to use the same music and playlist as the one above, simply copy the above configuration file and make a new file (e.g., {{Filename|/home/username/.mpd/config-icecast}}), and only change the log_file, error_file, pid_file, and state_file parameters (e.g., {{Filename|mpd-icecast.log}}, {{Filename|mpd-icecast.error}}, and so on); using the same directory paths for the music and playlist directories would ensure that this second mpd daemon would use the same music collection as your first one (e.g., creating and editing a playlist under the first daemon would affect the second daemon as well, so that you don't have to create the same playlists all over again for the second daemon). Then, call this second daemon the same way from your {{Filename|~/.xinitrc}} above. (Just be sure to have a different port number, so as to not conflict with your first mpd daemon).<br />
<br />
==Clients==<br />
Install a client program for MPD. Popular options are:<br />
<br />
===Console===<br />
* '''mpc''' &ndash; Command Line Client (you'll probably want this one no matter what)<br />
# pacman -S mpc<br />
* [http://mpd.wikia.com/wiki/Client:Ncmpc/ ncmpc] &ndash; NCurses Client (this one is very handy for running in a console)<br />
# pacman -S ncmpc<br />
* [http://unkart.ovh.org/ncmpcpp/ ncmpcpp] &ndash; Clone of ncmpc with some new features written in C++<br />
# pacman -S ncmpcpp<br />
* [http://pms.sourceforge.net/ pms] &ndash; NCurses Client (highly configurable and accessible)<br />
Install [http://aur.archlinux.org/packages.php?ID=24378 pmus] from the [[AUR]].<br />
<br />
===Graphical===<br />
* [http://ario-player.sourceforge.net ario] &ndash; GTK+ Client with a Rhythmbox like library browser<br />
# pacman -S ario<br />
* [http://gmpcwiki.sarine.nl/index.php?title=GMPC gmpc] &ndash; GNOME Client<br />
# pacman -S gmpc<br />
* [http://bitcheese.net/wiki/QMPDClient QMPDClient] &ndash; Client written with Qt 4.x.<br />
# pacman -S qmpdclient<br />
* [http://sonata.berlios.de/ sonata] &ndash; Python GTK+ Client<br />
# pacman -S sonata<br />
* [http://aur.archlinux.org/packages.php?ID=33380 dmpc] &ndash; Dmenu-based MPC client with a playlist manager and state-saving on playlist changes<br />
Install [http://aur.archlinux.org/packages.php?ID=33380 dmpc] from the [[AUR]].<br />
<br />
See a long list of clients at the [http://mpd.wikia.com/wiki/Clients mpd wiki].<br />
<br />
==Extra stuff==<br />
===Last.fm scrobbling===<br />
To scrobble your songs to [http://www.last.fm Last.fm] using MPD there are several alternatives.<br />
<br />
====mpdscribble====<br />
mpdscribble is another daemon, available in the "community" repository (if you prefer, the "git" version is available in the [http://aur.archlinux.org/packages.php?ID=22274 AUR]). This is arguably the best alternative, because it's the semi-official MPD scrobbler and uses the new "idle" feature in MPD for more accurate scrobbling. Also, you don't need root access to configure it, because it doesn't need any changes to <tt>/etc</tt> at all. Visit [http://mpd.wikia.com/wiki/Client:Mpdscribble the official website] for more information.<br />
<br />
After you have installed mpdscribble, do the following (not as root):<br />
<br />
* {{Codeline|$ mkdir ~/.mpdscribble}}<br />
* Create the file {{Filename|~/.mpdscribble/mpdscribble.conf}} and add the following:<br />
<pre><br />
[mpdscribble] <br />
host = <your mpd host> # optional, defaults to $MPD_HOST or localhost<br />
port = <your mpd port> # optional, defaults to $MPD_PORT or 6600<br />
log = /home/<YOUR_USERNAME>/.mpdscribble/mpdscribble.log<br />
verbose = 2<br />
sleep = 1<br />
musicdir = <your music directory><br />
proxy = <your proxy> # optional, e. g. http://your.proxy:8080, defaults to none<br />
<br />
[last.fm]<br />
# last.fm section, comment if you don't use last.fm<br />
url = http://post.audioscrobbler.com/<br />
username = <your last.fm username><br />
password = <your last.fm password> # md5sum also possible: echo -n 'PASSWORD' | md5sum | cut -f 1 -d " "<br />
journal = /home/<YOUR_USERNAME>/.mpdscribble/lastfm.journal<br />
<br />
[libre.fm]<br />
# libre.fm section, comment if you don't use libre.fm<br />
url = http://turtle.libre.fm/<br />
username = <your libre.fm username><br />
password = <your libre.fm password> # md5sum also possible: echo -n 'PASSWORD' | md5sum | cut -f 1 -d " "<br />
journal = /home/<YOUR_USERNAME>/.mpdscribble/librefm.journal<br />
</pre><br />
* Add {{Codeline|mpdscribble}} to your {{Filename|~/.xinitrc}}:<br />
pidof mpdscribble >& /dev/null<br />
if [ $? -ne 0 ]; then<br />
mpdscribble &<br />
fi<br />
<br />
====Sonata & Ario====<br />
The easiest way, if you don't care about having to have a program window open all the time, is using Sonata or Ario which are graphical frontends to MPD. They have built-in support for Last.fm scrobbling in their preferences. A downside of this is that Sonata doesn't cache your songs if for some reason you don't happen to have an Internet connection at the time of playing.<br />
<br />
====lastfmsubmitd====<br />
lastfmsubmitd is a daemon which is available in the "community" repository. To install it, first edit {{Filename|/etc/lastfmsubmitd.conf}} and add both {{Codeline|lastfmsubmitd}} and {{Codeline|lastmp}} to the {{Codeline|DAEMONS}} array in {{Filename|/etc/rc.conf}}.<br />
<br />
==Last.fm playback==<br />
<br />
==Last.fm playback with lastfmproxy==<br />
lastfmproxy is a python script that streams a last.fm music stream to another media player. To setup, install [http://aur.archlinux.org/packages.php?ID=14214 lastfmproxy] from the [[AUR]] and then edit {{Filename|/usr/share/lastfmproxy/config.py}}. If you plan to only stream to MPD on the same host, just edit the login info.<br />
<br />
{{Note | Since it installs to a read only directory but it requires read/write access for features like saving previously listened to stations, it would be wise to copy {{Filename|/usr/share/lastfmproxy}} to your home directory.}}<br />
<br />
Start lastfmproxy with {{Codeline|lastfmproxy}} and visit http://localhost:1881/ in your web browser. To add a last.fm station navigate to http://localhost:1881/ followed by the lastfm:// url. Example: http://localhost:1881/lastfm://globaltags/punk . Navigate back to http://localhost:1881/ and download the m3u file by selecting the ''Start Listening'' link. Simply add it to your music library path.<br />
<br />
==Native Last.fm playback==<br />
Since 0.16 mpd has a very well working method to play back last.fm streams.<br />
{{File|name=/etc/mpd.conf|content=<br />
$ playlist_plugin {<br />
name "lastfm"<br />
user "my_username"<br />
password "my_password"<br />
}<br />
}}<br />
Then use e.g. mpc to load streams<br />
$ mpc load "lastfm://artist/Beatles"<br />
<br />
===Never play on start===<br />
<br />
This feature has recently been added to mpd git by Martin Kellerman, see commits b57330cf75bcb339e3f268f1019c63e40d305145 and 2fb40fe728ac07574808c40034fc0f3d2254d49d.<br />
<br />
====[https://aur.archlinux.org/packages.php?ID=19676 mpd-git] Method====<br />
This is the best method currently available, but is only currently (April 2011) enabled in the git version. Install [https://aur.archlinux.org/packages.php?ID=19676 mpd-git] from the [[AUR]], then add {{Codeline|restore_paused "yes"}} to your {{Filename|mpd.conf}} file.<br />
<br />
If you have issues with connecting your client to [https://aur.archlinux.org/packages.php?ID=19676 mpd-git], see [[Music Player Daemon#Other issues when attempting to connect to mpd with a client]].<br />
<br />
====Method 1====<br />
If you don't want MPD to always play on your system start, but yet you want to preserve the other state information, add the following lines to your {{Filename|/etc/rc.d/mpd}} file:<br />
'' ...''<br />
'' stat_busy "Starting Music Player Daemon"''<br />
<br />
# always start in paused state<br />
awk '/^state_file[ \t]+"[^"]+"$/ {<br />
match($0, "\".+\"")<br />
sfile = substr($0, RSTART + 1, RLENGTH - 2)<br />
} /^user[ \t]+"[^"]+"$/ {<br />
match($0, "\".+\"")<br />
user = substr($0, RSTART + 1, RLENGTH - 2)<br />
} END {<br />
if (sfile == "")<br />
exit;<br />
if (user != "")<br />
sub(/^~/, "/home/" user, sfile)<br />
system("sed -i \x27s|^\\(state:[ \\t]\\{1,\\}\\)play$|\\1pause|\x27 \x27" sfile "\x27")<br />
}' /etc/mpd.conf<br />
<br />
'' /usr/bin/mpd /etc/mpd.conf &> /dev/null''<br />
'' ...''<br />
<br />
This will change the player status to "paused", if it was stopped while playing. Next, you want this file to be preserved, so MPD updates won't erase this edit. Add (or edit) this line to your {{Filename|/etc/pacman.conf}}:<br />
NoUpgrade = etc/rc.d/mpd<br />
<br />
====Method 2====<br />
<br />
Another simpler method, would be to add mpd to your {{Filename|[[rc.conf]]}} deamons array and add {{Codeline|mpc stop}} or {{Codeline|mpc pause}} to {{Filename|/etc/rc.local.shutdown}} and to {{Filename|/etc/rc.local}}. (Remember you must have mpc installed to use this method).<br />
<br />
Adding only the order in {{Filename|/etc/rc.local}} cannot assure that mpd will play absolutely nothing, since there may be a delay before the stop command is executed. <br />
On the other hand, if you only add the order to {{Filename|/etc/rc.local.shutdown}}, that will assure that mpd won't play at all, as long as you properly shutdown your system.<br />
Even though they are redundant, adding it to {{Filename|/etc/rc.local}} would serve as a safety for those, presumably, rare occasions when you do not shutdown the system properly.<br />
<br />
====Method 3====<br />
<br />
The general idea between this method is to ask mdp to pause music when user logs out so that during next restart, mdp will stick to that "pause" state. Sending such command can be achieve using [http://www.archlinux.org/packages/extra/x86_64/mpc/ mpc], the command line interface to MPD:<br />
pacman -S mpc<br />
<br />
GDM users can then add the next line to /etc/gdm/PostSession/Default (be sure to add it before "exit 0"):<br />
/usr/bin/mpc pause<br />
<br />
Non-GDM users can use their own login manager's method to launch the line at logout.<br />
<br />
===MPD & ALSA===<br />
Sometimes, when you use other audio output, e.g: some web pages containing Flash applets, MPD cannot reproduce anything anymore (until you restart). The error looks something like: (if you search the file {{Filename|/var/log/mpd/mpd.error}})<br />
<br />
Error opening alsa device "hw:0,0": Device or resource busy<br />
<br />
And here is the solution (dmix saving our life again). Apply these lines in your {{Filename|/etc/mpd.conf}}:<br />
<br />
<pre><br />
audio_output {<br />
type "alsa"<br />
name "Sound Card"<br />
options "dev=dmixer"<br />
device "plug:dmix"<br />
}<br />
</pre><br />
<br />
And then restart with {{Codeline|/etc/rc.d/mpd restart}}.<br />
<br />
Searching on Internet I found the reason for why that happens in Gentoo's wiki:<br />
* The sound card does not support hardware mixing (uses '''dmix''' plugin)<br />
* An application does not work with ALSA with it's default settings<br />
<br />
For a detailed description, it is recommended to take a look at [http://mpd.wikia.com/wiki/Alsa this] link. There you can find an example asound.conf which worked for me right out of the box.<br />
<br />
====High CPU usage with ALSA====<br />
When using MPD with ALSA, users may experience MPD taking up lots of CPU (around 20-30%). This is caused by most sound cards supporting 48kHz and most music being 44kHz, thus forcing MPD to resample it. This operation takes lots of CPU cycles and results into high usage.<br />
<br />
For most users the problem should be solved by telling MPD not to use resampling by adding {{Codeline|auto_resample "no"}} into audio_output-part of {{Filename|/etc/mpd.conf}}. This will degrade quality slightly, however.<br />
<br />
Example from {{Filename|mpd.conf}}:<br />
<br />
audio_output {<br />
type "alsa"<br />
name "My ALSA Device"<br />
auto_resample "no"<br />
}<br />
<br />
Although it may not give as drastic a speedup, enabling mmap may speed things up:<br />
<br />
audio_output {<br />
type "alsa"<br />
name "My ALSA Device"<br />
use_mmap "yes"<br />
}<br />
<br />
Some users might also want to tell dmix to use 44kHz as well. More info about tuning performance of your MPD can be found from: [http://mpd.wikia.com/wiki/Tuning MPD wiki]<br />
<br />
====Example configuration: Output with 44.1 KHz at e. g. 16 bit depth, multiple programs at once====<br />
<br />
''Why these formats?'' Because they are standard CDA, because ALSA on its own allows more than one program "to sound" only with dmix — whose resampling algorithm is inferior — and because dmix by default resamples anything lower to 48 KHz (or whatever higher format is playing at the time). Also, some get clicking sounds if at least {{Filename|mpd.conf}} is not changed this way.<br />
<br />
''What's the downside?'' These settings cause ''everything'' (if necessary) to be resampled to this format, such as material from DVD or TV which usually is at 48 KHz. But there is no known way to have ALSA dynamically change the format, and particularly if you listen to far more CDs than anything else the occasional 48 → 44.1 isn't too great a loss.<br />
<br />
The following assumes that there are not already other settings which conflict resp. overwrite it. This applies especially to the current user's potential {{Filename|~/.asoundrc}} — which MPD as its own user ignores, therefore the following should go to {{Filename|/etc/asound.conf}}:<br />
<br />
{{File|name=/etc/asound.conf|content=<br />
defaults.pcm.dmix.rate 44100 # Force 44.1 KHz<br />
defaults.pcm.dmix.format S16_LE # Force 16 bits<br />
}}<br />
<br />
{{File|name=/etc/mpd.conf|content=<br />
audio_output {<br />
type "alsa" # Use the ALSA output plugin.<br />
name "HDA Intel" # Can be called anything or nothing tmk, but must be present.<br />
options "dev=dmixer"<br />
device "plug:dmix" # Both lines cause MPD to output to dmix.<br />
format "44100:16:2" # the actual format<br />
auto_resample "no" # This bypasses ALSA's own algorithms, which generally are inferior. See below how to choose a different one.<br />
use_mmap "yes" # Minor speed improvement, should work with all modern cards.<br />
}<br />
<br />
samplerate_converter "0" # MPD's best, most CPU intensive algorithm. See 'man mpd.conf' for others — for anything other than the poorest "internal", libsamplerate must be installed.<br />
}}<br />
<br />
{{Note|MPD gives the mp3 format a special treatment at decoding: It's always outputted as 24 bit. (The conversion as forced by the ''format'' line only comes after that.)}}<br />
<br />
If one wants to leave the bit depth decision to ALSA resp. MPD, comment out resp. omit the ''dmix.format'' line and change the one for mpd with ''format'' to "44100:*:2".<br />
<br />
{{Note|''Crossfading'' between files decoded at two different bit depths (say, one mp3 and one 16 bit flac) does not work unless conversion is active.}}<br />
<br />
===Control MPD with lirc===<br />
There are already some clients designed for communications between lircd and MPD, however, as far as the practical use, they aren't very useful since their functions are limited.<br />
<br />
It's recommended to use mpc with irexec. mpc is a command line player which only sends the command to MPD and exits immediately, which is perfect for irexec, the command runner included in lirc. What irexec does is that it runs a specified command once received a remote control button.<br />
<br />
First of all, please setup your remotes as referred to the '''[[Lirc]]''' article.<br />
<br />
Edit your favored lirc startup configuration file, default location is {{Filename|~/.lircrc}}.<br />
<br />
Fill the file with the following pattern:<br />
begin<br />
prog = irexec<br />
button = <button_name><br />
config = <command_to_run><br />
repeat = <0 or 1><br />
end<br />
<br />
An useful example:<br />
## irexec<br />
begin<br />
prog = irexec<br />
button = play_pause<br />
config = mpc toggle<br />
repeat = 0<br />
end<br />
<br />
begin<br />
prog = irexec<br />
button = stop<br />
config = mpc stop<br />
repeat = 0<br />
end<br />
begin<br />
prog = irexec<br />
button = previous<br />
config = mpc prev<br />
repeat = 0<br />
end<br />
begin<br />
prog = irexec<br />
button = next<br />
config = mpc next<br />
repeat = 0<br />
end<br />
begin<br />
prog = irexec<br />
button = volup<br />
config = mpc volume +2<br />
repeat = 1<br />
end<br />
begin<br />
prog = irexec<br />
button = voldown<br />
config = mpc volume -2<br />
repeat = 1<br />
end<br />
begin<br />
prog = irexec<br />
button = pbc<br />
config = mpc random<br />
repeat = 0<br />
end<br />
begin<br />
prog = irexec<br />
button = pdvd<br />
config = mpc update<br />
repeat = 0<br />
end<br />
begin<br />
prog = irexec<br />
button = right<br />
config = mpc seek +00:00:05<br />
repeat = 0<br />
end<br />
begin<br />
prog = irexec<br />
button = left<br />
config = mpc seek -00:00:05<br />
repeat = 0<br />
end<br />
begin<br />
prog = irexec<br />
button = up<br />
config = mpc seek +1%<br />
repeat = 0<br />
end<br />
begin<br />
prog = irexec<br />
button = down<br />
config = mpc seek -1%<br />
repeat = 0<br />
end<br />
<br />
There are more functions for mpc, run {{Codeline|man mpc}} for more info.<br />
<br />
===Control MPD with bluetooth phone===<br />
You can also control MPD (to a certain extent) using a bluetooth enabled phone. You need to do the following:<br />
<br />
* install [http://remuco.sourceforge.net/index.php/Remuco remuco] -- a wireless remote control for several Linux media players ([http://aur.archlinux.org/packages.php?ID=25072 aur])<br />
* transfer remuco client -- jar/jad files from {{Filename|/usr/share/remuco/client/}} to your phone and install it<br />
* run {{Codeline|remuco-mpd}} (as current user)<br />
* run remuco on your phone, define a new bluetooth remuco connection (pair first if you haven't done this previously) and explore its capabilities<br />
<br />
More information about remuco including troubleshooting to be found at its [http://remuco.sourceforge.net/index.php/Remuco homepage]<br />
<br />
===MPD & PulseAudio===<br />
<br />
Edit {{Filename|/etc/mpd.conf}}, and uncomment the audio_output section for the type "pulse". The server and sink lines of it should be commented unless you know what you're doing.<br />
<br />
Then, add the mpd user (and yours if you haven't done so already) to the necessary pulse groups. The pulse-access group should be sufficient but you may want to add pulse-rt as well. The group "pulse" doesn't appear to be necessary.<br />
# gpasswd -a mpd pulse-access<br />
# gpasswd -a mpd pulse-rt<br />
<br />
Lastly, you may or may not need to copy {{Filename|~/.pulse-cookie}} from your current (pulse working) user's dir to your mpd user's home directory. It is likely to be {{Filename|/var/lib/mpd}} if you followed the first part of this wiki. This would probably only allow your current user to listen in on MPD's pulse. You may consider running pulse system-wide if that's insufficient.<br />
<br />
===Cue Files===<br />
<br />
To make cue file support actually work, you have to work around a nasty libcue bug. Libcue copied some files directly from libcdio, making it conflict with it. Steps to do to get proper cue support:<br />
<br />
* remove libcdio temporary (pacman -Rdd libcdio)<br />
* install libcue (pacman -S libcue)<br />
* install mpd with abs or from aur.<br />
* reinstall libcdio (pacman -S libcdio)<br />
<br />
At the point of writing mpd does not parse tracknumbers from cue sheets. There is a patch available (http://musicpd.org/mantis/view.php?id=3230)<br />
Once this patch is merged into mpd, i will remove this line :)<br />
<br />
==Troubleshooting==<br />
===Autodetection failed===<br />
During the start of MPD, it tries to autodetect your set-up and configure output and volume control accordingly. Though this mostly goes well, it will fail for some systems. It may help to tell MPD specifically what to use as output and mixer control. If you copied {{Filename|/etc/mpd.conf}} over from {{Filename|/etc/mpd.conf.example}} as mentioned above, you can simply uncomment:<br />
<br />
Example for alsa output type and alsa mixer:<br />
audio_output {<br />
type "alsa"<br />
name "My ALSA Device"<br />
device "hw:0,0" # optional<br />
format "44100:16:2" # optional<br />
mixer_type "hardware"<br />
mixer_device "default"<br />
mixer_control "PCM"<br />
}<br />
<br />
'''Note:''' in case of permission problems when using ESD with MPD run this as root:<br />
# chsh -s /bin/true mpd<br />
<br />
===Executable permissions===<br />
{{Warning|This is not good security practice and may be unnecessary.}}<br />
<br />
MPD needs to have +x permissions on '''ALL''' parent directories to your music collection (ie. if it's located outside of "mpd" home directory /var/lib/mpd). By default useradd sets permissions on home dir to 1700 drwx------. So if you're like me you will need to change permissions of /home/user. Example... my music collection is located /home/user/music. <br />
# chmod a+x /home/$USER<br />
# chmod -R a+X /home/$USER/music<br />
<br />
====Alternative solution====<br />
An alternative solution would be to use your group to share a selection of files, among them your music library. First remove all permissions for the group then add group permissions to read and execute home and music.<br />
# chmod -R g-rwx /home/$USER<br />
# chmod g+rx /home/$USER<br />
# chmod -R g+rX /home/$USER/music<br />
<br />
====Another alternative solution====<br />
Another alternative is to remount the music directory under a directory that mpd has access to. This does not entail the same security risks as modifying the permissions on one's home directory.<br />
# mkdir /var/lib/mpd/music<br />
# echo "/home/$USER/music /var/lib/mpd/music none bind" >> /etc/fstab<br />
# mount -a<br />
# /etc/rc.d/mpd restart<br />
And that should fix the problem. See also [https://bbs.archlinux.org/viewtopic.php?id=86449 the forum thread.]<br />
<br />
===Avoiding timeouts===<br />
To get rid of timeouts (i.e. when you paused music for long time) in gpmc and other clients uncomment and increase {{Codeline|connection_timeout}} option in {{Filename|mpd.conf}}.<br />
<br />
If files and/or titles are shown in wrong encoding, uncomment and change {{Codeline|filesystem_charset}} and {{Codeline|id3v1_encoding}} options.<br />
Note that you cannot set encoding for ID3 v2 tags. To workaround this you may use [http://mpd.wikia.com/wiki/GenericDecoder#Generic_Tagreader external tag readers].<br />
<br />
If you want to use another computer to control MPD over a network, the {{Codeline|bind_to_address}} option in {{Filename|mpd.conf}} will need to be set to either your IP address, or {{Codeline|any}} if your IP address changes frequently. <br />
<br />
'''Streaming'''<br><br />
With the latest version of MPD (0.15), built-in httpd streaming is now available.<br />
<br />
To activate this feature, you'll just need to add a new output of type httpd in {{Filename|mpd.conf}}:<br />
audio_output {<br />
type "httpd"<br />
name "What you want"<br />
encoder "lame" # vorbis or lame supported<br />
port "8000"<br />
bitrate "128"<br />
format "44100:16:2" # change 2 to 1 for mono<br />
}<br />
<br />
Restart the mpd deamon and, from another computer, simply load the stream as any other url. <br />
$ mplayer http://<server's IP>:8000<br />
<br />
{{Note | You must open the port on your router / firewall for the stream to be connectible to from another computer.}}<br />
<br />
Most players (i.e. vlc or xmms2) should also be able to load the stream via their "add url..." menu option.<br />
<br />
This is a nice clean way to replace your current icecast setup with something natively supported within MPD.<br />
<br />
===mpd hangs on first startup===<br />
This is a common error that's caused by corrupt mp3 tags.<br />
Here is an experimental way to solve this issue.<br />
Requirements:<br />
* kid3<br />
* easytag<br />
<br />
This method is very tedious, especially with a huge database. Just as a baseline it took 2.5h to fix a 16Gb DB.<br />
<br />
====Easy Tag====<br />
The purpose of easytag here is that easytag detects the error in the tags, but like MPD it hangs and dies. The trick here is that easy tags actually tells you what file is causing the problem on the status bar.<br />
Before starting easytag make sure to have a terminal close to be ready to kill easy tag to avoid a hang. Once you are ready, on the tree view select the directory where all your music is located. By default easytag starts to search all subdirectories for mp3 files. Once you notice that easytag stopped scanning for songs, make note of the culprit and kill easytag.<br />
<br />
====KID3====<br />
Here's where kid3 comes in handy. With kid3 go to the offending song and rewrite one of the tags. then save the file. This should force kid3 to rewrite the whole tag again fixing the problem with MPD and easy tag hanging.<br />
<br />
Repeat this procedure until your music library is done.<br />
<br />
===Cannot connect to mpd: host "localhost" not found: Temporary failure in name resolution===<br />
Cannot connect to MPD (with ncmpcpp), if you are disconnected from network. Solution is [[IPv6 - Disabling the Module|disable IPv6]] or add line to /etc/hosts<br />
::1 localhost.localdomain localhost<br />
<br />
===Other issues when attempting to connect to mpd with a client===<br />
Some have reported being unable to access mpd with various clients, for example seeing errors like these:<br />
$ ncmpcpp<br />
Cannot connect to mpd: Connection closed by the server<br />
$ sonata<br />
2011-02-13 18:33:05 Connection lost while reading MPD hello<br />
2011-02-13 18:33:05 Not connected<br />
2011-02-13 18:33:05 Not connected<br />
<br />
Please see posts on ncmpcpp on the Arch Forums [https://bbs.archlinux.org/viewtopic.php?id=109962 HERE] and [https://bbs.archlinux.org/viewtopic.php?id=113493 HERE]. Also see the Arch bug report on this issue [https://bugs.archlinux.org/task/22071 HERE]. <br />
<br />
====First fix====<br />
Check {{Filename|mpd.conf}} for a line like {{Codeline|mpd.error}} and remove it. The mpd error file is deprecated and has been removed.<br />
<br />
====Second fix====<br />
{{Note|I'm not so sure this is a good idea. There is a warning about changing the address to bind to in the default mpd.conf. If this does not help, you might want to comment out the changes.}}<br />
If that doesn't help, add the following to {{Filename|mpd.conf}}:<br />
<pre><br />
bind_to_address "127.0.0.1"<br />
port "6600"<br />
</pre><br />
<br />
Afterwards, instruct your client to connect via 127.0.0.1. For example, add the following to the ncmpcpp config file:<br />
<pre><br />
mpd_host "127.0.0.1"<br />
mpd_port "6600"<br />
</pre><br />
<br />
<br />
===Port 6600 already in use===<br />
MPD needs to bind to port 6600 and cannot start if it's already in use. The most common reason for this is that the user has started MPD once and then subsequently tried to start mpd again. In general, nothing should be done here.<br />
<br />
If port 6600 is tied up for some other reason, one can use the following command to find the offending process:<br />
# netstat -tulpan | grep 6600<br />
<br />
This will list IP:Port and the process name holding the connection (root privileges are required to see all processes).<br />
<br />
If you need to restart mpd for whatever reason, use:<br />
<pre><br />
$ mpd --kill<br />
$ mpd <br />
</pre><br />
A more brute-force approach:<br />
<pre><br />
$ killall mpd<br />
$ mpd <br />
</pre><br />
{{Note| If you typically run MPD as root, you will need to run the above commands as root.}}<br />
<br />
In the latest version of MPD, --create-db is completely deprecated. The database will be created automagically on first run and can subsequently be updated via your client (i.e. mpc update). You can now use inotify support to automatically update your music database. Add the following to {{File|name=mpd.conf|content=auto_update "yes"}} to enable it.<br />
<br />
===Binding to IPV6 before IPV4===<br />
If on startup, you see this message:<br />
listen: bind to '0.0.0.0:6600' failed: Address already in use (continuing anyway, because binding to '[::]:6600' succeeded)<br />
MPD is attempting to bind to the ipv6 interface before binding to ipv4. If you want to use your ipv4 interface, hardcode it in mpd.conf, like so:<br />
bind_to_address "127.0.0.1"<br />
Or, you could specify several binds, for example, to have MPD listen on localhost and the external IP of your network card:<br />
bind_to_address "127.0.0.1"<br />
bind_to_address "192.168.1.13"<br />
<br />
===Crackling sound with some audio files===<br />
This is usually a playback speed problem and can be fixed by uncommenting the audio_output_format line in:<br />
<br />
{{File|name=/etc/mpd.conf|content=<br />
audio_output_format "44100:16:2"}}<br />
<br />
This is usually a sane value for most mp3 files.<br />
<br />
===daemon: cannot setgid for user "mpd": Operation not permitted ===<br />
<br />
The error is stating that the user starting the process (you) does not have permissions to become another user (mpd) which the configuration has told that process to run as.<br />
<br />
To solve the issue, simply start mpd as root.<br />
su -c "/etc/rc.d/mpd start"<br />
or<br />
sudo /etc/rc.d/mpd start<br />
<br />
==External links==<br />
* [http://www.musicpd.org/ Official Web Site]<br />
* [http://mpd.wikia.com/wiki/Main_Page Official Wiki]<br />
* [http://mpd.wikia.com/wiki/Clients Sorted List of MPD Clients]<br />
* [http://www.musicpd.org/forum/ MPD forum]</div>Rasihttps://wiki.archlinux.org/index.php?title=Music_Player_Daemon&diff=150765Music Player Daemon2011-08-06T01:09:46Z<p>Rasi: /* Last.fm playback with lastfmproxy */</p>
<hr />
<div>[[fr:MPD]]<br />
[[Category:Audio/Video (English)]]<br />
[[Category:Daemons and system services (English)]]<br />
{{i18n|Music Player Daemon}}<br />
[[pl:Music Player Daemon]]<br />
<br />
'''MPD''' (music player daemon) is an audio player that has a server-client architecture. MPD runs in the background as a daemon, manages playlists and a music database, and uses very few resources. In order to interface with it, you need a separate client. More information can be found on their [http://www.musicpd.org/ website].<br />
<br />
''Please'' have a look at the official page for setup and troubleshooting instructions, the main developer called our wiki page in its current state ''"full of symptom killers"'', hence the official pages should contain better instructions.<br />
<br />
==Installing mpd==<br />
Install with [[pacman]]:<br />
# pacman -S mpd<br />
<br />
==Daemon Setup: Starting at Boot==<br />
General information about MPD configuration may be found at http://mpd.wikia.com/wiki/Configuration.<br />
<br />
===Sound setup===<br />
To make audio output actually work ensure that you have setup audio card and mixer correctly. See [[ALSA]], and [[PulseAudio]] if you are using Gnome 3. Do not forget to unmute the required channels in alsamixer, raise the volume and save changes with alsactl store. Run mpd with {{Filename|/usr/bin/mpd --stdout --no-daemon --verbose}} if that still doesn't work.<br />
<br />
Make sure your card can do hardware mixing (most of them can, including onboard audio). Or else this could cause problems with multiple sound playback. For example, this can prevent Mplayer from playing back sound while the mpd daemon is running, returning an audio error message stating the device is busy.<br />
<br />
===Timeline of MPD's behavior on a typical working setup when started as a daemon===<br />
# MPD is started on boot by {{Filename|/etc/rc.conf}}, by including it in the {{Codeline|DAEMONS}} array. (Or, this can be done manually each session by running {{Codeline|/etc/rc.d/mpd start}} with root privileges).<br />
# Since MPD is now started as root, it first reads the {{Filename|/etc/mpd.conf}} file.<br />
# MPD reads the user variable in the {{Filename|/etc/mpd.conf}} file, and changes from root to this user.<br />
# MPD then reads the contents of the {{Filename|/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 {{Filename|/etc/mpd.conf}} file. This way, uses of {{Codeline|~}} in the configuration file point correctly to the home user's directory, and not root's directory. It may be worthwhile to change all uses of {{Codeline|~}} to {{Codeline|/home/username}} to avoid any confusion over this aspect of MPD's behavior.<br />
<br />
===A clean configuration file===<br />
* As root, check if {{Filename|/etc/mpd.conf}} exists and delete the file if it does. This is safe.<br />
<br />
MPD comes with an example configuration file, available at {{Filename|/usr/share/mpd/mpd.conf.example}}. This file holds an abundance of information on MPD configuration, and holds default mixer values you can simply uncomment.<br />
<br />
* As root, copy this example file to {{Filename|/etc/mpd.conf}}.<br />
# cp /usr/share/mpd/mpd.conf.example /etc/mpd.conf<br />
({{Filename|/usr/share/mpd/mpd.conf.example}} is good for userspace setup)<br />
<br />
Since MPD is being set up to run as a daemon at boot, never put this file in the user's directory like some tutorials suggest, since it will not be read. Moreover, if you previously created a {{Filename|.mpdconf}} file in your home, remove it now (to set up MPD to run with user privileges alone, pleaser refer to the section [[Music_Player_Daemon#Alternative_Setup:_Starting_as_a_User | Alternative_Setup:_Starting_as_a_User]]). This is important to prevent conflicts. The presence of the configuration file in {{Filename|/etc}}, like is the case here, is what will enable MPD to run as a daemon at boot. Otherwise, a script would be needed to run MPD ''after'' the user has logged (like kdm or {{Filename|~/.fluxbox/startup}}) or it would require a manual move each time. For a single music collection, the method used here is simply better, even while the collection is shared to multiple users. Also, don't be afraid about root privileges: even while MPD runs as a daemon, it never completely runs as root since it automatically drops its root privileges after execution.<br />
<br />
===Edit {{Filename|mpd.conf}}===<br />
<br />
The default arch install keeps the setup in /var and uses "mpd" as default user, instead of cluttering up ~/.<br />
Edit {{Filename|/etc/mpd.conf}} to reflect as such.<br />
<br />
{{File|name=/etc/mpd.conf|content=<br />
music_directory "/home/user/music" # Your music dir.<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 "/var/run/mpd/mpd.pid" # Omit this line for systemd<br />
state_file "/var/lib/mpd/mpdstate"<br />
user "mpd"<br />
# Binding to address and port causing problems in mpd-0.14.2 best to leave<br />
# commented.<br />
# bind_to_address "127.0.0.1"<br />
# port "6600"<br />
}}<br />
<br />
* If your music collection is contained under multiple directories, you can make symbolic links under /var/lib/mpd then set 'music_directory' to the directory holding the symbolic links. Remember to set permissions accordingly on the directories being linked.<br />
<br />
* To change the volume of audio from mpd independent of other programs, uncomment or add the switch in mpd.conf:<br />
<br />
{{File|name=/etc/mpd.conf|content=<br />
mixer_type "software"<br />
}}<br />
<br />
* Lastly, if you are running pulseaudio under Gnome 3, the default setting of "alsa" for the audio output will not work. Make the modification from:<br />
{{File|name=/etc/mpd.conf|content=<br />
audio_output {<br />
type "alsa"<br />
name "Sound Card"<br />
}<br />
}}<br />
<br />
to<br />
<br />
{{File|name=/etc/mpd.conf|content=<br />
audio_output {<br />
type "pulse"<br />
name "Sound Card"<br />
}<br />
}}<br />
<br />
===Create files===<br />
<br />
* As root, create the directories and files you specified in {{Filename|/etc/mpd.conf}}.<br />
# mkdir -p /var/lib/mpd/playlists /var/run/mpd<br />
# touch /var/lib/mpd/{mpd.db,mpdstate} && touch /var/run/mpd/mpd.pid<br />
<br />
* You then need to change the file's permissions so that the daemon can modify them.<br />
# chown -R mpd /var/lib/mpd /var/run/mpd<br />
<br />
===Create database===<br />
<br />
Creating the database is now accomplished via the update feature of the client, for example 'mpc update'. The previous method, creating the MPD database as root (# mpd --create-db), is deprecated.<br />
<br />
==Alternative Setup: Starting as a User==<br />
MPD need not be started with root permissions. The only reason why MPD needs to be started as root (by being called from {{Filename|/etc/rc.conf}}) is because the default files and folders in the default configuration file points to directories owned by root (the /var directory). A less common, but perhaps more sensible, approach is to make MPD work with files and directories owned by a normal user. Running MPD as a normal user has several advantages: <br />
# You can easily have a single directory ~/.mpd (or any other directory under /home/username) for all MPD configuration files<br />
# No read/write permission errors<br />
# More flexible calls to MPD by using {{Filename|~/.xinitrc}} instead of including 'mpd' in the {{Filename|/etc/rc.conf}} DAEMONS array.<br />
<br />
The following steps shows how to run MPD as a normal user. '''Note''': this approach will not work if you want multiple users to have access to MPD.<br />
<br />
* Copy the contents of the default MPD configuration file in {{Filename|/usr/share/mpd/mpd.conf.example}} to your home directory. A good place would be {{Filename|"/home/user/.mpd/mpd.conf"}}.<br />
* Follow the 'old setup instructions' from above, ignoring the first part about copying the config to {{Filename|/etc/mpd.conf}} and do not set a user variable. <br />
* Create all of the requisite files in {{filename|"/home/user/.mpd/"}}:<br />
"~/.mpd/playlists/"<br />
"~/.mpd/db"<br />
"~/.mpd/mpd.db"<br />
"~/.mpd/mpd.log"<br />
"~/.mpd/mpd.error"<br />
"~/.mpd/mpd.pid"<br />
"~/.mpd/mpdstate"<br />
<br />
* Let MPD start on bootup by calling it from your {{Filename|~/.xinitrc}} as follows:<br />
# this starts mpd as normal user<br />
mpd ~/.mpd/mpd.conf<br />
{{Note| that you don't have to put a "&" at the end of the line here, since MPD will automatically daemonize itself.}}<br />
<br />
Lastly, delete the entry 'mpd' from your DAEMONS array in {{Filename|/etc/rc.conf}}, as you are not running it as root anymore.<br />
<br />
===Quick setup===<br />
<br />
The fastest way to do set up the structure is to do this:<br />
<br />
$ mkdir -p ~/.mpd/playlists && touch ~/.mpd/database && cp /usr/share/doc/mpd/mpdconf.example ~/.mpd/mpd.conf<br />
<br />
Then edit mpd.conf to your liking, in a manner similar to [[Music_Player_Daemon#Edit_mpd.conf]]. Beware that you must uncomment the db_file entry if you do edit mpd.conf.<br />
<br />
Then, to run it:<br />
<br />
$ mpd ~/.mpd/mpd.conf<br />
<br />
<br />
===Even quicker setup===<br />
I created a little script that will only ask for the location of your music and then creates the needed files and folders for you.<br />
You can find the script here:<br />
[http://karif.server-speed.net/~carnager/mpdsetup.tar]<br />
extract it<br />
$ tar xf mpdsetup.tar<br />
and run it<br />
$ ./mpdsetup.sh<br />
<br />
If you want to use this config in daemon mode, open it (~/.mpdconf) in an editor and find the "user" line. remove the comment (#) and fill in your own user name. Then copy the file to /etc/mpd.conf. If running mpd as user is fine for you, make sure to remove "mpd" from the daemons list in /etc/rc.conf<br />
<br />
===Multi-mpd setup===<br />
'''Useful if you want to run for example an icecast server.'''<br />
If you want a second MPD daemon (e.g., with icecast output to share music over the network) to use the same music and playlist as the one above, simply copy the above configuration file and make a new file (e.g., {{Filename|/home/username/.mpd/config-icecast}}), and only change the log_file, error_file, pid_file, and state_file parameters (e.g., {{Filename|mpd-icecast.log}}, {{Filename|mpd-icecast.error}}, and so on); using the same directory paths for the music and playlist directories would ensure that this second mpd daemon would use the same music collection as your first one (e.g., creating and editing a playlist under the first daemon would affect the second daemon as well, so that you don't have to create the same playlists all over again for the second daemon). Then, call this second daemon the same way from your {{Filename|~/.xinitrc}} above. (Just be sure to have a different port number, so as to not conflict with your first mpd daemon).<br />
<br />
==Clients==<br />
Install a client program for MPD. Popular options are:<br />
<br />
===Console===<br />
* '''mpc''' &ndash; Command Line Client (you'll probably want this one no matter what)<br />
# pacman -S mpc<br />
* [http://mpd.wikia.com/wiki/Client:Ncmpc/ ncmpc] &ndash; NCurses Client (this one is very handy for running in a console)<br />
# pacman -S ncmpc<br />
* [http://unkart.ovh.org/ncmpcpp/ ncmpcpp] &ndash; Clone of ncmpc with some new features written in C++<br />
# pacman -S ncmpcpp<br />
* [http://pms.sourceforge.net/ pms] &ndash; NCurses Client (highly configurable and accessible)<br />
Install [http://aur.archlinux.org/packages.php?ID=24378 pmus] from the [[AUR]].<br />
<br />
===Graphical===<br />
* [http://ario-player.sourceforge.net ario] &ndash; GTK+ Client with a Rhythmbox like library browser<br />
# pacman -S ario<br />
* [http://gmpcwiki.sarine.nl/index.php?title=GMPC gmpc] &ndash; GNOME Client<br />
# pacman -S gmpc<br />
* [http://bitcheese.net/wiki/QMPDClient QMPDClient] &ndash; Client written with Qt 4.x.<br />
# pacman -S qmpdclient<br />
* [http://sonata.berlios.de/ sonata] &ndash; Python GTK+ Client<br />
# pacman -S sonata<br />
* [http://aur.archlinux.org/packages.php?ID=33380 dmpc] &ndash; Dmenu-based MPC client with a playlist manager and state-saving on playlist changes<br />
Install [http://aur.archlinux.org/packages.php?ID=33380 dmpc] from the [[AUR]].<br />
<br />
See a long list of clients at the [http://mpd.wikia.com/wiki/Clients mpd wiki].<br />
<br />
==Extra stuff==<br />
===Last.fm scrobbling===<br />
To scrobble your songs to [http://www.last.fm Last.fm] using MPD there are several alternatives.<br />
<br />
====mpdscribble====<br />
mpdscribble is another daemon, available in the "community" repository (if you prefer, the "git" version is available in the [http://aur.archlinux.org/packages.php?ID=22274 AUR]). This is arguably the best alternative, because it's the semi-official MPD scrobbler and uses the new "idle" feature in MPD for more accurate scrobbling. Also, you don't need root access to configure it, because it doesn't need any changes to <tt>/etc</tt> at all. Visit [http://mpd.wikia.com/wiki/Client:Mpdscribble the official website] for more information.<br />
<br />
After you have installed mpdscribble, do the following (not as root):<br />
<br />
* {{Codeline|$ mkdir ~/.mpdscribble}}<br />
* Create the file {{Filename|~/.mpdscribble/mpdscribble.conf}} and add the following:<br />
<pre><br />
[mpdscribble] <br />
host = <your mpd host> # optional, defaults to $MPD_HOST or localhost<br />
port = <your mpd port> # optional, defaults to $MPD_PORT or 6600<br />
log = /home/<YOUR_USERNAME>/.mpdscribble/mpdscribble.log<br />
verbose = 2<br />
sleep = 1<br />
musicdir = <your music directory><br />
proxy = <your proxy> # optional, e. g. http://your.proxy:8080, defaults to none<br />
<br />
[last.fm]<br />
# last.fm section, comment if you don't use last.fm<br />
url = http://post.audioscrobbler.com/<br />
username = <your last.fm username><br />
password = <your last.fm password> # md5sum also possible: echo -n 'PASSWORD' | md5sum | cut -f 1 -d " "<br />
journal = /home/<YOUR_USERNAME>/.mpdscribble/lastfm.journal<br />
<br />
[libre.fm]<br />
# libre.fm section, comment if you don't use libre.fm<br />
url = http://turtle.libre.fm/<br />
username = <your libre.fm username><br />
password = <your libre.fm password> # md5sum also possible: echo -n 'PASSWORD' | md5sum | cut -f 1 -d " "<br />
journal = /home/<YOUR_USERNAME>/.mpdscribble/librefm.journal<br />
</pre><br />
* Add {{Codeline|mpdscribble}} to your {{Filename|~/.xinitrc}}:<br />
pidof mpdscribble >& /dev/null<br />
if [ $? -ne 0 ]; then<br />
mpdscribble &<br />
fi<br />
<br />
====Sonata & Ario====<br />
The easiest way, if you don't care about having to have a program window open all the time, is using Sonata or Ario which are graphical frontends to MPD. They have built-in support for Last.fm scrobbling in their preferences. A downside of this is that Sonata doesn't cache your songs if for some reason you don't happen to have an Internet connection at the time of playing.<br />
<br />
====lastfmsubmitd====<br />
lastfmsubmitd is a daemon which is available in the "community" repository. To install it, first edit {{Filename|/etc/lastfmsubmitd.conf}} and add both {{Codeline|lastfmsubmitd}} and {{Codeline|lastmp}} to the {{Codeline|DAEMONS}} array in {{Filename|/etc/rc.conf}}.<br />
<br />
===Last.fm playback===<br />
<br />
==Last.fm playback with lastfmproxy==<br />
lastfmproxy is a python script that streams a last.fm music stream to another media player. To setup, install [http://aur.archlinux.org/packages.php?ID=14214 lastfmproxy] from the [[AUR]] and then edit {{Filename|/usr/share/lastfmproxy/config.py}}. If you plan to only stream to MPD on the same host, just edit the login info.<br />
<br />
{{Note | Since it installs to a read only directory but it requires read/write access for features like saving previously listened to stations, it would be wise to copy {{Filename|/usr/share/lastfmproxy}} to your home directory.}}<br />
<br />
Start lastfmproxy with {{Codeline|lastfmproxy}} and visit http://localhost:1881/ in your web browser. To add a last.fm station navigate to http://localhost:1881/ followed by the lastfm:// url. Example: http://localhost:1881/lastfm://globaltags/punk . Navigate back to http://localhost:1881/ and download the m3u file by selecting the ''Start Listening'' link. Simply add it to your music library path.<br />
<br />
==Native Last.fm playback==<br />
Since 0.16 mpd has a very well working method to play back last.fm streams.<br />
{{File|name=/etc/mpd.conf|content=<br />
$ playlist_plugin {<br />
name "lastfm"<br />
user "my_username"<br />
password "my_password"<br />
}<br />
}}<br />
Then use e.g. mpc to load streams<br />
$ mpc load "lastfm://artist/Beatles"<br />
<br />
===Never play on start===<br />
<br />
This feature has recently been added to mpd git by Martin Kellerman, see commits b57330cf75bcb339e3f268f1019c63e40d305145 and 2fb40fe728ac07574808c40034fc0f3d2254d49d.<br />
<br />
====[https://aur.archlinux.org/packages.php?ID=19676 mpd-git] Method====<br />
This is the best method currently available, but is only currently (April 2011) enabled in the git version. Install [https://aur.archlinux.org/packages.php?ID=19676 mpd-git] from the [[AUR]], then add {{Codeline|restore_paused "yes"}} to your {{Filename|mpd.conf}} file.<br />
<br />
If you have issues with connecting your client to [https://aur.archlinux.org/packages.php?ID=19676 mpd-git], see [[Music Player Daemon#Other issues when attempting to connect to mpd with a client]].<br />
<br />
====Method 1====<br />
If you don't want MPD to always play on your system start, but yet you want to preserve the other state information, add the following lines to your {{Filename|/etc/rc.d/mpd}} file:<br />
'' ...''<br />
'' stat_busy "Starting Music Player Daemon"''<br />
<br />
# always start in paused state<br />
awk '/^state_file[ \t]+"[^"]+"$/ {<br />
match($0, "\".+\"")<br />
sfile = substr($0, RSTART + 1, RLENGTH - 2)<br />
} /^user[ \t]+"[^"]+"$/ {<br />
match($0, "\".+\"")<br />
user = substr($0, RSTART + 1, RLENGTH - 2)<br />
} END {<br />
if (sfile == "")<br />
exit;<br />
if (user != "")<br />
sub(/^~/, "/home/" user, sfile)<br />
system("sed -i \x27s|^\\(state:[ \\t]\\{1,\\}\\)play$|\\1pause|\x27 \x27" sfile "\x27")<br />
}' /etc/mpd.conf<br />
<br />
'' /usr/bin/mpd /etc/mpd.conf &> /dev/null''<br />
'' ...''<br />
<br />
This will change the player status to "paused", if it was stopped while playing. Next, you want this file to be preserved, so MPD updates won't erase this edit. Add (or edit) this line to your {{Filename|/etc/pacman.conf}}:<br />
NoUpgrade = etc/rc.d/mpd<br />
<br />
====Method 2====<br />
<br />
Another simpler method, would be to add mpd to your {{Filename|[[rc.conf]]}} deamons array and add {{Codeline|mpc stop}} or {{Codeline|mpc pause}} to {{Filename|/etc/rc.local.shutdown}} and to {{Filename|/etc/rc.local}}. (Remember you must have mpc installed to use this method).<br />
<br />
Adding only the order in {{Filename|/etc/rc.local}} cannot assure that mpd will play absolutely nothing, since there may be a delay before the stop command is executed. <br />
On the other hand, if you only add the order to {{Filename|/etc/rc.local.shutdown}}, that will assure that mpd won't play at all, as long as you properly shutdown your system.<br />
Even though they are redundant, adding it to {{Filename|/etc/rc.local}} would serve as a safety for those, presumably, rare occasions when you do not shutdown the system properly.<br />
<br />
====Method 3====<br />
<br />
The general idea between this method is to ask mdp to pause music when user logs out so that during next restart, mdp will stick to that "pause" state. Sending such command can be achieve using [http://www.archlinux.org/packages/extra/x86_64/mpc/ mpc], the command line interface to MPD:<br />
pacman -S mpc<br />
<br />
GDM users can then add the next line to /etc/gdm/PostSession/Default (be sure to add it before "exit 0"):<br />
/usr/bin/mpc pause<br />
<br />
Non-GDM users can use their own login manager's method to launch the line at logout.<br />
<br />
===MPD & ALSA===<br />
Sometimes, when you use other audio output, e.g: some web pages containing Flash applets, MPD cannot reproduce anything anymore (until you restart). The error looks something like: (if you search the file {{Filename|/var/log/mpd/mpd.error}})<br />
<br />
Error opening alsa device "hw:0,0": Device or resource busy<br />
<br />
And here is the solution (dmix saving our life again). Apply these lines in your {{Filename|/etc/mpd.conf}}:<br />
<br />
<pre><br />
audio_output {<br />
type "alsa"<br />
name "Sound Card"<br />
options "dev=dmixer"<br />
device "plug:dmix"<br />
}<br />
</pre><br />
<br />
And then restart with {{Codeline|/etc/rc.d/mpd restart}}.<br />
<br />
Searching on Internet I found the reason for why that happens in Gentoo's wiki:<br />
* The sound card does not support hardware mixing (uses '''dmix''' plugin)<br />
* An application does not work with ALSA with it's default settings<br />
<br />
For a detailed description, it is recommended to take a look at [http://mpd.wikia.com/wiki/Alsa this] link. There you can find an example asound.conf which worked for me right out of the box.<br />
<br />
====High CPU usage with ALSA====<br />
When using MPD with ALSA, users may experience MPD taking up lots of CPU (around 20-30%). This is caused by most sound cards supporting 48kHz and most music being 44kHz, thus forcing MPD to resample it. This operation takes lots of CPU cycles and results into high usage.<br />
<br />
For most users the problem should be solved by telling MPD not to use resampling by adding {{Codeline|auto_resample "no"}} into audio_output-part of {{Filename|/etc/mpd.conf}}. This will degrade quality slightly, however.<br />
<br />
Example from {{Filename|mpd.conf}}:<br />
<br />
audio_output {<br />
type "alsa"<br />
name "My ALSA Device"<br />
auto_resample "no"<br />
}<br />
<br />
Although it may not give as drastic a speedup, enabling mmap may speed things up:<br />
<br />
audio_output {<br />
type "alsa"<br />
name "My ALSA Device"<br />
use_mmap "yes"<br />
}<br />
<br />
Some users might also want to tell dmix to use 44kHz as well. More info about tuning performance of your MPD can be found from: [http://mpd.wikia.com/wiki/Tuning MPD wiki]<br />
<br />
====Example configuration: Output with 44.1 KHz at e. g. 16 bit depth, multiple programs at once====<br />
<br />
''Why these formats?'' Because they are standard CDA, because ALSA on its own allows more than one program "to sound" only with dmix — whose resampling algorithm is inferior — and because dmix by default resamples anything lower to 48 KHz (or whatever higher format is playing at the time). Also, some get clicking sounds if at least {{Filename|mpd.conf}} is not changed this way.<br />
<br />
''What's the downside?'' These settings cause ''everything'' (if necessary) to be resampled to this format, such as material from DVD or TV which usually is at 48 KHz. But there is no known way to have ALSA dynamically change the format, and particularly if you listen to far more CDs than anything else the occasional 48 → 44.1 isn't too great a loss.<br />
<br />
The following assumes that there are not already other settings which conflict resp. overwrite it. This applies especially to the current user's potential {{Filename|~/.asoundrc}} — which MPD as its own user ignores, therefore the following should go to {{Filename|/etc/asound.conf}}:<br />
<br />
{{File|name=/etc/asound.conf|content=<br />
defaults.pcm.dmix.rate 44100 # Force 44.1 KHz<br />
defaults.pcm.dmix.format S16_LE # Force 16 bits<br />
}}<br />
<br />
{{File|name=/etc/mpd.conf|content=<br />
audio_output {<br />
type "alsa" # Use the ALSA output plugin.<br />
name "HDA Intel" # Can be called anything or nothing tmk, but must be present.<br />
options "dev=dmixer"<br />
device "plug:dmix" # Both lines cause MPD to output to dmix.<br />
format "44100:16:2" # the actual format<br />
auto_resample "no" # This bypasses ALSA's own algorithms, which generally are inferior. See below how to choose a different one.<br />
use_mmap "yes" # Minor speed improvement, should work with all modern cards.<br />
}<br />
<br />
samplerate_converter "0" # MPD's best, most CPU intensive algorithm. See 'man mpd.conf' for others — for anything other than the poorest "internal", libsamplerate must be installed.<br />
}}<br />
<br />
{{Note|MPD gives the mp3 format a special treatment at decoding: It's always outputted as 24 bit. (The conversion as forced by the ''format'' line only comes after that.)}}<br />
<br />
If one wants to leave the bit depth decision to ALSA resp. MPD, comment out resp. omit the ''dmix.format'' line and change the one for mpd with ''format'' to "44100:*:2".<br />
<br />
{{Note|''Crossfading'' between files decoded at two different bit depths (say, one mp3 and one 16 bit flac) does not work unless conversion is active.}}<br />
<br />
===Control MPD with lirc===<br />
There are already some clients designed for communications between lircd and MPD, however, as far as the practical use, they aren't very useful since their functions are limited.<br />
<br />
It's recommended to use mpc with irexec. mpc is a command line player which only sends the command to MPD and exits immediately, which is perfect for irexec, the command runner included in lirc. What irexec does is that it runs a specified command once received a remote control button.<br />
<br />
First of all, please setup your remotes as referred to the '''[[Lirc]]''' article.<br />
<br />
Edit your favored lirc startup configuration file, default location is {{Filename|~/.lircrc}}.<br />
<br />
Fill the file with the following pattern:<br />
begin<br />
prog = irexec<br />
button = <button_name><br />
config = <command_to_run><br />
repeat = <0 or 1><br />
end<br />
<br />
An useful example:<br />
## irexec<br />
begin<br />
prog = irexec<br />
button = play_pause<br />
config = mpc toggle<br />
repeat = 0<br />
end<br />
<br />
begin<br />
prog = irexec<br />
button = stop<br />
config = mpc stop<br />
repeat = 0<br />
end<br />
begin<br />
prog = irexec<br />
button = previous<br />
config = mpc prev<br />
repeat = 0<br />
end<br />
begin<br />
prog = irexec<br />
button = next<br />
config = mpc next<br />
repeat = 0<br />
end<br />
begin<br />
prog = irexec<br />
button = volup<br />
config = mpc volume +2<br />
repeat = 1<br />
end<br />
begin<br />
prog = irexec<br />
button = voldown<br />
config = mpc volume -2<br />
repeat = 1<br />
end<br />
begin<br />
prog = irexec<br />
button = pbc<br />
config = mpc random<br />
repeat = 0<br />
end<br />
begin<br />
prog = irexec<br />
button = pdvd<br />
config = mpc update<br />
repeat = 0<br />
end<br />
begin<br />
prog = irexec<br />
button = right<br />
config = mpc seek +00:00:05<br />
repeat = 0<br />
end<br />
begin<br />
prog = irexec<br />
button = left<br />
config = mpc seek -00:00:05<br />
repeat = 0<br />
end<br />
begin<br />
prog = irexec<br />
button = up<br />
config = mpc seek +1%<br />
repeat = 0<br />
end<br />
begin<br />
prog = irexec<br />
button = down<br />
config = mpc seek -1%<br />
repeat = 0<br />
end<br />
<br />
There are more functions for mpc, run {{Codeline|man mpc}} for more info.<br />
<br />
===Control MPD with bluetooth phone===<br />
You can also control MPD (to a certain extent) using a bluetooth enabled phone. You need to do the following:<br />
<br />
* install [http://remuco.sourceforge.net/index.php/Remuco remuco] -- a wireless remote control for several Linux media players ([http://aur.archlinux.org/packages.php?ID=25072 aur])<br />
* transfer remuco client -- jar/jad files from {{Filename|/usr/share/remuco/client/}} to your phone and install it<br />
* run {{Codeline|remuco-mpd}} (as current user)<br />
* run remuco on your phone, define a new bluetooth remuco connection (pair first if you haven't done this previously) and explore its capabilities<br />
<br />
More information about remuco including troubleshooting to be found at its [http://remuco.sourceforge.net/index.php/Remuco homepage]<br />
<br />
===MPD & PulseAudio===<br />
<br />
Edit {{Filename|/etc/mpd.conf}}, and uncomment the audio_output section for the type "pulse". The server and sink lines of it should be commented unless you know what you're doing.<br />
<br />
Then, add the mpd user (and yours if you haven't done so already) to the necessary pulse groups. The pulse-access group should be sufficient but you may want to add pulse-rt as well. The group "pulse" doesn't appear to be necessary.<br />
# gpasswd -a mpd pulse-access<br />
# gpasswd -a mpd pulse-rt<br />
<br />
Lastly, you may or may not need to copy {{Filename|~/.pulse-cookie}} from your current (pulse working) user's dir to your mpd user's home directory. It is likely to be {{Filename|/var/lib/mpd}} if you followed the first part of this wiki. This would probably only allow your current user to listen in on MPD's pulse. You may consider running pulse system-wide if that's insufficient.<br />
<br />
===Cue Files===<br />
<br />
To make cue file support actually work, you have to work around a nasty libcue bug. Libcue copied some files directly from libcdio, making it conflict with it. Steps to do to get proper cue support:<br />
<br />
* remove libcdio temporary (pacman -Rdd libcdio)<br />
* install libcue (pacman -S libcue)<br />
* install mpd with abs or from aur.<br />
* reinstall libcdio (pacman -S libcdio)<br />
<br />
At the point of writing mpd does not parse tracknumbers from cue sheets. There is a patch available (http://musicpd.org/mantis/view.php?id=3230)<br />
Once this patch is merged into mpd, i will remove this line :)<br />
<br />
==Troubleshooting==<br />
===Autodetection failed===<br />
During the start of MPD, it tries to autodetect your set-up and configure output and volume control accordingly. Though this mostly goes well, it will fail for some systems. It may help to tell MPD specifically what to use as output and mixer control. If you copied {{Filename|/etc/mpd.conf}} over from {{Filename|/etc/mpd.conf.example}} as mentioned above, you can simply uncomment:<br />
<br />
Example for alsa output type and alsa mixer:<br />
audio_output {<br />
type "alsa"<br />
name "My ALSA Device"<br />
device "hw:0,0" # optional<br />
format "44100:16:2" # optional<br />
mixer_type "hardware"<br />
mixer_device "default"<br />
mixer_control "PCM"<br />
}<br />
<br />
'''Note:''' in case of permission problems when using ESD with MPD run this as root:<br />
# chsh -s /bin/true mpd<br />
<br />
===Executable permissions===<br />
{{Warning|This is not good security practice and may be unnecessary.}}<br />
<br />
MPD needs to have +x permissions on '''ALL''' parent directories to your music collection (ie. if it's located outside of "mpd" home directory /var/lib/mpd). By default useradd sets permissions on home dir to 1700 drwx------. So if you're like me you will need to change permissions of /home/user. Example... my music collection is located /home/user/music. <br />
# chmod a+x /home/$USER<br />
# chmod -R a+X /home/$USER/music<br />
<br />
====Alternative solution====<br />
An alternative solution would be to use your group to share a selection of files, among them your music library. First remove all permissions for the group then add group permissions to read and execute home and music.<br />
# chmod -R g-rwx /home/$USER<br />
# chmod g+rx /home/$USER<br />
# chmod -R g+rX /home/$USER/music<br />
<br />
====Another alternative solution====<br />
Another alternative is to remount the music directory under a directory that mpd has access to. This does not entail the same security risks as modifying the permissions on one's home directory.<br />
# mkdir /var/lib/mpd/music<br />
# echo "/home/$USER/music /var/lib/mpd/music none bind" >> /etc/fstab<br />
# mount -a<br />
# /etc/rc.d/mpd restart<br />
And that should fix the problem. See also [https://bbs.archlinux.org/viewtopic.php?id=86449 the forum thread.]<br />
<br />
===Avoiding timeouts===<br />
To get rid of timeouts (i.e. when you paused music for long time) in gpmc and other clients uncomment and increase {{Codeline|connection_timeout}} option in {{Filename|mpd.conf}}.<br />
<br />
If files and/or titles are shown in wrong encoding, uncomment and change {{Codeline|filesystem_charset}} and {{Codeline|id3v1_encoding}} options.<br />
Note that you cannot set encoding for ID3 v2 tags. To workaround this you may use [http://mpd.wikia.com/wiki/GenericDecoder#Generic_Tagreader external tag readers].<br />
<br />
If you want to use another computer to control MPD over a network, the {{Codeline|bind_to_address}} option in {{Filename|mpd.conf}} will need to be set to either your IP address, or {{Codeline|any}} if your IP address changes frequently. <br />
<br />
'''Streaming'''<br><br />
With the latest version of MPD (0.15), built-in httpd streaming is now available.<br />
<br />
To activate this feature, you'll just need to add a new output of type httpd in {{Filename|mpd.conf}}:<br />
audio_output {<br />
type "httpd"<br />
name "What you want"<br />
encoder "lame" # vorbis or lame supported<br />
port "8000"<br />
bitrate "128"<br />
format "44100:16:2" # change 2 to 1 for mono<br />
}<br />
<br />
Restart the mpd deamon and, from another computer, simply load the stream as any other url. <br />
$ mplayer http://<server's IP>:8000<br />
<br />
{{Note | You must open the port on your router / firewall for the stream to be connectible to from another computer.}}<br />
<br />
Most players (i.e. vlc or xmms2) should also be able to load the stream via their "add url..." menu option.<br />
<br />
This is a nice clean way to replace your current icecast setup with something natively supported within MPD.<br />
<br />
===mpd hangs on first startup===<br />
This is a common error that's caused by corrupt mp3 tags.<br />
Here is an experimental way to solve this issue.<br />
Requirements:<br />
* kid3<br />
* easytag<br />
<br />
This method is very tedious, especially with a huge database. Just as a baseline it took 2.5h to fix a 16Gb DB.<br />
<br />
====Easy Tag====<br />
The purpose of easytag here is that easytag detects the error in the tags, but like MPD it hangs and dies. The trick here is that easy tags actually tells you what file is causing the problem on the status bar.<br />
Before starting easytag make sure to have a terminal close to be ready to kill easy tag to avoid a hang. Once you are ready, on the tree view select the directory where all your music is located. By default easytag starts to search all subdirectories for mp3 files. Once you notice that easytag stopped scanning for songs, make note of the culprit and kill easytag.<br />
<br />
====KID3====<br />
Here's where kid3 comes in handy. With kid3 go to the offending song and rewrite one of the tags. then save the file. This should force kid3 to rewrite the whole tag again fixing the problem with MPD and easy tag hanging.<br />
<br />
Repeat this procedure until your music library is done.<br />
<br />
===Cannot connect to mpd: host "localhost" not found: Temporary failure in name resolution===<br />
Cannot connect to MPD (with ncmpcpp), if you are disconnected from network. Solution is [[IPv6 - Disabling the Module|disable IPv6]] or add line to /etc/hosts<br />
::1 localhost.localdomain localhost<br />
<br />
===Other issues when attempting to connect to mpd with a client===<br />
Some have reported being unable to access mpd with various clients, for example seeing errors like these:<br />
$ ncmpcpp<br />
Cannot connect to mpd: Connection closed by the server<br />
$ sonata<br />
2011-02-13 18:33:05 Connection lost while reading MPD hello<br />
2011-02-13 18:33:05 Not connected<br />
2011-02-13 18:33:05 Not connected<br />
<br />
Please see posts on ncmpcpp on the Arch Forums [https://bbs.archlinux.org/viewtopic.php?id=109962 HERE] and [https://bbs.archlinux.org/viewtopic.php?id=113493 HERE]. Also see the Arch bug report on this issue [https://bugs.archlinux.org/task/22071 HERE]. <br />
<br />
====First fix====<br />
Check {{Filename|mpd.conf}} for a line like {{Codeline|mpd.error}} and remove it. The mpd error file is deprecated and has been removed.<br />
<br />
====Second fix====<br />
{{Note|I'm not so sure this is a good idea. There is a warning about changing the address to bind to in the default mpd.conf. If this does not help, you might want to comment out the changes.}}<br />
If that doesn't help, add the following to {{Filename|mpd.conf}}:<br />
<pre><br />
bind_to_address "127.0.0.1"<br />
port "6600"<br />
</pre><br />
<br />
Afterwards, instruct your client to connect via 127.0.0.1. For example, add the following to the ncmpcpp config file:<br />
<pre><br />
mpd_host "127.0.0.1"<br />
mpd_port "6600"<br />
</pre><br />
<br />
<br />
===Port 6600 already in use===<br />
MPD needs to bind to port 6600 and cannot start if it's already in use. The most common reason for this is that the user has started MPD once and then subsequently tried to start mpd again. In general, nothing should be done here.<br />
<br />
If port 6600 is tied up for some other reason, one can use the following command to find the offending process:<br />
# netstat -tulpan | grep 6600<br />
<br />
This will list IP:Port and the process name holding the connection (root privileges are required to see all processes).<br />
<br />
If you need to restart mpd for whatever reason, use:<br />
<pre><br />
$ mpd --kill<br />
$ mpd <br />
</pre><br />
A more brute-force approach:<br />
<pre><br />
$ killall mpd<br />
$ mpd <br />
</pre><br />
{{Note| If you typically run MPD as root, you will need to run the above commands as root.}}<br />
<br />
In the latest version of MPD, --create-db is completely deprecated. The database will be created automagically on first run and can subsequently be updated via your client (i.e. mpc update). You can now use inotify support to automatically update your music database. Add the following to {{File|name=mpd.conf|content=auto_update "yes"}} to enable it.<br />
<br />
===Binding to IPV6 before IPV4===<br />
If on startup, you see this message:<br />
listen: bind to '0.0.0.0:6600' failed: Address already in use (continuing anyway, because binding to '[::]:6600' succeeded)<br />
MPD is attempting to bind to the ipv6 interface before binding to ipv4. If you want to use your ipv4 interface, hardcode it in mpd.conf, like so:<br />
bind_to_address "127.0.0.1"<br />
Or, you could specify several binds, for example, to have MPD listen on localhost and the external IP of your network card:<br />
bind_to_address "127.0.0.1"<br />
bind_to_address "192.168.1.13"<br />
<br />
===Crackling sound with some audio files===<br />
This is usually a playback speed problem and can be fixed by uncommenting the audio_output_format line in:<br />
<br />
{{File|name=/etc/mpd.conf|content=<br />
audio_output_format "44100:16:2"}}<br />
<br />
This is usually a sane value for most mp3 files.<br />
<br />
===daemon: cannot setgid for user "mpd": Operation not permitted ===<br />
<br />
The error is stating that the user starting the process (you) does not have permissions to become another user (mpd) which the configuration has told that process to run as.<br />
<br />
To solve the issue, simply start mpd as root.<br />
su -c "/etc/rc.d/mpd start"<br />
or<br />
sudo /etc/rc.d/mpd start<br />
<br />
==External links==<br />
* [http://www.musicpd.org/ Official Web Site]<br />
* [http://mpd.wikia.com/wiki/Main_Page Official Wiki]<br />
* [http://mpd.wikia.com/wiki/Clients Sorted List of MPD Clients]<br />
* [http://www.musicpd.org/forum/ MPD forum]</div>Rasihttps://wiki.archlinux.org/index.php?title=Music_Player_Daemon&diff=150764Music Player Daemon2011-08-06T01:09:16Z<p>Rasi: /* Native Last.fm playback */</p>
<hr />
<div>[[fr:MPD]]<br />
[[Category:Audio/Video (English)]]<br />
[[Category:Daemons and system services (English)]]<br />
{{i18n|Music Player Daemon}}<br />
[[pl:Music Player Daemon]]<br />
<br />
'''MPD''' (music player daemon) is an audio player that has a server-client architecture. MPD runs in the background as a daemon, manages playlists and a music database, and uses very few resources. In order to interface with it, you need a separate client. More information can be found on their [http://www.musicpd.org/ website].<br />
<br />
''Please'' have a look at the official page for setup and troubleshooting instructions, the main developer called our wiki page in its current state ''"full of symptom killers"'', hence the official pages should contain better instructions.<br />
<br />
==Installing mpd==<br />
Install with [[pacman]]:<br />
# pacman -S mpd<br />
<br />
==Daemon Setup: Starting at Boot==<br />
General information about MPD configuration may be found at http://mpd.wikia.com/wiki/Configuration.<br />
<br />
===Sound setup===<br />
To make audio output actually work ensure that you have setup audio card and mixer correctly. See [[ALSA]], and [[PulseAudio]] if you are using Gnome 3. Do not forget to unmute the required channels in alsamixer, raise the volume and save changes with alsactl store. Run mpd with {{Filename|/usr/bin/mpd --stdout --no-daemon --verbose}} if that still doesn't work.<br />
<br />
Make sure your card can do hardware mixing (most of them can, including onboard audio). Or else this could cause problems with multiple sound playback. For example, this can prevent Mplayer from playing back sound while the mpd daemon is running, returning an audio error message stating the device is busy.<br />
<br />
===Timeline of MPD's behavior on a typical working setup when started as a daemon===<br />
# MPD is started on boot by {{Filename|/etc/rc.conf}}, by including it in the {{Codeline|DAEMONS}} array. (Or, this can be done manually each session by running {{Codeline|/etc/rc.d/mpd start}} with root privileges).<br />
# Since MPD is now started as root, it first reads the {{Filename|/etc/mpd.conf}} file.<br />
# MPD reads the user variable in the {{Filename|/etc/mpd.conf}} file, and changes from root to this user.<br />
# MPD then reads the contents of the {{Filename|/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 {{Filename|/etc/mpd.conf}} file. This way, uses of {{Codeline|~}} in the configuration file point correctly to the home user's directory, and not root's directory. It may be worthwhile to change all uses of {{Codeline|~}} to {{Codeline|/home/username}} to avoid any confusion over this aspect of MPD's behavior.<br />
<br />
===A clean configuration file===<br />
* As root, check if {{Filename|/etc/mpd.conf}} exists and delete the file if it does. This is safe.<br />
<br />
MPD comes with an example configuration file, available at {{Filename|/usr/share/mpd/mpd.conf.example}}. This file holds an abundance of information on MPD configuration, and holds default mixer values you can simply uncomment.<br />
<br />
* As root, copy this example file to {{Filename|/etc/mpd.conf}}.<br />
# cp /usr/share/mpd/mpd.conf.example /etc/mpd.conf<br />
({{Filename|/usr/share/mpd/mpd.conf.example}} is good for userspace setup)<br />
<br />
Since MPD is being set up to run as a daemon at boot, never put this file in the user's directory like some tutorials suggest, since it will not be read. Moreover, if you previously created a {{Filename|.mpdconf}} file in your home, remove it now (to set up MPD to run with user privileges alone, pleaser refer to the section [[Music_Player_Daemon#Alternative_Setup:_Starting_as_a_User | Alternative_Setup:_Starting_as_a_User]]). This is important to prevent conflicts. The presence of the configuration file in {{Filename|/etc}}, like is the case here, is what will enable MPD to run as a daemon at boot. Otherwise, a script would be needed to run MPD ''after'' the user has logged (like kdm or {{Filename|~/.fluxbox/startup}}) or it would require a manual move each time. For a single music collection, the method used here is simply better, even while the collection is shared to multiple users. Also, don't be afraid about root privileges: even while MPD runs as a daemon, it never completely runs as root since it automatically drops its root privileges after execution.<br />
<br />
===Edit {{Filename|mpd.conf}}===<br />
<br />
The default arch install keeps the setup in /var and uses "mpd" as default user, instead of cluttering up ~/.<br />
Edit {{Filename|/etc/mpd.conf}} to reflect as such.<br />
<br />
{{File|name=/etc/mpd.conf|content=<br />
music_directory "/home/user/music" # Your music dir.<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 "/var/run/mpd/mpd.pid" # Omit this line for systemd<br />
state_file "/var/lib/mpd/mpdstate"<br />
user "mpd"<br />
# Binding to address and port causing problems in mpd-0.14.2 best to leave<br />
# commented.<br />
# bind_to_address "127.0.0.1"<br />
# port "6600"<br />
}}<br />
<br />
* If your music collection is contained under multiple directories, you can make symbolic links under /var/lib/mpd then set 'music_directory' to the directory holding the symbolic links. Remember to set permissions accordingly on the directories being linked.<br />
<br />
* To change the volume of audio from mpd independent of other programs, uncomment or add the switch in mpd.conf:<br />
<br />
{{File|name=/etc/mpd.conf|content=<br />
mixer_type "software"<br />
}}<br />
<br />
* Lastly, if you are running pulseaudio under Gnome 3, the default setting of "alsa" for the audio output will not work. Make the modification from:<br />
{{File|name=/etc/mpd.conf|content=<br />
audio_output {<br />
type "alsa"<br />
name "Sound Card"<br />
}<br />
}}<br />
<br />
to<br />
<br />
{{File|name=/etc/mpd.conf|content=<br />
audio_output {<br />
type "pulse"<br />
name "Sound Card"<br />
}<br />
}}<br />
<br />
===Create files===<br />
<br />
* As root, create the directories and files you specified in {{Filename|/etc/mpd.conf}}.<br />
# mkdir -p /var/lib/mpd/playlists /var/run/mpd<br />
# touch /var/lib/mpd/{mpd.db,mpdstate} && touch /var/run/mpd/mpd.pid<br />
<br />
* You then need to change the file's permissions so that the daemon can modify them.<br />
# chown -R mpd /var/lib/mpd /var/run/mpd<br />
<br />
===Create database===<br />
<br />
Creating the database is now accomplished via the update feature of the client, for example 'mpc update'. The previous method, creating the MPD database as root (# mpd --create-db), is deprecated.<br />
<br />
==Alternative Setup: Starting as a User==<br />
MPD need not be started with root permissions. The only reason why MPD needs to be started as root (by being called from {{Filename|/etc/rc.conf}}) is because the default files and folders in the default configuration file points to directories owned by root (the /var directory). A less common, but perhaps more sensible, approach is to make MPD work with files and directories owned by a normal user. Running MPD as a normal user has several advantages: <br />
# You can easily have a single directory ~/.mpd (or any other directory under /home/username) for all MPD configuration files<br />
# No read/write permission errors<br />
# More flexible calls to MPD by using {{Filename|~/.xinitrc}} instead of including 'mpd' in the {{Filename|/etc/rc.conf}} DAEMONS array.<br />
<br />
The following steps shows how to run MPD as a normal user. '''Note''': this approach will not work if you want multiple users to have access to MPD.<br />
<br />
* Copy the contents of the default MPD configuration file in {{Filename|/usr/share/mpd/mpd.conf.example}} to your home directory. A good place would be {{Filename|"/home/user/.mpd/mpd.conf"}}.<br />
* Follow the 'old setup instructions' from above, ignoring the first part about copying the config to {{Filename|/etc/mpd.conf}} and do not set a user variable. <br />
* Create all of the requisite files in {{filename|"/home/user/.mpd/"}}:<br />
"~/.mpd/playlists/"<br />
"~/.mpd/db"<br />
"~/.mpd/mpd.db"<br />
"~/.mpd/mpd.log"<br />
"~/.mpd/mpd.error"<br />
"~/.mpd/mpd.pid"<br />
"~/.mpd/mpdstate"<br />
<br />
* Let MPD start on bootup by calling it from your {{Filename|~/.xinitrc}} as follows:<br />
# this starts mpd as normal user<br />
mpd ~/.mpd/mpd.conf<br />
{{Note| that you don't have to put a "&" at the end of the line here, since MPD will automatically daemonize itself.}}<br />
<br />
Lastly, delete the entry 'mpd' from your DAEMONS array in {{Filename|/etc/rc.conf}}, as you are not running it as root anymore.<br />
<br />
===Quick setup===<br />
<br />
The fastest way to do set up the structure is to do this:<br />
<br />
$ mkdir -p ~/.mpd/playlists && touch ~/.mpd/database && cp /usr/share/doc/mpd/mpdconf.example ~/.mpd/mpd.conf<br />
<br />
Then edit mpd.conf to your liking, in a manner similar to [[Music_Player_Daemon#Edit_mpd.conf]]. Beware that you must uncomment the db_file entry if you do edit mpd.conf.<br />
<br />
Then, to run it:<br />
<br />
$ mpd ~/.mpd/mpd.conf<br />
<br />
<br />
===Even quicker setup===<br />
I created a little script that will only ask for the location of your music and then creates the needed files and folders for you.<br />
You can find the script here:<br />
[http://karif.server-speed.net/~carnager/mpdsetup.tar]<br />
extract it<br />
$ tar xf mpdsetup.tar<br />
and run it<br />
$ ./mpdsetup.sh<br />
<br />
If you want to use this config in daemon mode, open it (~/.mpdconf) in an editor and find the "user" line. remove the comment (#) and fill in your own user name. Then copy the file to /etc/mpd.conf. If running mpd as user is fine for you, make sure to remove "mpd" from the daemons list in /etc/rc.conf<br />
<br />
===Multi-mpd setup===<br />
'''Useful if you want to run for example an icecast server.'''<br />
If you want a second MPD daemon (e.g., with icecast output to share music over the network) to use the same music and playlist as the one above, simply copy the above configuration file and make a new file (e.g., {{Filename|/home/username/.mpd/config-icecast}}), and only change the log_file, error_file, pid_file, and state_file parameters (e.g., {{Filename|mpd-icecast.log}}, {{Filename|mpd-icecast.error}}, and so on); using the same directory paths for the music and playlist directories would ensure that this second mpd daemon would use the same music collection as your first one (e.g., creating and editing a playlist under the first daemon would affect the second daemon as well, so that you don't have to create the same playlists all over again for the second daemon). Then, call this second daemon the same way from your {{Filename|~/.xinitrc}} above. (Just be sure to have a different port number, so as to not conflict with your first mpd daemon).<br />
<br />
==Clients==<br />
Install a client program for MPD. Popular options are:<br />
<br />
===Console===<br />
* '''mpc''' &ndash; Command Line Client (you'll probably want this one no matter what)<br />
# pacman -S mpc<br />
* [http://mpd.wikia.com/wiki/Client:Ncmpc/ ncmpc] &ndash; NCurses Client (this one is very handy for running in a console)<br />
# pacman -S ncmpc<br />
* [http://unkart.ovh.org/ncmpcpp/ ncmpcpp] &ndash; Clone of ncmpc with some new features written in C++<br />
# pacman -S ncmpcpp<br />
* [http://pms.sourceforge.net/ pms] &ndash; NCurses Client (highly configurable and accessible)<br />
Install [http://aur.archlinux.org/packages.php?ID=24378 pmus] from the [[AUR]].<br />
<br />
===Graphical===<br />
* [http://ario-player.sourceforge.net ario] &ndash; GTK+ Client with a Rhythmbox like library browser<br />
# pacman -S ario<br />
* [http://gmpcwiki.sarine.nl/index.php?title=GMPC gmpc] &ndash; GNOME Client<br />
# pacman -S gmpc<br />
* [http://bitcheese.net/wiki/QMPDClient QMPDClient] &ndash; Client written with Qt 4.x.<br />
# pacman -S qmpdclient<br />
* [http://sonata.berlios.de/ sonata] &ndash; Python GTK+ Client<br />
# pacman -S sonata<br />
* [http://aur.archlinux.org/packages.php?ID=33380 dmpc] &ndash; Dmenu-based MPC client with a playlist manager and state-saving on playlist changes<br />
Install [http://aur.archlinux.org/packages.php?ID=33380 dmpc] from the [[AUR]].<br />
<br />
See a long list of clients at the [http://mpd.wikia.com/wiki/Clients mpd wiki].<br />
<br />
==Extra stuff==<br />
===Last.fm scrobbling===<br />
To scrobble your songs to [http://www.last.fm Last.fm] using MPD there are several alternatives.<br />
<br />
====mpdscribble====<br />
mpdscribble is another daemon, available in the "community" repository (if you prefer, the "git" version is available in the [http://aur.archlinux.org/packages.php?ID=22274 AUR]). This is arguably the best alternative, because it's the semi-official MPD scrobbler and uses the new "idle" feature in MPD for more accurate scrobbling. Also, you don't need root access to configure it, because it doesn't need any changes to <tt>/etc</tt> at all. Visit [http://mpd.wikia.com/wiki/Client:Mpdscribble the official website] for more information.<br />
<br />
After you have installed mpdscribble, do the following (not as root):<br />
<br />
* {{Codeline|$ mkdir ~/.mpdscribble}}<br />
* Create the file {{Filename|~/.mpdscribble/mpdscribble.conf}} and add the following:<br />
<pre><br />
[mpdscribble] <br />
host = <your mpd host> # optional, defaults to $MPD_HOST or localhost<br />
port = <your mpd port> # optional, defaults to $MPD_PORT or 6600<br />
log = /home/<YOUR_USERNAME>/.mpdscribble/mpdscribble.log<br />
verbose = 2<br />
sleep = 1<br />
musicdir = <your music directory><br />
proxy = <your proxy> # optional, e. g. http://your.proxy:8080, defaults to none<br />
<br />
[last.fm]<br />
# last.fm section, comment if you don't use last.fm<br />
url = http://post.audioscrobbler.com/<br />
username = <your last.fm username><br />
password = <your last.fm password> # md5sum also possible: echo -n 'PASSWORD' | md5sum | cut -f 1 -d " "<br />
journal = /home/<YOUR_USERNAME>/.mpdscribble/lastfm.journal<br />
<br />
[libre.fm]<br />
# libre.fm section, comment if you don't use libre.fm<br />
url = http://turtle.libre.fm/<br />
username = <your libre.fm username><br />
password = <your libre.fm password> # md5sum also possible: echo -n 'PASSWORD' | md5sum | cut -f 1 -d " "<br />
journal = /home/<YOUR_USERNAME>/.mpdscribble/librefm.journal<br />
</pre><br />
* Add {{Codeline|mpdscribble}} to your {{Filename|~/.xinitrc}}:<br />
pidof mpdscribble >& /dev/null<br />
if [ $? -ne 0 ]; then<br />
mpdscribble &<br />
fi<br />
<br />
====Sonata & Ario====<br />
The easiest way, if you don't care about having to have a program window open all the time, is using Sonata or Ario which are graphical frontends to MPD. They have built-in support for Last.fm scrobbling in their preferences. A downside of this is that Sonata doesn't cache your songs if for some reason you don't happen to have an Internet connection at the time of playing.<br />
<br />
====lastfmsubmitd====<br />
lastfmsubmitd is a daemon which is available in the "community" repository. To install it, first edit {{Filename|/etc/lastfmsubmitd.conf}} and add both {{Codeline|lastfmsubmitd}} and {{Codeline|lastmp}} to the {{Codeline|DAEMONS}} array in {{Filename|/etc/rc.conf}}.<br />
<br />
===Last.fm playback with lastfmproxy===<br />
lastfmproxy is a python script that streams a last.fm music stream to another media player. To setup, install [http://aur.archlinux.org/packages.php?ID=14214 lastfmproxy] from the [[AUR]] and then edit {{Filename|/usr/share/lastfmproxy/config.py}}. If you plan to only stream to MPD on the same host, just edit the login info.<br />
<br />
{{Note | Since it installs to a read only directory but it requires read/write access for features like saving previously listened to stations, it would be wise to copy {{Filename|/usr/share/lastfmproxy}} to your home directory.}}<br />
<br />
Start lastfmproxy with {{Codeline|lastfmproxy}} and visit http://localhost:1881/ in your web browser. To add a last.fm station navigate to http://localhost:1881/ followed by the lastfm:// url. Example: http://localhost:1881/lastfm://globaltags/punk . Navigate back to http://localhost:1881/ and download the m3u file by selecting the ''Start Listening'' link. Simply add it to your music library path.<br />
<br />
<br />
==Native Last.fm playback==<br />
Since 0.16 mpd has a very well working method to play back last.fm streams.<br />
{{File|name=/etc/mpd.conf|content=<br />
$ playlist_plugin {<br />
name "lastfm"<br />
user "my_username"<br />
password "my_password"<br />
}<br />
}}<br />
Then use e.g. mpc to load streams<br />
$ mpc load "lastfm://artist/Beatles"<br />
<br />
===Never play on start===<br />
<br />
This feature has recently been added to mpd git by Martin Kellerman, see commits b57330cf75bcb339e3f268f1019c63e40d305145 and 2fb40fe728ac07574808c40034fc0f3d2254d49d.<br />
<br />
====[https://aur.archlinux.org/packages.php?ID=19676 mpd-git] Method====<br />
This is the best method currently available, but is only currently (April 2011) enabled in the git version. Install [https://aur.archlinux.org/packages.php?ID=19676 mpd-git] from the [[AUR]], then add {{Codeline|restore_paused "yes"}} to your {{Filename|mpd.conf}} file.<br />
<br />
If you have issues with connecting your client to [https://aur.archlinux.org/packages.php?ID=19676 mpd-git], see [[Music Player Daemon#Other issues when attempting to connect to mpd with a client]].<br />
<br />
====Method 1====<br />
If you don't want MPD to always play on your system start, but yet you want to preserve the other state information, add the following lines to your {{Filename|/etc/rc.d/mpd}} file:<br />
'' ...''<br />
'' stat_busy "Starting Music Player Daemon"''<br />
<br />
# always start in paused state<br />
awk '/^state_file[ \t]+"[^"]+"$/ {<br />
match($0, "\".+\"")<br />
sfile = substr($0, RSTART + 1, RLENGTH - 2)<br />
} /^user[ \t]+"[^"]+"$/ {<br />
match($0, "\".+\"")<br />
user = substr($0, RSTART + 1, RLENGTH - 2)<br />
} END {<br />
if (sfile == "")<br />
exit;<br />
if (user != "")<br />
sub(/^~/, "/home/" user, sfile)<br />
system("sed -i \x27s|^\\(state:[ \\t]\\{1,\\}\\)play$|\\1pause|\x27 \x27" sfile "\x27")<br />
}' /etc/mpd.conf<br />
<br />
'' /usr/bin/mpd /etc/mpd.conf &> /dev/null''<br />
'' ...''<br />
<br />
This will change the player status to "paused", if it was stopped while playing. Next, you want this file to be preserved, so MPD updates won't erase this edit. Add (or edit) this line to your {{Filename|/etc/pacman.conf}}:<br />
NoUpgrade = etc/rc.d/mpd<br />
<br />
====Method 2====<br />
<br />
Another simpler method, would be to add mpd to your {{Filename|[[rc.conf]]}} deamons array and add {{Codeline|mpc stop}} or {{Codeline|mpc pause}} to {{Filename|/etc/rc.local.shutdown}} and to {{Filename|/etc/rc.local}}. (Remember you must have mpc installed to use this method).<br />
<br />
Adding only the order in {{Filename|/etc/rc.local}} cannot assure that mpd will play absolutely nothing, since there may be a delay before the stop command is executed. <br />
On the other hand, if you only add the order to {{Filename|/etc/rc.local.shutdown}}, that will assure that mpd won't play at all, as long as you properly shutdown your system.<br />
Even though they are redundant, adding it to {{Filename|/etc/rc.local}} would serve as a safety for those, presumably, rare occasions when you do not shutdown the system properly.<br />
<br />
====Method 3====<br />
<br />
The general idea between this method is to ask mdp to pause music when user logs out so that during next restart, mdp will stick to that "pause" state. Sending such command can be achieve using [http://www.archlinux.org/packages/extra/x86_64/mpc/ mpc], the command line interface to MPD:<br />
pacman -S mpc<br />
<br />
GDM users can then add the next line to /etc/gdm/PostSession/Default (be sure to add it before "exit 0"):<br />
/usr/bin/mpc pause<br />
<br />
Non-GDM users can use their own login manager's method to launch the line at logout.<br />
<br />
===MPD & ALSA===<br />
Sometimes, when you use other audio output, e.g: some web pages containing Flash applets, MPD cannot reproduce anything anymore (until you restart). The error looks something like: (if you search the file {{Filename|/var/log/mpd/mpd.error}})<br />
<br />
Error opening alsa device "hw:0,0": Device or resource busy<br />
<br />
And here is the solution (dmix saving our life again). Apply these lines in your {{Filename|/etc/mpd.conf}}:<br />
<br />
<pre><br />
audio_output {<br />
type "alsa"<br />
name "Sound Card"<br />
options "dev=dmixer"<br />
device "plug:dmix"<br />
}<br />
</pre><br />
<br />
And then restart with {{Codeline|/etc/rc.d/mpd restart}}.<br />
<br />
Searching on Internet I found the reason for why that happens in Gentoo's wiki:<br />
* The sound card does not support hardware mixing (uses '''dmix''' plugin)<br />
* An application does not work with ALSA with it's default settings<br />
<br />
For a detailed description, it is recommended to take a look at [http://mpd.wikia.com/wiki/Alsa this] link. There you can find an example asound.conf which worked for me right out of the box.<br />
<br />
====High CPU usage with ALSA====<br />
When using MPD with ALSA, users may experience MPD taking up lots of CPU (around 20-30%). This is caused by most sound cards supporting 48kHz and most music being 44kHz, thus forcing MPD to resample it. This operation takes lots of CPU cycles and results into high usage.<br />
<br />
For most users the problem should be solved by telling MPD not to use resampling by adding {{Codeline|auto_resample "no"}} into audio_output-part of {{Filename|/etc/mpd.conf}}. This will degrade quality slightly, however.<br />
<br />
Example from {{Filename|mpd.conf}}:<br />
<br />
audio_output {<br />
type "alsa"<br />
name "My ALSA Device"<br />
auto_resample "no"<br />
}<br />
<br />
Although it may not give as drastic a speedup, enabling mmap may speed things up:<br />
<br />
audio_output {<br />
type "alsa"<br />
name "My ALSA Device"<br />
use_mmap "yes"<br />
}<br />
<br />
Some users might also want to tell dmix to use 44kHz as well. More info about tuning performance of your MPD can be found from: [http://mpd.wikia.com/wiki/Tuning MPD wiki]<br />
<br />
====Example configuration: Output with 44.1 KHz at e. g. 16 bit depth, multiple programs at once====<br />
<br />
''Why these formats?'' Because they are standard CDA, because ALSA on its own allows more than one program "to sound" only with dmix — whose resampling algorithm is inferior — and because dmix by default resamples anything lower to 48 KHz (or whatever higher format is playing at the time). Also, some get clicking sounds if at least {{Filename|mpd.conf}} is not changed this way.<br />
<br />
''What's the downside?'' These settings cause ''everything'' (if necessary) to be resampled to this format, such as material from DVD or TV which usually is at 48 KHz. But there is no known way to have ALSA dynamically change the format, and particularly if you listen to far more CDs than anything else the occasional 48 → 44.1 isn't too great a loss.<br />
<br />
The following assumes that there are not already other settings which conflict resp. overwrite it. This applies especially to the current user's potential {{Filename|~/.asoundrc}} — which MPD as its own user ignores, therefore the following should go to {{Filename|/etc/asound.conf}}:<br />
<br />
{{File|name=/etc/asound.conf|content=<br />
defaults.pcm.dmix.rate 44100 # Force 44.1 KHz<br />
defaults.pcm.dmix.format S16_LE # Force 16 bits<br />
}}<br />
<br />
{{File|name=/etc/mpd.conf|content=<br />
audio_output {<br />
type "alsa" # Use the ALSA output plugin.<br />
name "HDA Intel" # Can be called anything or nothing tmk, but must be present.<br />
options "dev=dmixer"<br />
device "plug:dmix" # Both lines cause MPD to output to dmix.<br />
format "44100:16:2" # the actual format<br />
auto_resample "no" # This bypasses ALSA's own algorithms, which generally are inferior. See below how to choose a different one.<br />
use_mmap "yes" # Minor speed improvement, should work with all modern cards.<br />
}<br />
<br />
samplerate_converter "0" # MPD's best, most CPU intensive algorithm. See 'man mpd.conf' for others — for anything other than the poorest "internal", libsamplerate must be installed.<br />
}}<br />
<br />
{{Note|MPD gives the mp3 format a special treatment at decoding: It's always outputted as 24 bit. (The conversion as forced by the ''format'' line only comes after that.)}}<br />
<br />
If one wants to leave the bit depth decision to ALSA resp. MPD, comment out resp. omit the ''dmix.format'' line and change the one for mpd with ''format'' to "44100:*:2".<br />
<br />
{{Note|''Crossfading'' between files decoded at two different bit depths (say, one mp3 and one 16 bit flac) does not work unless conversion is active.}}<br />
<br />
===Control MPD with lirc===<br />
There are already some clients designed for communications between lircd and MPD, however, as far as the practical use, they aren't very useful since their functions are limited.<br />
<br />
It's recommended to use mpc with irexec. mpc is a command line player which only sends the command to MPD and exits immediately, which is perfect for irexec, the command runner included in lirc. What irexec does is that it runs a specified command once received a remote control button.<br />
<br />
First of all, please setup your remotes as referred to the '''[[Lirc]]''' article.<br />
<br />
Edit your favored lirc startup configuration file, default location is {{Filename|~/.lircrc}}.<br />
<br />
Fill the file with the following pattern:<br />
begin<br />
prog = irexec<br />
button = <button_name><br />
config = <command_to_run><br />
repeat = <0 or 1><br />
end<br />
<br />
An useful example:<br />
## irexec<br />
begin<br />
prog = irexec<br />
button = play_pause<br />
config = mpc toggle<br />
repeat = 0<br />
end<br />
<br />
begin<br />
prog = irexec<br />
button = stop<br />
config = mpc stop<br />
repeat = 0<br />
end<br />
begin<br />
prog = irexec<br />
button = previous<br />
config = mpc prev<br />
repeat = 0<br />
end<br />
begin<br />
prog = irexec<br />
button = next<br />
config = mpc next<br />
repeat = 0<br />
end<br />
begin<br />
prog = irexec<br />
button = volup<br />
config = mpc volume +2<br />
repeat = 1<br />
end<br />
begin<br />
prog = irexec<br />
button = voldown<br />
config = mpc volume -2<br />
repeat = 1<br />
end<br />
begin<br />
prog = irexec<br />
button = pbc<br />
config = mpc random<br />
repeat = 0<br />
end<br />
begin<br />
prog = irexec<br />
button = pdvd<br />
config = mpc update<br />
repeat = 0<br />
end<br />
begin<br />
prog = irexec<br />
button = right<br />
config = mpc seek +00:00:05<br />
repeat = 0<br />
end<br />
begin<br />
prog = irexec<br />
button = left<br />
config = mpc seek -00:00:05<br />
repeat = 0<br />
end<br />
begin<br />
prog = irexec<br />
button = up<br />
config = mpc seek +1%<br />
repeat = 0<br />
end<br />
begin<br />
prog = irexec<br />
button = down<br />
config = mpc seek -1%<br />
repeat = 0<br />
end<br />
<br />
There are more functions for mpc, run {{Codeline|man mpc}} for more info.<br />
<br />
===Control MPD with bluetooth phone===<br />
You can also control MPD (to a certain extent) using a bluetooth enabled phone. You need to do the following:<br />
<br />
* install [http://remuco.sourceforge.net/index.php/Remuco remuco] -- a wireless remote control for several Linux media players ([http://aur.archlinux.org/packages.php?ID=25072 aur])<br />
* transfer remuco client -- jar/jad files from {{Filename|/usr/share/remuco/client/}} to your phone and install it<br />
* run {{Codeline|remuco-mpd}} (as current user)<br />
* run remuco on your phone, define a new bluetooth remuco connection (pair first if you haven't done this previously) and explore its capabilities<br />
<br />
More information about remuco including troubleshooting to be found at its [http://remuco.sourceforge.net/index.php/Remuco homepage]<br />
<br />
===MPD & PulseAudio===<br />
<br />
Edit {{Filename|/etc/mpd.conf}}, and uncomment the audio_output section for the type "pulse". The server and sink lines of it should be commented unless you know what you're doing.<br />
<br />
Then, add the mpd user (and yours if you haven't done so already) to the necessary pulse groups. The pulse-access group should be sufficient but you may want to add pulse-rt as well. The group "pulse" doesn't appear to be necessary.<br />
# gpasswd -a mpd pulse-access<br />
# gpasswd -a mpd pulse-rt<br />
<br />
Lastly, you may or may not need to copy {{Filename|~/.pulse-cookie}} from your current (pulse working) user's dir to your mpd user's home directory. It is likely to be {{Filename|/var/lib/mpd}} if you followed the first part of this wiki. This would probably only allow your current user to listen in on MPD's pulse. You may consider running pulse system-wide if that's insufficient.<br />
<br />
===Cue Files===<br />
<br />
To make cue file support actually work, you have to work around a nasty libcue bug. Libcue copied some files directly from libcdio, making it conflict with it. Steps to do to get proper cue support:<br />
<br />
* remove libcdio temporary (pacman -Rdd libcdio)<br />
* install libcue (pacman -S libcue)<br />
* install mpd with abs or from aur.<br />
* reinstall libcdio (pacman -S libcdio)<br />
<br />
At the point of writing mpd does not parse tracknumbers from cue sheets. There is a patch available (http://musicpd.org/mantis/view.php?id=3230)<br />
Once this patch is merged into mpd, i will remove this line :)<br />
<br />
==Troubleshooting==<br />
===Autodetection failed===<br />
During the start of MPD, it tries to autodetect your set-up and configure output and volume control accordingly. Though this mostly goes well, it will fail for some systems. It may help to tell MPD specifically what to use as output and mixer control. If you copied {{Filename|/etc/mpd.conf}} over from {{Filename|/etc/mpd.conf.example}} as mentioned above, you can simply uncomment:<br />
<br />
Example for alsa output type and alsa mixer:<br />
audio_output {<br />
type "alsa"<br />
name "My ALSA Device"<br />
device "hw:0,0" # optional<br />
format "44100:16:2" # optional<br />
mixer_type "hardware"<br />
mixer_device "default"<br />
mixer_control "PCM"<br />
}<br />
<br />
'''Note:''' in case of permission problems when using ESD with MPD run this as root:<br />
# chsh -s /bin/true mpd<br />
<br />
===Executable permissions===<br />
{{Warning|This is not good security practice and may be unnecessary.}}<br />
<br />
MPD needs to have +x permissions on '''ALL''' parent directories to your music collection (ie. if it's located outside of "mpd" home directory /var/lib/mpd). By default useradd sets permissions on home dir to 1700 drwx------. So if you're like me you will need to change permissions of /home/user. Example... my music collection is located /home/user/music. <br />
# chmod a+x /home/$USER<br />
# chmod -R a+X /home/$USER/music<br />
<br />
====Alternative solution====<br />
An alternative solution would be to use your group to share a selection of files, among them your music library. First remove all permissions for the group then add group permissions to read and execute home and music.<br />
# chmod -R g-rwx /home/$USER<br />
# chmod g+rx /home/$USER<br />
# chmod -R g+rX /home/$USER/music<br />
<br />
====Another alternative solution====<br />
Another alternative is to remount the music directory under a directory that mpd has access to. This does not entail the same security risks as modifying the permissions on one's home directory.<br />
# mkdir /var/lib/mpd/music<br />
# echo "/home/$USER/music /var/lib/mpd/music none bind" >> /etc/fstab<br />
# mount -a<br />
# /etc/rc.d/mpd restart<br />
And that should fix the problem. See also [https://bbs.archlinux.org/viewtopic.php?id=86449 the forum thread.]<br />
<br />
===Avoiding timeouts===<br />
To get rid of timeouts (i.e. when you paused music for long time) in gpmc and other clients uncomment and increase {{Codeline|connection_timeout}} option in {{Filename|mpd.conf}}.<br />
<br />
If files and/or titles are shown in wrong encoding, uncomment and change {{Codeline|filesystem_charset}} and {{Codeline|id3v1_encoding}} options.<br />
Note that you cannot set encoding for ID3 v2 tags. To workaround this you may use [http://mpd.wikia.com/wiki/GenericDecoder#Generic_Tagreader external tag readers].<br />
<br />
If you want to use another computer to control MPD over a network, the {{Codeline|bind_to_address}} option in {{Filename|mpd.conf}} will need to be set to either your IP address, or {{Codeline|any}} if your IP address changes frequently. <br />
<br />
'''Streaming'''<br><br />
With the latest version of MPD (0.15), built-in httpd streaming is now available.<br />
<br />
To activate this feature, you'll just need to add a new output of type httpd in {{Filename|mpd.conf}}:<br />
audio_output {<br />
type "httpd"<br />
name "What you want"<br />
encoder "lame" # vorbis or lame supported<br />
port "8000"<br />
bitrate "128"<br />
format "44100:16:2" # change 2 to 1 for mono<br />
}<br />
<br />
Restart the mpd deamon and, from another computer, simply load the stream as any other url. <br />
$ mplayer http://<server's IP>:8000<br />
<br />
{{Note | You must open the port on your router / firewall for the stream to be connectible to from another computer.}}<br />
<br />
Most players (i.e. vlc or xmms2) should also be able to load the stream via their "add url..." menu option.<br />
<br />
This is a nice clean way to replace your current icecast setup with something natively supported within MPD.<br />
<br />
===mpd hangs on first startup===<br />
This is a common error that's caused by corrupt mp3 tags.<br />
Here is an experimental way to solve this issue.<br />
Requirements:<br />
* kid3<br />
* easytag<br />
<br />
This method is very tedious, especially with a huge database. Just as a baseline it took 2.5h to fix a 16Gb DB.<br />
<br />
====Easy Tag====<br />
The purpose of easytag here is that easytag detects the error in the tags, but like MPD it hangs and dies. The trick here is that easy tags actually tells you what file is causing the problem on the status bar.<br />
Before starting easytag make sure to have a terminal close to be ready to kill easy tag to avoid a hang. Once you are ready, on the tree view select the directory where all your music is located. By default easytag starts to search all subdirectories for mp3 files. Once you notice that easytag stopped scanning for songs, make note of the culprit and kill easytag.<br />
<br />
====KID3====<br />
Here's where kid3 comes in handy. With kid3 go to the offending song and rewrite one of the tags. then save the file. This should force kid3 to rewrite the whole tag again fixing the problem with MPD and easy tag hanging.<br />
<br />
Repeat this procedure until your music library is done.<br />
<br />
===Cannot connect to mpd: host "localhost" not found: Temporary failure in name resolution===<br />
Cannot connect to MPD (with ncmpcpp), if you are disconnected from network. Solution is [[IPv6 - Disabling the Module|disable IPv6]] or add line to /etc/hosts<br />
::1 localhost.localdomain localhost<br />
<br />
===Other issues when attempting to connect to mpd with a client===<br />
Some have reported being unable to access mpd with various clients, for example seeing errors like these:<br />
$ ncmpcpp<br />
Cannot connect to mpd: Connection closed by the server<br />
$ sonata<br />
2011-02-13 18:33:05 Connection lost while reading MPD hello<br />
2011-02-13 18:33:05 Not connected<br />
2011-02-13 18:33:05 Not connected<br />
<br />
Please see posts on ncmpcpp on the Arch Forums [https://bbs.archlinux.org/viewtopic.php?id=109962 HERE] and [https://bbs.archlinux.org/viewtopic.php?id=113493 HERE]. Also see the Arch bug report on this issue [https://bugs.archlinux.org/task/22071 HERE]. <br />
<br />
====First fix====<br />
Check {{Filename|mpd.conf}} for a line like {{Codeline|mpd.error}} and remove it. The mpd error file is deprecated and has been removed.<br />
<br />
====Second fix====<br />
{{Note|I'm not so sure this is a good idea. There is a warning about changing the address to bind to in the default mpd.conf. If this does not help, you might want to comment out the changes.}}<br />
If that doesn't help, add the following to {{Filename|mpd.conf}}:<br />
<pre><br />
bind_to_address "127.0.0.1"<br />
port "6600"<br />
</pre><br />
<br />
Afterwards, instruct your client to connect via 127.0.0.1. For example, add the following to the ncmpcpp config file:<br />
<pre><br />
mpd_host "127.0.0.1"<br />
mpd_port "6600"<br />
</pre><br />
<br />
<br />
===Port 6600 already in use===<br />
MPD needs to bind to port 6600 and cannot start if it's already in use. The most common reason for this is that the user has started MPD once and then subsequently tried to start mpd again. In general, nothing should be done here.<br />
<br />
If port 6600 is tied up for some other reason, one can use the following command to find the offending process:<br />
# netstat -tulpan | grep 6600<br />
<br />
This will list IP:Port and the process name holding the connection (root privileges are required to see all processes).<br />
<br />
If you need to restart mpd for whatever reason, use:<br />
<pre><br />
$ mpd --kill<br />
$ mpd <br />
</pre><br />
A more brute-force approach:<br />
<pre><br />
$ killall mpd<br />
$ mpd <br />
</pre><br />
{{Note| If you typically run MPD as root, you will need to run the above commands as root.}}<br />
<br />
In the latest version of MPD, --create-db is completely deprecated. The database will be created automagically on first run and can subsequently be updated via your client (i.e. mpc update). You can now use inotify support to automatically update your music database. Add the following to {{File|name=mpd.conf|content=auto_update "yes"}} to enable it.<br />
<br />
===Binding to IPV6 before IPV4===<br />
If on startup, you see this message:<br />
listen: bind to '0.0.0.0:6600' failed: Address already in use (continuing anyway, because binding to '[::]:6600' succeeded)<br />
MPD is attempting to bind to the ipv6 interface before binding to ipv4. If you want to use your ipv4 interface, hardcode it in mpd.conf, like so:<br />
bind_to_address "127.0.0.1"<br />
Or, you could specify several binds, for example, to have MPD listen on localhost and the external IP of your network card:<br />
bind_to_address "127.0.0.1"<br />
bind_to_address "192.168.1.13"<br />
<br />
===Crackling sound with some audio files===<br />
This is usually a playback speed problem and can be fixed by uncommenting the audio_output_format line in:<br />
<br />
{{File|name=/etc/mpd.conf|content=<br />
audio_output_format "44100:16:2"}}<br />
<br />
This is usually a sane value for most mp3 files.<br />
<br />
===daemon: cannot setgid for user "mpd": Operation not permitted ===<br />
<br />
The error is stating that the user starting the process (you) does not have permissions to become another user (mpd) which the configuration has told that process to run as.<br />
<br />
To solve the issue, simply start mpd as root.<br />
su -c "/etc/rc.d/mpd start"<br />
or<br />
sudo /etc/rc.d/mpd start<br />
<br />
==External links==<br />
* [http://www.musicpd.org/ Official Web Site]<br />
* [http://mpd.wikia.com/wiki/Main_Page Official Wiki]<br />
* [http://mpd.wikia.com/wiki/Clients Sorted List of MPD Clients]<br />
* [http://www.musicpd.org/forum/ MPD forum]</div>Rasihttps://wiki.archlinux.org/index.php?title=Music_Player_Daemon&diff=150763Music Player Daemon2011-08-06T01:08:57Z<p>Rasi: /* Last.fm playback with lastfmproxy */</p>
<hr />
<div>[[fr:MPD]]<br />
[[Category:Audio/Video (English)]]<br />
[[Category:Daemons and system services (English)]]<br />
{{i18n|Music Player Daemon}}<br />
[[pl:Music Player Daemon]]<br />
<br />
'''MPD''' (music player daemon) is an audio player that has a server-client architecture. MPD runs in the background as a daemon, manages playlists and a music database, and uses very few resources. In order to interface with it, you need a separate client. More information can be found on their [http://www.musicpd.org/ website].<br />
<br />
''Please'' have a look at the official page for setup and troubleshooting instructions, the main developer called our wiki page in its current state ''"full of symptom killers"'', hence the official pages should contain better instructions.<br />
<br />
==Installing mpd==<br />
Install with [[pacman]]:<br />
# pacman -S mpd<br />
<br />
==Daemon Setup: Starting at Boot==<br />
General information about MPD configuration may be found at http://mpd.wikia.com/wiki/Configuration.<br />
<br />
===Sound setup===<br />
To make audio output actually work ensure that you have setup audio card and mixer correctly. See [[ALSA]], and [[PulseAudio]] if you are using Gnome 3. Do not forget to unmute the required channels in alsamixer, raise the volume and save changes with alsactl store. Run mpd with {{Filename|/usr/bin/mpd --stdout --no-daemon --verbose}} if that still doesn't work.<br />
<br />
Make sure your card can do hardware mixing (most of them can, including onboard audio). Or else this could cause problems with multiple sound playback. For example, this can prevent Mplayer from playing back sound while the mpd daemon is running, returning an audio error message stating the device is busy.<br />
<br />
===Timeline of MPD's behavior on a typical working setup when started as a daemon===<br />
# MPD is started on boot by {{Filename|/etc/rc.conf}}, by including it in the {{Codeline|DAEMONS}} array. (Or, this can be done manually each session by running {{Codeline|/etc/rc.d/mpd start}} with root privileges).<br />
# Since MPD is now started as root, it first reads the {{Filename|/etc/mpd.conf}} file.<br />
# MPD reads the user variable in the {{Filename|/etc/mpd.conf}} file, and changes from root to this user.<br />
# MPD then reads the contents of the {{Filename|/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 {{Filename|/etc/mpd.conf}} file. This way, uses of {{Codeline|~}} in the configuration file point correctly to the home user's directory, and not root's directory. It may be worthwhile to change all uses of {{Codeline|~}} to {{Codeline|/home/username}} to avoid any confusion over this aspect of MPD's behavior.<br />
<br />
===A clean configuration file===<br />
* As root, check if {{Filename|/etc/mpd.conf}} exists and delete the file if it does. This is safe.<br />
<br />
MPD comes with an example configuration file, available at {{Filename|/usr/share/mpd/mpd.conf.example}}. This file holds an abundance of information on MPD configuration, and holds default mixer values you can simply uncomment.<br />
<br />
* As root, copy this example file to {{Filename|/etc/mpd.conf}}.<br />
# cp /usr/share/mpd/mpd.conf.example /etc/mpd.conf<br />
({{Filename|/usr/share/mpd/mpd.conf.example}} is good for userspace setup)<br />
<br />
Since MPD is being set up to run as a daemon at boot, never put this file in the user's directory like some tutorials suggest, since it will not be read. Moreover, if you previously created a {{Filename|.mpdconf}} file in your home, remove it now (to set up MPD to run with user privileges alone, pleaser refer to the section [[Music_Player_Daemon#Alternative_Setup:_Starting_as_a_User | Alternative_Setup:_Starting_as_a_User]]). This is important to prevent conflicts. The presence of the configuration file in {{Filename|/etc}}, like is the case here, is what will enable MPD to run as a daemon at boot. Otherwise, a script would be needed to run MPD ''after'' the user has logged (like kdm or {{Filename|~/.fluxbox/startup}}) or it would require a manual move each time. For a single music collection, the method used here is simply better, even while the collection is shared to multiple users. Also, don't be afraid about root privileges: even while MPD runs as a daemon, it never completely runs as root since it automatically drops its root privileges after execution.<br />
<br />
===Edit {{Filename|mpd.conf}}===<br />
<br />
The default arch install keeps the setup in /var and uses "mpd" as default user, instead of cluttering up ~/.<br />
Edit {{Filename|/etc/mpd.conf}} to reflect as such.<br />
<br />
{{File|name=/etc/mpd.conf|content=<br />
music_directory "/home/user/music" # Your music dir.<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 "/var/run/mpd/mpd.pid" # Omit this line for systemd<br />
state_file "/var/lib/mpd/mpdstate"<br />
user "mpd"<br />
# Binding to address and port causing problems in mpd-0.14.2 best to leave<br />
# commented.<br />
# bind_to_address "127.0.0.1"<br />
# port "6600"<br />
}}<br />
<br />
* If your music collection is contained under multiple directories, you can make symbolic links under /var/lib/mpd then set 'music_directory' to the directory holding the symbolic links. Remember to set permissions accordingly on the directories being linked.<br />
<br />
* To change the volume of audio from mpd independent of other programs, uncomment or add the switch in mpd.conf:<br />
<br />
{{File|name=/etc/mpd.conf|content=<br />
mixer_type "software"<br />
}}<br />
<br />
* Lastly, if you are running pulseaudio under Gnome 3, the default setting of "alsa" for the audio output will not work. Make the modification from:<br />
{{File|name=/etc/mpd.conf|content=<br />
audio_output {<br />
type "alsa"<br />
name "Sound Card"<br />
}<br />
}}<br />
<br />
to<br />
<br />
{{File|name=/etc/mpd.conf|content=<br />
audio_output {<br />
type "pulse"<br />
name "Sound Card"<br />
}<br />
}}<br />
<br />
===Create files===<br />
<br />
* As root, create the directories and files you specified in {{Filename|/etc/mpd.conf}}.<br />
# mkdir -p /var/lib/mpd/playlists /var/run/mpd<br />
# touch /var/lib/mpd/{mpd.db,mpdstate} && touch /var/run/mpd/mpd.pid<br />
<br />
* You then need to change the file's permissions so that the daemon can modify them.<br />
# chown -R mpd /var/lib/mpd /var/run/mpd<br />
<br />
===Create database===<br />
<br />
Creating the database is now accomplished via the update feature of the client, for example 'mpc update'. The previous method, creating the MPD database as root (# mpd --create-db), is deprecated.<br />
<br />
==Alternative Setup: Starting as a User==<br />
MPD need not be started with root permissions. The only reason why MPD needs to be started as root (by being called from {{Filename|/etc/rc.conf}}) is because the default files and folders in the default configuration file points to directories owned by root (the /var directory). A less common, but perhaps more sensible, approach is to make MPD work with files and directories owned by a normal user. Running MPD as a normal user has several advantages: <br />
# You can easily have a single directory ~/.mpd (or any other directory under /home/username) for all MPD configuration files<br />
# No read/write permission errors<br />
# More flexible calls to MPD by using {{Filename|~/.xinitrc}} instead of including 'mpd' in the {{Filename|/etc/rc.conf}} DAEMONS array.<br />
<br />
The following steps shows how to run MPD as a normal user. '''Note''': this approach will not work if you want multiple users to have access to MPD.<br />
<br />
* Copy the contents of the default MPD configuration file in {{Filename|/usr/share/mpd/mpd.conf.example}} to your home directory. A good place would be {{Filename|"/home/user/.mpd/mpd.conf"}}.<br />
* Follow the 'old setup instructions' from above, ignoring the first part about copying the config to {{Filename|/etc/mpd.conf}} and do not set a user variable. <br />
* Create all of the requisite files in {{filename|"/home/user/.mpd/"}}:<br />
"~/.mpd/playlists/"<br />
"~/.mpd/db"<br />
"~/.mpd/mpd.db"<br />
"~/.mpd/mpd.log"<br />
"~/.mpd/mpd.error"<br />
"~/.mpd/mpd.pid"<br />
"~/.mpd/mpdstate"<br />
<br />
* Let MPD start on bootup by calling it from your {{Filename|~/.xinitrc}} as follows:<br />
# this starts mpd as normal user<br />
mpd ~/.mpd/mpd.conf<br />
{{Note| that you don't have to put a "&" at the end of the line here, since MPD will automatically daemonize itself.}}<br />
<br />
Lastly, delete the entry 'mpd' from your DAEMONS array in {{Filename|/etc/rc.conf}}, as you are not running it as root anymore.<br />
<br />
===Quick setup===<br />
<br />
The fastest way to do set up the structure is to do this:<br />
<br />
$ mkdir -p ~/.mpd/playlists && touch ~/.mpd/database && cp /usr/share/doc/mpd/mpdconf.example ~/.mpd/mpd.conf<br />
<br />
Then edit mpd.conf to your liking, in a manner similar to [[Music_Player_Daemon#Edit_mpd.conf]]. Beware that you must uncomment the db_file entry if you do edit mpd.conf.<br />
<br />
Then, to run it:<br />
<br />
$ mpd ~/.mpd/mpd.conf<br />
<br />
<br />
===Even quicker setup===<br />
I created a little script that will only ask for the location of your music and then creates the needed files and folders for you.<br />
You can find the script here:<br />
[http://karif.server-speed.net/~carnager/mpdsetup.tar]<br />
extract it<br />
$ tar xf mpdsetup.tar<br />
and run it<br />
$ ./mpdsetup.sh<br />
<br />
If you want to use this config in daemon mode, open it (~/.mpdconf) in an editor and find the "user" line. remove the comment (#) and fill in your own user name. Then copy the file to /etc/mpd.conf. If running mpd as user is fine for you, make sure to remove "mpd" from the daemons list in /etc/rc.conf<br />
<br />
===Multi-mpd setup===<br />
'''Useful if you want to run for example an icecast server.'''<br />
If you want a second MPD daemon (e.g., with icecast output to share music over the network) to use the same music and playlist as the one above, simply copy the above configuration file and make a new file (e.g., {{Filename|/home/username/.mpd/config-icecast}}), and only change the log_file, error_file, pid_file, and state_file parameters (e.g., {{Filename|mpd-icecast.log}}, {{Filename|mpd-icecast.error}}, and so on); using the same directory paths for the music and playlist directories would ensure that this second mpd daemon would use the same music collection as your first one (e.g., creating and editing a playlist under the first daemon would affect the second daemon as well, so that you don't have to create the same playlists all over again for the second daemon). Then, call this second daemon the same way from your {{Filename|~/.xinitrc}} above. (Just be sure to have a different port number, so as to not conflict with your first mpd daemon).<br />
<br />
==Clients==<br />
Install a client program for MPD. Popular options are:<br />
<br />
===Console===<br />
* '''mpc''' &ndash; Command Line Client (you'll probably want this one no matter what)<br />
# pacman -S mpc<br />
* [http://mpd.wikia.com/wiki/Client:Ncmpc/ ncmpc] &ndash; NCurses Client (this one is very handy for running in a console)<br />
# pacman -S ncmpc<br />
* [http://unkart.ovh.org/ncmpcpp/ ncmpcpp] &ndash; Clone of ncmpc with some new features written in C++<br />
# pacman -S ncmpcpp<br />
* [http://pms.sourceforge.net/ pms] &ndash; NCurses Client (highly configurable and accessible)<br />
Install [http://aur.archlinux.org/packages.php?ID=24378 pmus] from the [[AUR]].<br />
<br />
===Graphical===<br />
* [http://ario-player.sourceforge.net ario] &ndash; GTK+ Client with a Rhythmbox like library browser<br />
# pacman -S ario<br />
* [http://gmpcwiki.sarine.nl/index.php?title=GMPC gmpc] &ndash; GNOME Client<br />
# pacman -S gmpc<br />
* [http://bitcheese.net/wiki/QMPDClient QMPDClient] &ndash; Client written with Qt 4.x.<br />
# pacman -S qmpdclient<br />
* [http://sonata.berlios.de/ sonata] &ndash; Python GTK+ Client<br />
# pacman -S sonata<br />
* [http://aur.archlinux.org/packages.php?ID=33380 dmpc] &ndash; Dmenu-based MPC client with a playlist manager and state-saving on playlist changes<br />
Install [http://aur.archlinux.org/packages.php?ID=33380 dmpc] from the [[AUR]].<br />
<br />
See a long list of clients at the [http://mpd.wikia.com/wiki/Clients mpd wiki].<br />
<br />
==Extra stuff==<br />
===Last.fm scrobbling===<br />
To scrobble your songs to [http://www.last.fm Last.fm] using MPD there are several alternatives.<br />
<br />
====mpdscribble====<br />
mpdscribble is another daemon, available in the "community" repository (if you prefer, the "git" version is available in the [http://aur.archlinux.org/packages.php?ID=22274 AUR]). This is arguably the best alternative, because it's the semi-official MPD scrobbler and uses the new "idle" feature in MPD for more accurate scrobbling. Also, you don't need root access to configure it, because it doesn't need any changes to <tt>/etc</tt> at all. Visit [http://mpd.wikia.com/wiki/Client:Mpdscribble the official website] for more information.<br />
<br />
After you have installed mpdscribble, do the following (not as root):<br />
<br />
* {{Codeline|$ mkdir ~/.mpdscribble}}<br />
* Create the file {{Filename|~/.mpdscribble/mpdscribble.conf}} and add the following:<br />
<pre><br />
[mpdscribble] <br />
host = <your mpd host> # optional, defaults to $MPD_HOST or localhost<br />
port = <your mpd port> # optional, defaults to $MPD_PORT or 6600<br />
log = /home/<YOUR_USERNAME>/.mpdscribble/mpdscribble.log<br />
verbose = 2<br />
sleep = 1<br />
musicdir = <your music directory><br />
proxy = <your proxy> # optional, e. g. http://your.proxy:8080, defaults to none<br />
<br />
[last.fm]<br />
# last.fm section, comment if you don't use last.fm<br />
url = http://post.audioscrobbler.com/<br />
username = <your last.fm username><br />
password = <your last.fm password> # md5sum also possible: echo -n 'PASSWORD' | md5sum | cut -f 1 -d " "<br />
journal = /home/<YOUR_USERNAME>/.mpdscribble/lastfm.journal<br />
<br />
[libre.fm]<br />
# libre.fm section, comment if you don't use libre.fm<br />
url = http://turtle.libre.fm/<br />
username = <your libre.fm username><br />
password = <your libre.fm password> # md5sum also possible: echo -n 'PASSWORD' | md5sum | cut -f 1 -d " "<br />
journal = /home/<YOUR_USERNAME>/.mpdscribble/librefm.journal<br />
</pre><br />
* Add {{Codeline|mpdscribble}} to your {{Filename|~/.xinitrc}}:<br />
pidof mpdscribble >& /dev/null<br />
if [ $? -ne 0 ]; then<br />
mpdscribble &<br />
fi<br />
<br />
====Sonata & Ario====<br />
The easiest way, if you don't care about having to have a program window open all the time, is using Sonata or Ario which are graphical frontends to MPD. They have built-in support for Last.fm scrobbling in their preferences. A downside of this is that Sonata doesn't cache your songs if for some reason you don't happen to have an Internet connection at the time of playing.<br />
<br />
====lastfmsubmitd====<br />
lastfmsubmitd is a daemon which is available in the "community" repository. To install it, first edit {{Filename|/etc/lastfmsubmitd.conf}} and add both {{Codeline|lastfmsubmitd}} and {{Codeline|lastmp}} to the {{Codeline|DAEMONS}} array in {{Filename|/etc/rc.conf}}.<br />
<br />
===Last.fm playback with lastfmproxy===<br />
lastfmproxy is a python script that streams a last.fm music stream to another media player. To setup, install [http://aur.archlinux.org/packages.php?ID=14214 lastfmproxy] from the [[AUR]] and then edit {{Filename|/usr/share/lastfmproxy/config.py}}. If you plan to only stream to MPD on the same host, just edit the login info.<br />
<br />
{{Note | Since it installs to a read only directory but it requires read/write access for features like saving previously listened to stations, it would be wise to copy {{Filename|/usr/share/lastfmproxy}} to your home directory.}}<br />
<br />
Start lastfmproxy with {{Codeline|lastfmproxy}} and visit http://localhost:1881/ in your web browser. To add a last.fm station navigate to http://localhost:1881/ followed by the lastfm:// url. Example: http://localhost:1881/lastfm://globaltags/punk . Navigate back to http://localhost:1881/ and download the m3u file by selecting the ''Start Listening'' link. Simply add it to your music library path.<br />
<br />
<br />
===Native Last.fm playback===<br />
Since 0.16 mpd has a very well working method to play back last.fm streams.<br />
{{File|name=/etc/mpd.conf|content=<br />
$ playlist_plugin {<br />
name "lastfm"<br />
user "my_username"<br />
password "my_password"<br />
}<br />
}}<br />
Then use e.g. mpc to load streams<br />
$ mpc load "lastfm://artist/Beatles"<br />
<br />
===Never play on start===<br />
<br />
This feature has recently been added to mpd git by Martin Kellerman, see commits b57330cf75bcb339e3f268f1019c63e40d305145 and 2fb40fe728ac07574808c40034fc0f3d2254d49d.<br />
<br />
====[https://aur.archlinux.org/packages.php?ID=19676 mpd-git] Method====<br />
This is the best method currently available, but is only currently (April 2011) enabled in the git version. Install [https://aur.archlinux.org/packages.php?ID=19676 mpd-git] from the [[AUR]], then add {{Codeline|restore_paused "yes"}} to your {{Filename|mpd.conf}} file.<br />
<br />
If you have issues with connecting your client to [https://aur.archlinux.org/packages.php?ID=19676 mpd-git], see [[Music Player Daemon#Other issues when attempting to connect to mpd with a client]].<br />
<br />
====Method 1====<br />
If you don't want MPD to always play on your system start, but yet you want to preserve the other state information, add the following lines to your {{Filename|/etc/rc.d/mpd}} file:<br />
'' ...''<br />
'' stat_busy "Starting Music Player Daemon"''<br />
<br />
# always start in paused state<br />
awk '/^state_file[ \t]+"[^"]+"$/ {<br />
match($0, "\".+\"")<br />
sfile = substr($0, RSTART + 1, RLENGTH - 2)<br />
} /^user[ \t]+"[^"]+"$/ {<br />
match($0, "\".+\"")<br />
user = substr($0, RSTART + 1, RLENGTH - 2)<br />
} END {<br />
if (sfile == "")<br />
exit;<br />
if (user != "")<br />
sub(/^~/, "/home/" user, sfile)<br />
system("sed -i \x27s|^\\(state:[ \\t]\\{1,\\}\\)play$|\\1pause|\x27 \x27" sfile "\x27")<br />
}' /etc/mpd.conf<br />
<br />
'' /usr/bin/mpd /etc/mpd.conf &> /dev/null''<br />
'' ...''<br />
<br />
This will change the player status to "paused", if it was stopped while playing. Next, you want this file to be preserved, so MPD updates won't erase this edit. Add (or edit) this line to your {{Filename|/etc/pacman.conf}}:<br />
NoUpgrade = etc/rc.d/mpd<br />
<br />
====Method 2====<br />
<br />
Another simpler method, would be to add mpd to your {{Filename|[[rc.conf]]}} deamons array and add {{Codeline|mpc stop}} or {{Codeline|mpc pause}} to {{Filename|/etc/rc.local.shutdown}} and to {{Filename|/etc/rc.local}}. (Remember you must have mpc installed to use this method).<br />
<br />
Adding only the order in {{Filename|/etc/rc.local}} cannot assure that mpd will play absolutely nothing, since there may be a delay before the stop command is executed. <br />
On the other hand, if you only add the order to {{Filename|/etc/rc.local.shutdown}}, that will assure that mpd won't play at all, as long as you properly shutdown your system.<br />
Even though they are redundant, adding it to {{Filename|/etc/rc.local}} would serve as a safety for those, presumably, rare occasions when you do not shutdown the system properly.<br />
<br />
====Method 3====<br />
<br />
The general idea between this method is to ask mdp to pause music when user logs out so that during next restart, mdp will stick to that "pause" state. Sending such command can be achieve using [http://www.archlinux.org/packages/extra/x86_64/mpc/ mpc], the command line interface to MPD:<br />
pacman -S mpc<br />
<br />
GDM users can then add the next line to /etc/gdm/PostSession/Default (be sure to add it before "exit 0"):<br />
/usr/bin/mpc pause<br />
<br />
Non-GDM users can use their own login manager's method to launch the line at logout.<br />
<br />
===MPD & ALSA===<br />
Sometimes, when you use other audio output, e.g: some web pages containing Flash applets, MPD cannot reproduce anything anymore (until you restart). The error looks something like: (if you search the file {{Filename|/var/log/mpd/mpd.error}})<br />
<br />
Error opening alsa device "hw:0,0": Device or resource busy<br />
<br />
And here is the solution (dmix saving our life again). Apply these lines in your {{Filename|/etc/mpd.conf}}:<br />
<br />
<pre><br />
audio_output {<br />
type "alsa"<br />
name "Sound Card"<br />
options "dev=dmixer"<br />
device "plug:dmix"<br />
}<br />
</pre><br />
<br />
And then restart with {{Codeline|/etc/rc.d/mpd restart}}.<br />
<br />
Searching on Internet I found the reason for why that happens in Gentoo's wiki:<br />
* The sound card does not support hardware mixing (uses '''dmix''' plugin)<br />
* An application does not work with ALSA with it's default settings<br />
<br />
For a detailed description, it is recommended to take a look at [http://mpd.wikia.com/wiki/Alsa this] link. There you can find an example asound.conf which worked for me right out of the box.<br />
<br />
====High CPU usage with ALSA====<br />
When using MPD with ALSA, users may experience MPD taking up lots of CPU (around 20-30%). This is caused by most sound cards supporting 48kHz and most music being 44kHz, thus forcing MPD to resample it. This operation takes lots of CPU cycles and results into high usage.<br />
<br />
For most users the problem should be solved by telling MPD not to use resampling by adding {{Codeline|auto_resample "no"}} into audio_output-part of {{Filename|/etc/mpd.conf}}. This will degrade quality slightly, however.<br />
<br />
Example from {{Filename|mpd.conf}}:<br />
<br />
audio_output {<br />
type "alsa"<br />
name "My ALSA Device"<br />
auto_resample "no"<br />
}<br />
<br />
Although it may not give as drastic a speedup, enabling mmap may speed things up:<br />
<br />
audio_output {<br />
type "alsa"<br />
name "My ALSA Device"<br />
use_mmap "yes"<br />
}<br />
<br />
Some users might also want to tell dmix to use 44kHz as well. More info about tuning performance of your MPD can be found from: [http://mpd.wikia.com/wiki/Tuning MPD wiki]<br />
<br />
====Example configuration: Output with 44.1 KHz at e. g. 16 bit depth, multiple programs at once====<br />
<br />
''Why these formats?'' Because they are standard CDA, because ALSA on its own allows more than one program "to sound" only with dmix — whose resampling algorithm is inferior — and because dmix by default resamples anything lower to 48 KHz (or whatever higher format is playing at the time). Also, some get clicking sounds if at least {{Filename|mpd.conf}} is not changed this way.<br />
<br />
''What's the downside?'' These settings cause ''everything'' (if necessary) to be resampled to this format, such as material from DVD or TV which usually is at 48 KHz. But there is no known way to have ALSA dynamically change the format, and particularly if you listen to far more CDs than anything else the occasional 48 → 44.1 isn't too great a loss.<br />
<br />
The following assumes that there are not already other settings which conflict resp. overwrite it. This applies especially to the current user's potential {{Filename|~/.asoundrc}} — which MPD as its own user ignores, therefore the following should go to {{Filename|/etc/asound.conf}}:<br />
<br />
{{File|name=/etc/asound.conf|content=<br />
defaults.pcm.dmix.rate 44100 # Force 44.1 KHz<br />
defaults.pcm.dmix.format S16_LE # Force 16 bits<br />
}}<br />
<br />
{{File|name=/etc/mpd.conf|content=<br />
audio_output {<br />
type "alsa" # Use the ALSA output plugin.<br />
name "HDA Intel" # Can be called anything or nothing tmk, but must be present.<br />
options "dev=dmixer"<br />
device "plug:dmix" # Both lines cause MPD to output to dmix.<br />
format "44100:16:2" # the actual format<br />
auto_resample "no" # This bypasses ALSA's own algorithms, which generally are inferior. See below how to choose a different one.<br />
use_mmap "yes" # Minor speed improvement, should work with all modern cards.<br />
}<br />
<br />
samplerate_converter "0" # MPD's best, most CPU intensive algorithm. See 'man mpd.conf' for others — for anything other than the poorest "internal", libsamplerate must be installed.<br />
}}<br />
<br />
{{Note|MPD gives the mp3 format a special treatment at decoding: It's always outputted as 24 bit. (The conversion as forced by the ''format'' line only comes after that.)}}<br />
<br />
If one wants to leave the bit depth decision to ALSA resp. MPD, comment out resp. omit the ''dmix.format'' line and change the one for mpd with ''format'' to "44100:*:2".<br />
<br />
{{Note|''Crossfading'' between files decoded at two different bit depths (say, one mp3 and one 16 bit flac) does not work unless conversion is active.}}<br />
<br />
===Control MPD with lirc===<br />
There are already some clients designed for communications between lircd and MPD, however, as far as the practical use, they aren't very useful since their functions are limited.<br />
<br />
It's recommended to use mpc with irexec. mpc is a command line player which only sends the command to MPD and exits immediately, which is perfect for irexec, the command runner included in lirc. What irexec does is that it runs a specified command once received a remote control button.<br />
<br />
First of all, please setup your remotes as referred to the '''[[Lirc]]''' article.<br />
<br />
Edit your favored lirc startup configuration file, default location is {{Filename|~/.lircrc}}.<br />
<br />
Fill the file with the following pattern:<br />
begin<br />
prog = irexec<br />
button = <button_name><br />
config = <command_to_run><br />
repeat = <0 or 1><br />
end<br />
<br />
An useful example:<br />
## irexec<br />
begin<br />
prog = irexec<br />
button = play_pause<br />
config = mpc toggle<br />
repeat = 0<br />
end<br />
<br />
begin<br />
prog = irexec<br />
button = stop<br />
config = mpc stop<br />
repeat = 0<br />
end<br />
begin<br />
prog = irexec<br />
button = previous<br />
config = mpc prev<br />
repeat = 0<br />
end<br />
begin<br />
prog = irexec<br />
button = next<br />
config = mpc next<br />
repeat = 0<br />
end<br />
begin<br />
prog = irexec<br />
button = volup<br />
config = mpc volume +2<br />
repeat = 1<br />
end<br />
begin<br />
prog = irexec<br />
button = voldown<br />
config = mpc volume -2<br />
repeat = 1<br />
end<br />
begin<br />
prog = irexec<br />
button = pbc<br />
config = mpc random<br />
repeat = 0<br />
end<br />
begin<br />
prog = irexec<br />
button = pdvd<br />
config = mpc update<br />
repeat = 0<br />
end<br />
begin<br />
prog = irexec<br />
button = right<br />
config = mpc seek +00:00:05<br />
repeat = 0<br />
end<br />
begin<br />
prog = irexec<br />
button = left<br />
config = mpc seek -00:00:05<br />
repeat = 0<br />
end<br />
begin<br />
prog = irexec<br />
button = up<br />
config = mpc seek +1%<br />
repeat = 0<br />
end<br />
begin<br />
prog = irexec<br />
button = down<br />
config = mpc seek -1%<br />
repeat = 0<br />
end<br />
<br />
There are more functions for mpc, run {{Codeline|man mpc}} for more info.<br />
<br />
===Control MPD with bluetooth phone===<br />
You can also control MPD (to a certain extent) using a bluetooth enabled phone. You need to do the following:<br />
<br />
* install [http://remuco.sourceforge.net/index.php/Remuco remuco] -- a wireless remote control for several Linux media players ([http://aur.archlinux.org/packages.php?ID=25072 aur])<br />
* transfer remuco client -- jar/jad files from {{Filename|/usr/share/remuco/client/}} to your phone and install it<br />
* run {{Codeline|remuco-mpd}} (as current user)<br />
* run remuco on your phone, define a new bluetooth remuco connection (pair first if you haven't done this previously) and explore its capabilities<br />
<br />
More information about remuco including troubleshooting to be found at its [http://remuco.sourceforge.net/index.php/Remuco homepage]<br />
<br />
===MPD & PulseAudio===<br />
<br />
Edit {{Filename|/etc/mpd.conf}}, and uncomment the audio_output section for the type "pulse". The server and sink lines of it should be commented unless you know what you're doing.<br />
<br />
Then, add the mpd user (and yours if you haven't done so already) to the necessary pulse groups. The pulse-access group should be sufficient but you may want to add pulse-rt as well. The group "pulse" doesn't appear to be necessary.<br />
# gpasswd -a mpd pulse-access<br />
# gpasswd -a mpd pulse-rt<br />
<br />
Lastly, you may or may not need to copy {{Filename|~/.pulse-cookie}} from your current (pulse working) user's dir to your mpd user's home directory. It is likely to be {{Filename|/var/lib/mpd}} if you followed the first part of this wiki. This would probably only allow your current user to listen in on MPD's pulse. You may consider running pulse system-wide if that's insufficient.<br />
<br />
===Cue Files===<br />
<br />
To make cue file support actually work, you have to work around a nasty libcue bug. Libcue copied some files directly from libcdio, making it conflict with it. Steps to do to get proper cue support:<br />
<br />
* remove libcdio temporary (pacman -Rdd libcdio)<br />
* install libcue (pacman -S libcue)<br />
* install mpd with abs or from aur.<br />
* reinstall libcdio (pacman -S libcdio)<br />
<br />
At the point of writing mpd does not parse tracknumbers from cue sheets. There is a patch available (http://musicpd.org/mantis/view.php?id=3230)<br />
Once this patch is merged into mpd, i will remove this line :)<br />
<br />
==Troubleshooting==<br />
===Autodetection failed===<br />
During the start of MPD, it tries to autodetect your set-up and configure output and volume control accordingly. Though this mostly goes well, it will fail for some systems. It may help to tell MPD specifically what to use as output and mixer control. If you copied {{Filename|/etc/mpd.conf}} over from {{Filename|/etc/mpd.conf.example}} as mentioned above, you can simply uncomment:<br />
<br />
Example for alsa output type and alsa mixer:<br />
audio_output {<br />
type "alsa"<br />
name "My ALSA Device"<br />
device "hw:0,0" # optional<br />
format "44100:16:2" # optional<br />
mixer_type "hardware"<br />
mixer_device "default"<br />
mixer_control "PCM"<br />
}<br />
<br />
'''Note:''' in case of permission problems when using ESD with MPD run this as root:<br />
# chsh -s /bin/true mpd<br />
<br />
===Executable permissions===<br />
{{Warning|This is not good security practice and may be unnecessary.}}<br />
<br />
MPD needs to have +x permissions on '''ALL''' parent directories to your music collection (ie. if it's located outside of "mpd" home directory /var/lib/mpd). By default useradd sets permissions on home dir to 1700 drwx------. So if you're like me you will need to change permissions of /home/user. Example... my music collection is located /home/user/music. <br />
# chmod a+x /home/$USER<br />
# chmod -R a+X /home/$USER/music<br />
<br />
====Alternative solution====<br />
An alternative solution would be to use your group to share a selection of files, among them your music library. First remove all permissions for the group then add group permissions to read and execute home and music.<br />
# chmod -R g-rwx /home/$USER<br />
# chmod g+rx /home/$USER<br />
# chmod -R g+rX /home/$USER/music<br />
<br />
====Another alternative solution====<br />
Another alternative is to remount the music directory under a directory that mpd has access to. This does not entail the same security risks as modifying the permissions on one's home directory.<br />
# mkdir /var/lib/mpd/music<br />
# echo "/home/$USER/music /var/lib/mpd/music none bind" >> /etc/fstab<br />
# mount -a<br />
# /etc/rc.d/mpd restart<br />
And that should fix the problem. See also [https://bbs.archlinux.org/viewtopic.php?id=86449 the forum thread.]<br />
<br />
===Avoiding timeouts===<br />
To get rid of timeouts (i.e. when you paused music for long time) in gpmc and other clients uncomment and increase {{Codeline|connection_timeout}} option in {{Filename|mpd.conf}}.<br />
<br />
If files and/or titles are shown in wrong encoding, uncomment and change {{Codeline|filesystem_charset}} and {{Codeline|id3v1_encoding}} options.<br />
Note that you cannot set encoding for ID3 v2 tags. To workaround this you may use [http://mpd.wikia.com/wiki/GenericDecoder#Generic_Tagreader external tag readers].<br />
<br />
If you want to use another computer to control MPD over a network, the {{Codeline|bind_to_address}} option in {{Filename|mpd.conf}} will need to be set to either your IP address, or {{Codeline|any}} if your IP address changes frequently. <br />
<br />
'''Streaming'''<br><br />
With the latest version of MPD (0.15), built-in httpd streaming is now available.<br />
<br />
To activate this feature, you'll just need to add a new output of type httpd in {{Filename|mpd.conf}}:<br />
audio_output {<br />
type "httpd"<br />
name "What you want"<br />
encoder "lame" # vorbis or lame supported<br />
port "8000"<br />
bitrate "128"<br />
format "44100:16:2" # change 2 to 1 for mono<br />
}<br />
<br />
Restart the mpd deamon and, from another computer, simply load the stream as any other url. <br />
$ mplayer http://<server's IP>:8000<br />
<br />
{{Note | You must open the port on your router / firewall for the stream to be connectible to from another computer.}}<br />
<br />
Most players (i.e. vlc or xmms2) should also be able to load the stream via their "add url..." menu option.<br />
<br />
This is a nice clean way to replace your current icecast setup with something natively supported within MPD.<br />
<br />
===mpd hangs on first startup===<br />
This is a common error that's caused by corrupt mp3 tags.<br />
Here is an experimental way to solve this issue.<br />
Requirements:<br />
* kid3<br />
* easytag<br />
<br />
This method is very tedious, especially with a huge database. Just as a baseline it took 2.5h to fix a 16Gb DB.<br />
<br />
====Easy Tag====<br />
The purpose of easytag here is that easytag detects the error in the tags, but like MPD it hangs and dies. The trick here is that easy tags actually tells you what file is causing the problem on the status bar.<br />
Before starting easytag make sure to have a terminal close to be ready to kill easy tag to avoid a hang. Once you are ready, on the tree view select the directory where all your music is located. By default easytag starts to search all subdirectories for mp3 files. Once you notice that easytag stopped scanning for songs, make note of the culprit and kill easytag.<br />
<br />
====KID3====<br />
Here's where kid3 comes in handy. With kid3 go to the offending song and rewrite one of the tags. then save the file. This should force kid3 to rewrite the whole tag again fixing the problem with MPD and easy tag hanging.<br />
<br />
Repeat this procedure until your music library is done.<br />
<br />
===Cannot connect to mpd: host "localhost" not found: Temporary failure in name resolution===<br />
Cannot connect to MPD (with ncmpcpp), if you are disconnected from network. Solution is [[IPv6 - Disabling the Module|disable IPv6]] or add line to /etc/hosts<br />
::1 localhost.localdomain localhost<br />
<br />
===Other issues when attempting to connect to mpd with a client===<br />
Some have reported being unable to access mpd with various clients, for example seeing errors like these:<br />
$ ncmpcpp<br />
Cannot connect to mpd: Connection closed by the server<br />
$ sonata<br />
2011-02-13 18:33:05 Connection lost while reading MPD hello<br />
2011-02-13 18:33:05 Not connected<br />
2011-02-13 18:33:05 Not connected<br />
<br />
Please see posts on ncmpcpp on the Arch Forums [https://bbs.archlinux.org/viewtopic.php?id=109962 HERE] and [https://bbs.archlinux.org/viewtopic.php?id=113493 HERE]. Also see the Arch bug report on this issue [https://bugs.archlinux.org/task/22071 HERE]. <br />
<br />
====First fix====<br />
Check {{Filename|mpd.conf}} for a line like {{Codeline|mpd.error}} and remove it. The mpd error file is deprecated and has been removed.<br />
<br />
====Second fix====<br />
{{Note|I'm not so sure this is a good idea. There is a warning about changing the address to bind to in the default mpd.conf. If this does not help, you might want to comment out the changes.}}<br />
If that doesn't help, add the following to {{Filename|mpd.conf}}:<br />
<pre><br />
bind_to_address "127.0.0.1"<br />
port "6600"<br />
</pre><br />
<br />
Afterwards, instruct your client to connect via 127.0.0.1. For example, add the following to the ncmpcpp config file:<br />
<pre><br />
mpd_host "127.0.0.1"<br />
mpd_port "6600"<br />
</pre><br />
<br />
<br />
===Port 6600 already in use===<br />
MPD needs to bind to port 6600 and cannot start if it's already in use. The most common reason for this is that the user has started MPD once and then subsequently tried to start mpd again. In general, nothing should be done here.<br />
<br />
If port 6600 is tied up for some other reason, one can use the following command to find the offending process:<br />
# netstat -tulpan | grep 6600<br />
<br />
This will list IP:Port and the process name holding the connection (root privileges are required to see all processes).<br />
<br />
If you need to restart mpd for whatever reason, use:<br />
<pre><br />
$ mpd --kill<br />
$ mpd <br />
</pre><br />
A more brute-force approach:<br />
<pre><br />
$ killall mpd<br />
$ mpd <br />
</pre><br />
{{Note| If you typically run MPD as root, you will need to run the above commands as root.}}<br />
<br />
In the latest version of MPD, --create-db is completely deprecated. The database will be created automagically on first run and can subsequently be updated via your client (i.e. mpc update). You can now use inotify support to automatically update your music database. Add the following to {{File|name=mpd.conf|content=auto_update "yes"}} to enable it.<br />
<br />
===Binding to IPV6 before IPV4===<br />
If on startup, you see this message:<br />
listen: bind to '0.0.0.0:6600' failed: Address already in use (continuing anyway, because binding to '[::]:6600' succeeded)<br />
MPD is attempting to bind to the ipv6 interface before binding to ipv4. If you want to use your ipv4 interface, hardcode it in mpd.conf, like so:<br />
bind_to_address "127.0.0.1"<br />
Or, you could specify several binds, for example, to have MPD listen on localhost and the external IP of your network card:<br />
bind_to_address "127.0.0.1"<br />
bind_to_address "192.168.1.13"<br />
<br />
===Crackling sound with some audio files===<br />
This is usually a playback speed problem and can be fixed by uncommenting the audio_output_format line in:<br />
<br />
{{File|name=/etc/mpd.conf|content=<br />
audio_output_format "44100:16:2"}}<br />
<br />
This is usually a sane value for most mp3 files.<br />
<br />
===daemon: cannot setgid for user "mpd": Operation not permitted ===<br />
<br />
The error is stating that the user starting the process (you) does not have permissions to become another user (mpd) which the configuration has told that process to run as.<br />
<br />
To solve the issue, simply start mpd as root.<br />
su -c "/etc/rc.d/mpd start"<br />
or<br />
sudo /etc/rc.d/mpd start<br />
<br />
==External links==<br />
* [http://www.musicpd.org/ Official Web Site]<br />
* [http://mpd.wikia.com/wiki/Main_Page Official Wiki]<br />
* [http://mpd.wikia.com/wiki/Clients Sorted List of MPD Clients]<br />
* [http://www.musicpd.org/forum/ MPD forum]</div>Rasihttps://wiki.archlinux.org/index.php?title=Music_Player_Daemon&diff=150762Music Player Daemon2011-08-06T01:08:25Z<p>Rasi: /* Native Last.fm playback */</p>
<hr />
<div>[[fr:MPD]]<br />
[[Category:Audio/Video (English)]]<br />
[[Category:Daemons and system services (English)]]<br />
{{i18n|Music Player Daemon}}<br />
[[pl:Music Player Daemon]]<br />
<br />
'''MPD''' (music player daemon) is an audio player that has a server-client architecture. MPD runs in the background as a daemon, manages playlists and a music database, and uses very few resources. In order to interface with it, you need a separate client. More information can be found on their [http://www.musicpd.org/ website].<br />
<br />
''Please'' have a look at the official page for setup and troubleshooting instructions, the main developer called our wiki page in its current state ''"full of symptom killers"'', hence the official pages should contain better instructions.<br />
<br />
==Installing mpd==<br />
Install with [[pacman]]:<br />
# pacman -S mpd<br />
<br />
==Daemon Setup: Starting at Boot==<br />
General information about MPD configuration may be found at http://mpd.wikia.com/wiki/Configuration.<br />
<br />
===Sound setup===<br />
To make audio output actually work ensure that you have setup audio card and mixer correctly. See [[ALSA]], and [[PulseAudio]] if you are using Gnome 3. Do not forget to unmute the required channels in alsamixer, raise the volume and save changes with alsactl store. Run mpd with {{Filename|/usr/bin/mpd --stdout --no-daemon --verbose}} if that still doesn't work.<br />
<br />
Make sure your card can do hardware mixing (most of them can, including onboard audio). Or else this could cause problems with multiple sound playback. For example, this can prevent Mplayer from playing back sound while the mpd daemon is running, returning an audio error message stating the device is busy.<br />
<br />
===Timeline of MPD's behavior on a typical working setup when started as a daemon===<br />
# MPD is started on boot by {{Filename|/etc/rc.conf}}, by including it in the {{Codeline|DAEMONS}} array. (Or, this can be done manually each session by running {{Codeline|/etc/rc.d/mpd start}} with root privileges).<br />
# Since MPD is now started as root, it first reads the {{Filename|/etc/mpd.conf}} file.<br />
# MPD reads the user variable in the {{Filename|/etc/mpd.conf}} file, and changes from root to this user.<br />
# MPD then reads the contents of the {{Filename|/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 {{Filename|/etc/mpd.conf}} file. This way, uses of {{Codeline|~}} in the configuration file point correctly to the home user's directory, and not root's directory. It may be worthwhile to change all uses of {{Codeline|~}} to {{Codeline|/home/username}} to avoid any confusion over this aspect of MPD's behavior.<br />
<br />
===A clean configuration file===<br />
* As root, check if {{Filename|/etc/mpd.conf}} exists and delete the file if it does. This is safe.<br />
<br />
MPD comes with an example configuration file, available at {{Filename|/usr/share/mpd/mpd.conf.example}}. This file holds an abundance of information on MPD configuration, and holds default mixer values you can simply uncomment.<br />
<br />
* As root, copy this example file to {{Filename|/etc/mpd.conf}}.<br />
# cp /usr/share/mpd/mpd.conf.example /etc/mpd.conf<br />
({{Filename|/usr/share/mpd/mpd.conf.example}} is good for userspace setup)<br />
<br />
Since MPD is being set up to run as a daemon at boot, never put this file in the user's directory like some tutorials suggest, since it will not be read. Moreover, if you previously created a {{Filename|.mpdconf}} file in your home, remove it now (to set up MPD to run with user privileges alone, pleaser refer to the section [[Music_Player_Daemon#Alternative_Setup:_Starting_as_a_User | Alternative_Setup:_Starting_as_a_User]]). This is important to prevent conflicts. The presence of the configuration file in {{Filename|/etc}}, like is the case here, is what will enable MPD to run as a daemon at boot. Otherwise, a script would be needed to run MPD ''after'' the user has logged (like kdm or {{Filename|~/.fluxbox/startup}}) or it would require a manual move each time. For a single music collection, the method used here is simply better, even while the collection is shared to multiple users. Also, don't be afraid about root privileges: even while MPD runs as a daemon, it never completely runs as root since it automatically drops its root privileges after execution.<br />
<br />
===Edit {{Filename|mpd.conf}}===<br />
<br />
The default arch install keeps the setup in /var and uses "mpd" as default user, instead of cluttering up ~/.<br />
Edit {{Filename|/etc/mpd.conf}} to reflect as such.<br />
<br />
{{File|name=/etc/mpd.conf|content=<br />
music_directory "/home/user/music" # Your music dir.<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 "/var/run/mpd/mpd.pid" # Omit this line for systemd<br />
state_file "/var/lib/mpd/mpdstate"<br />
user "mpd"<br />
# Binding to address and port causing problems in mpd-0.14.2 best to leave<br />
# commented.<br />
# bind_to_address "127.0.0.1"<br />
# port "6600"<br />
}}<br />
<br />
* If your music collection is contained under multiple directories, you can make symbolic links under /var/lib/mpd then set 'music_directory' to the directory holding the symbolic links. Remember to set permissions accordingly on the directories being linked.<br />
<br />
* To change the volume of audio from mpd independent of other programs, uncomment or add the switch in mpd.conf:<br />
<br />
{{File|name=/etc/mpd.conf|content=<br />
mixer_type "software"<br />
}}<br />
<br />
* Lastly, if you are running pulseaudio under Gnome 3, the default setting of "alsa" for the audio output will not work. Make the modification from:<br />
{{File|name=/etc/mpd.conf|content=<br />
audio_output {<br />
type "alsa"<br />
name "Sound Card"<br />
}<br />
}}<br />
<br />
to<br />
<br />
{{File|name=/etc/mpd.conf|content=<br />
audio_output {<br />
type "pulse"<br />
name "Sound Card"<br />
}<br />
}}<br />
<br />
===Create files===<br />
<br />
* As root, create the directories and files you specified in {{Filename|/etc/mpd.conf}}.<br />
# mkdir -p /var/lib/mpd/playlists /var/run/mpd<br />
# touch /var/lib/mpd/{mpd.db,mpdstate} && touch /var/run/mpd/mpd.pid<br />
<br />
* You then need to change the file's permissions so that the daemon can modify them.<br />
# chown -R mpd /var/lib/mpd /var/run/mpd<br />
<br />
===Create database===<br />
<br />
Creating the database is now accomplished via the update feature of the client, for example 'mpc update'. The previous method, creating the MPD database as root (# mpd --create-db), is deprecated.<br />
<br />
==Alternative Setup: Starting as a User==<br />
MPD need not be started with root permissions. The only reason why MPD needs to be started as root (by being called from {{Filename|/etc/rc.conf}}) is because the default files and folders in the default configuration file points to directories owned by root (the /var directory). A less common, but perhaps more sensible, approach is to make MPD work with files and directories owned by a normal user. Running MPD as a normal user has several advantages: <br />
# You can easily have a single directory ~/.mpd (or any other directory under /home/username) for all MPD configuration files<br />
# No read/write permission errors<br />
# More flexible calls to MPD by using {{Filename|~/.xinitrc}} instead of including 'mpd' in the {{Filename|/etc/rc.conf}} DAEMONS array.<br />
<br />
The following steps shows how to run MPD as a normal user. '''Note''': this approach will not work if you want multiple users to have access to MPD.<br />
<br />
* Copy the contents of the default MPD configuration file in {{Filename|/usr/share/mpd/mpd.conf.example}} to your home directory. A good place would be {{Filename|"/home/user/.mpd/mpd.conf"}}.<br />
* Follow the 'old setup instructions' from above, ignoring the first part about copying the config to {{Filename|/etc/mpd.conf}} and do not set a user variable. <br />
* Create all of the requisite files in {{filename|"/home/user/.mpd/"}}:<br />
"~/.mpd/playlists/"<br />
"~/.mpd/db"<br />
"~/.mpd/mpd.db"<br />
"~/.mpd/mpd.log"<br />
"~/.mpd/mpd.error"<br />
"~/.mpd/mpd.pid"<br />
"~/.mpd/mpdstate"<br />
<br />
* Let MPD start on bootup by calling it from your {{Filename|~/.xinitrc}} as follows:<br />
# this starts mpd as normal user<br />
mpd ~/.mpd/mpd.conf<br />
{{Note| that you don't have to put a "&" at the end of the line here, since MPD will automatically daemonize itself.}}<br />
<br />
Lastly, delete the entry 'mpd' from your DAEMONS array in {{Filename|/etc/rc.conf}}, as you are not running it as root anymore.<br />
<br />
===Quick setup===<br />
<br />
The fastest way to do set up the structure is to do this:<br />
<br />
$ mkdir -p ~/.mpd/playlists && touch ~/.mpd/database && cp /usr/share/doc/mpd/mpdconf.example ~/.mpd/mpd.conf<br />
<br />
Then edit mpd.conf to your liking, in a manner similar to [[Music_Player_Daemon#Edit_mpd.conf]]. Beware that you must uncomment the db_file entry if you do edit mpd.conf.<br />
<br />
Then, to run it:<br />
<br />
$ mpd ~/.mpd/mpd.conf<br />
<br />
<br />
===Even quicker setup===<br />
I created a little script that will only ask for the location of your music and then creates the needed files and folders for you.<br />
You can find the script here:<br />
[http://karif.server-speed.net/~carnager/mpdsetup.tar]<br />
extract it<br />
$ tar xf mpdsetup.tar<br />
and run it<br />
$ ./mpdsetup.sh<br />
<br />
If you want to use this config in daemon mode, open it (~/.mpdconf) in an editor and find the "user" line. remove the comment (#) and fill in your own user name. Then copy the file to /etc/mpd.conf. If running mpd as user is fine for you, make sure to remove "mpd" from the daemons list in /etc/rc.conf<br />
<br />
===Multi-mpd setup===<br />
'''Useful if you want to run for example an icecast server.'''<br />
If you want a second MPD daemon (e.g., with icecast output to share music over the network) to use the same music and playlist as the one above, simply copy the above configuration file and make a new file (e.g., {{Filename|/home/username/.mpd/config-icecast}}), and only change the log_file, error_file, pid_file, and state_file parameters (e.g., {{Filename|mpd-icecast.log}}, {{Filename|mpd-icecast.error}}, and so on); using the same directory paths for the music and playlist directories would ensure that this second mpd daemon would use the same music collection as your first one (e.g., creating and editing a playlist under the first daemon would affect the second daemon as well, so that you don't have to create the same playlists all over again for the second daemon). Then, call this second daemon the same way from your {{Filename|~/.xinitrc}} above. (Just be sure to have a different port number, so as to not conflict with your first mpd daemon).<br />
<br />
==Clients==<br />
Install a client program for MPD. Popular options are:<br />
<br />
===Console===<br />
* '''mpc''' &ndash; Command Line Client (you'll probably want this one no matter what)<br />
# pacman -S mpc<br />
* [http://mpd.wikia.com/wiki/Client:Ncmpc/ ncmpc] &ndash; NCurses Client (this one is very handy for running in a console)<br />
# pacman -S ncmpc<br />
* [http://unkart.ovh.org/ncmpcpp/ ncmpcpp] &ndash; Clone of ncmpc with some new features written in C++<br />
# pacman -S ncmpcpp<br />
* [http://pms.sourceforge.net/ pms] &ndash; NCurses Client (highly configurable and accessible)<br />
Install [http://aur.archlinux.org/packages.php?ID=24378 pmus] from the [[AUR]].<br />
<br />
===Graphical===<br />
* [http://ario-player.sourceforge.net ario] &ndash; GTK+ Client with a Rhythmbox like library browser<br />
# pacman -S ario<br />
* [http://gmpcwiki.sarine.nl/index.php?title=GMPC gmpc] &ndash; GNOME Client<br />
# pacman -S gmpc<br />
* [http://bitcheese.net/wiki/QMPDClient QMPDClient] &ndash; Client written with Qt 4.x.<br />
# pacman -S qmpdclient<br />
* [http://sonata.berlios.de/ sonata] &ndash; Python GTK+ Client<br />
# pacman -S sonata<br />
* [http://aur.archlinux.org/packages.php?ID=33380 dmpc] &ndash; Dmenu-based MPC client with a playlist manager and state-saving on playlist changes<br />
Install [http://aur.archlinux.org/packages.php?ID=33380 dmpc] from the [[AUR]].<br />
<br />
See a long list of clients at the [http://mpd.wikia.com/wiki/Clients mpd wiki].<br />
<br />
==Extra stuff==<br />
===Last.fm scrobbling===<br />
To scrobble your songs to [http://www.last.fm Last.fm] using MPD there are several alternatives.<br />
<br />
====mpdscribble====<br />
mpdscribble is another daemon, available in the "community" repository (if you prefer, the "git" version is available in the [http://aur.archlinux.org/packages.php?ID=22274 AUR]). This is arguably the best alternative, because it's the semi-official MPD scrobbler and uses the new "idle" feature in MPD for more accurate scrobbling. Also, you don't need root access to configure it, because it doesn't need any changes to <tt>/etc</tt> at all. Visit [http://mpd.wikia.com/wiki/Client:Mpdscribble the official website] for more information.<br />
<br />
After you have installed mpdscribble, do the following (not as root):<br />
<br />
* {{Codeline|$ mkdir ~/.mpdscribble}}<br />
* Create the file {{Filename|~/.mpdscribble/mpdscribble.conf}} and add the following:<br />
<pre><br />
[mpdscribble] <br />
host = <your mpd host> # optional, defaults to $MPD_HOST or localhost<br />
port = <your mpd port> # optional, defaults to $MPD_PORT or 6600<br />
log = /home/<YOUR_USERNAME>/.mpdscribble/mpdscribble.log<br />
verbose = 2<br />
sleep = 1<br />
musicdir = <your music directory><br />
proxy = <your proxy> # optional, e. g. http://your.proxy:8080, defaults to none<br />
<br />
[last.fm]<br />
# last.fm section, comment if you don't use last.fm<br />
url = http://post.audioscrobbler.com/<br />
username = <your last.fm username><br />
password = <your last.fm password> # md5sum also possible: echo -n 'PASSWORD' | md5sum | cut -f 1 -d " "<br />
journal = /home/<YOUR_USERNAME>/.mpdscribble/lastfm.journal<br />
<br />
[libre.fm]<br />
# libre.fm section, comment if you don't use libre.fm<br />
url = http://turtle.libre.fm/<br />
username = <your libre.fm username><br />
password = <your libre.fm password> # md5sum also possible: echo -n 'PASSWORD' | md5sum | cut -f 1 -d " "<br />
journal = /home/<YOUR_USERNAME>/.mpdscribble/librefm.journal<br />
</pre><br />
* Add {{Codeline|mpdscribble}} to your {{Filename|~/.xinitrc}}:<br />
pidof mpdscribble >& /dev/null<br />
if [ $? -ne 0 ]; then<br />
mpdscribble &<br />
fi<br />
<br />
====Sonata & Ario====<br />
The easiest way, if you don't care about having to have a program window open all the time, is using Sonata or Ario which are graphical frontends to MPD. They have built-in support for Last.fm scrobbling in their preferences. A downside of this is that Sonata doesn't cache your songs if for some reason you don't happen to have an Internet connection at the time of playing.<br />
<br />
====lastfmsubmitd====<br />
lastfmsubmitd is a daemon which is available in the "community" repository. To install it, first edit {{Filename|/etc/lastfmsubmitd.conf}} and add both {{Codeline|lastfmsubmitd}} and {{Codeline|lastmp}} to the {{Codeline|DAEMONS}} array in {{Filename|/etc/rc.conf}}.<br />
<br />
===Last.fm playback with lastfmproxy===<br />
lastfmproxy is a python script that streams a last.fm music stream to another media player. To setup, install [http://aur.archlinux.org/packages.php?ID=14214 lastfmproxy] from the [[AUR]] and then edit {{Filename|/usr/share/lastfmproxy/config.py}}. If you plan to only stream to MPD on the same host, just edit the login info.<br />
<br />
{{Note | Since it installs to a read only directory but it requires read/write access for features like saving previously listened to stations, it would be wise to copy {{Filename|/usr/share/lastfmproxy}} to your home directory.}}<br />
<br />
Start lastfmproxy with {{Codeline|lastfmproxy}} and visit http://localhost:1881/ in your web browser. To add a last.fm station navigate to http://localhost:1881/ followed by the lastfm:// url. Example: http://localhost:1881/lastfm://globaltags/punk . Navigate back to http://localhost:1881/ and download the m3u file by selecting the ''Start Listening'' link. Simply add it to your music library path.<br />
<br />
<br />
===Last.fm playback with lastfmproxy===<br />
<br />
lastfmproxy is a python script that streams a last.fm music stream to another media player. To setup, install lastfmproxy from the AUR and then edit /usr/share/lastfmproxy/config.py. If you plan to only stream to MPD on the same host, just edit the login info.<br />
$ Note: Since it installs to a read only directory but it requires read/write access for features like saving previously listened to stations, it would be wise to copy /usr/share/lastfmproxy to your home directory.<br />
<br />
Start lastfmproxy with lastfmproxy and visit http://localhost:1881/ in your web browser. To add a last.fm station navigate to http://localhost:1881/ followed by the lastfm:// url. Example: http://localhost:1881/lastfm://globaltags/punk . Navigate back to http://localhost:1881/ and download the m3u file by selecting the Start Listening link. Simply add it to your music library path. <br />
<br />
===Native Last.fm playback===<br />
Since 0.16 mpd has a very well working method to play back last.fm streams.<br />
{{File|name=/etc/mpd.conf|content=<br />
$ playlist_plugin {<br />
name "lastfm"<br />
user "my_username"<br />
password "my_password"<br />
}<br />
}}<br />
Then use e.g. mpc to load streams<br />
$ mpc load "lastfm://artist/Beatles"<br />
<br />
===Never play on start===<br />
<br />
This feature has recently been added to mpd git by Martin Kellerman, see commits b57330cf75bcb339e3f268f1019c63e40d305145 and 2fb40fe728ac07574808c40034fc0f3d2254d49d.<br />
<br />
====[https://aur.archlinux.org/packages.php?ID=19676 mpd-git] Method====<br />
This is the best method currently available, but is only currently (April 2011) enabled in the git version. Install [https://aur.archlinux.org/packages.php?ID=19676 mpd-git] from the [[AUR]], then add {{Codeline|restore_paused "yes"}} to your {{Filename|mpd.conf}} file.<br />
<br />
If you have issues with connecting your client to [https://aur.archlinux.org/packages.php?ID=19676 mpd-git], see [[Music Player Daemon#Other issues when attempting to connect to mpd with a client]].<br />
<br />
====Method 1====<br />
If you don't want MPD to always play on your system start, but yet you want to preserve the other state information, add the following lines to your {{Filename|/etc/rc.d/mpd}} file:<br />
'' ...''<br />
'' stat_busy "Starting Music Player Daemon"''<br />
<br />
# always start in paused state<br />
awk '/^state_file[ \t]+"[^"]+"$/ {<br />
match($0, "\".+\"")<br />
sfile = substr($0, RSTART + 1, RLENGTH - 2)<br />
} /^user[ \t]+"[^"]+"$/ {<br />
match($0, "\".+\"")<br />
user = substr($0, RSTART + 1, RLENGTH - 2)<br />
} END {<br />
if (sfile == "")<br />
exit;<br />
if (user != "")<br />
sub(/^~/, "/home/" user, sfile)<br />
system("sed -i \x27s|^\\(state:[ \\t]\\{1,\\}\\)play$|\\1pause|\x27 \x27" sfile "\x27")<br />
}' /etc/mpd.conf<br />
<br />
'' /usr/bin/mpd /etc/mpd.conf &> /dev/null''<br />
'' ...''<br />
<br />
This will change the player status to "paused", if it was stopped while playing. Next, you want this file to be preserved, so MPD updates won't erase this edit. Add (or edit) this line to your {{Filename|/etc/pacman.conf}}:<br />
NoUpgrade = etc/rc.d/mpd<br />
<br />
====Method 2====<br />
<br />
Another simpler method, would be to add mpd to your {{Filename|[[rc.conf]]}} deamons array and add {{Codeline|mpc stop}} or {{Codeline|mpc pause}} to {{Filename|/etc/rc.local.shutdown}} and to {{Filename|/etc/rc.local}}. (Remember you must have mpc installed to use this method).<br />
<br />
Adding only the order in {{Filename|/etc/rc.local}} cannot assure that mpd will play absolutely nothing, since there may be a delay before the stop command is executed. <br />
On the other hand, if you only add the order to {{Filename|/etc/rc.local.shutdown}}, that will assure that mpd won't play at all, as long as you properly shutdown your system.<br />
Even though they are redundant, adding it to {{Filename|/etc/rc.local}} would serve as a safety for those, presumably, rare occasions when you do not shutdown the system properly.<br />
<br />
====Method 3====<br />
<br />
The general idea between this method is to ask mdp to pause music when user logs out so that during next restart, mdp will stick to that "pause" state. Sending such command can be achieve using [http://www.archlinux.org/packages/extra/x86_64/mpc/ mpc], the command line interface to MPD:<br />
pacman -S mpc<br />
<br />
GDM users can then add the next line to /etc/gdm/PostSession/Default (be sure to add it before "exit 0"):<br />
/usr/bin/mpc pause<br />
<br />
Non-GDM users can use their own login manager's method to launch the line at logout.<br />
<br />
===MPD & ALSA===<br />
Sometimes, when you use other audio output, e.g: some web pages containing Flash applets, MPD cannot reproduce anything anymore (until you restart). The error looks something like: (if you search the file {{Filename|/var/log/mpd/mpd.error}})<br />
<br />
Error opening alsa device "hw:0,0": Device or resource busy<br />
<br />
And here is the solution (dmix saving our life again). Apply these lines in your {{Filename|/etc/mpd.conf}}:<br />
<br />
<pre><br />
audio_output {<br />
type "alsa"<br />
name "Sound Card"<br />
options "dev=dmixer"<br />
device "plug:dmix"<br />
}<br />
</pre><br />
<br />
And then restart with {{Codeline|/etc/rc.d/mpd restart}}.<br />
<br />
Searching on Internet I found the reason for why that happens in Gentoo's wiki:<br />
* The sound card does not support hardware mixing (uses '''dmix''' plugin)<br />
* An application does not work with ALSA with it's default settings<br />
<br />
For a detailed description, it is recommended to take a look at [http://mpd.wikia.com/wiki/Alsa this] link. There you can find an example asound.conf which worked for me right out of the box.<br />
<br />
====High CPU usage with ALSA====<br />
When using MPD with ALSA, users may experience MPD taking up lots of CPU (around 20-30%). This is caused by most sound cards supporting 48kHz and most music being 44kHz, thus forcing MPD to resample it. This operation takes lots of CPU cycles and results into high usage.<br />
<br />
For most users the problem should be solved by telling MPD not to use resampling by adding {{Codeline|auto_resample "no"}} into audio_output-part of {{Filename|/etc/mpd.conf}}. This will degrade quality slightly, however.<br />
<br />
Example from {{Filename|mpd.conf}}:<br />
<br />
audio_output {<br />
type "alsa"<br />
name "My ALSA Device"<br />
auto_resample "no"<br />
}<br />
<br />
Although it may not give as drastic a speedup, enabling mmap may speed things up:<br />
<br />
audio_output {<br />
type "alsa"<br />
name "My ALSA Device"<br />
use_mmap "yes"<br />
}<br />
<br />
Some users might also want to tell dmix to use 44kHz as well. More info about tuning performance of your MPD can be found from: [http://mpd.wikia.com/wiki/Tuning MPD wiki]<br />
<br />
====Example configuration: Output with 44.1 KHz at e. g. 16 bit depth, multiple programs at once====<br />
<br />
''Why these formats?'' Because they are standard CDA, because ALSA on its own allows more than one program "to sound" only with dmix — whose resampling algorithm is inferior — and because dmix by default resamples anything lower to 48 KHz (or whatever higher format is playing at the time). Also, some get clicking sounds if at least {{Filename|mpd.conf}} is not changed this way.<br />
<br />
''What's the downside?'' These settings cause ''everything'' (if necessary) to be resampled to this format, such as material from DVD or TV which usually is at 48 KHz. But there is no known way to have ALSA dynamically change the format, and particularly if you listen to far more CDs than anything else the occasional 48 → 44.1 isn't too great a loss.<br />
<br />
The following assumes that there are not already other settings which conflict resp. overwrite it. This applies especially to the current user's potential {{Filename|~/.asoundrc}} — which MPD as its own user ignores, therefore the following should go to {{Filename|/etc/asound.conf}}:<br />
<br />
{{File|name=/etc/asound.conf|content=<br />
defaults.pcm.dmix.rate 44100 # Force 44.1 KHz<br />
defaults.pcm.dmix.format S16_LE # Force 16 bits<br />
}}<br />
<br />
{{File|name=/etc/mpd.conf|content=<br />
audio_output {<br />
type "alsa" # Use the ALSA output plugin.<br />
name "HDA Intel" # Can be called anything or nothing tmk, but must be present.<br />
options "dev=dmixer"<br />
device "plug:dmix" # Both lines cause MPD to output to dmix.<br />
format "44100:16:2" # the actual format<br />
auto_resample "no" # This bypasses ALSA's own algorithms, which generally are inferior. See below how to choose a different one.<br />
use_mmap "yes" # Minor speed improvement, should work with all modern cards.<br />
}<br />
<br />
samplerate_converter "0" # MPD's best, most CPU intensive algorithm. See 'man mpd.conf' for others — for anything other than the poorest "internal", libsamplerate must be installed.<br />
}}<br />
<br />
{{Note|MPD gives the mp3 format a special treatment at decoding: It's always outputted as 24 bit. (The conversion as forced by the ''format'' line only comes after that.)}}<br />
<br />
If one wants to leave the bit depth decision to ALSA resp. MPD, comment out resp. omit the ''dmix.format'' line and change the one for mpd with ''format'' to "44100:*:2".<br />
<br />
{{Note|''Crossfading'' between files decoded at two different bit depths (say, one mp3 and one 16 bit flac) does not work unless conversion is active.}}<br />
<br />
===Control MPD with lirc===<br />
There are already some clients designed for communications between lircd and MPD, however, as far as the practical use, they aren't very useful since their functions are limited.<br />
<br />
It's recommended to use mpc with irexec. mpc is a command line player which only sends the command to MPD and exits immediately, which is perfect for irexec, the command runner included in lirc. What irexec does is that it runs a specified command once received a remote control button.<br />
<br />
First of all, please setup your remotes as referred to the '''[[Lirc]]''' article.<br />
<br />
Edit your favored lirc startup configuration file, default location is {{Filename|~/.lircrc}}.<br />
<br />
Fill the file with the following pattern:<br />
begin<br />
prog = irexec<br />
button = <button_name><br />
config = <command_to_run><br />
repeat = <0 or 1><br />
end<br />
<br />
An useful example:<br />
## irexec<br />
begin<br />
prog = irexec<br />
button = play_pause<br />
config = mpc toggle<br />
repeat = 0<br />
end<br />
<br />
begin<br />
prog = irexec<br />
button = stop<br />
config = mpc stop<br />
repeat = 0<br />
end<br />
begin<br />
prog = irexec<br />
button = previous<br />
config = mpc prev<br />
repeat = 0<br />
end<br />
begin<br />
prog = irexec<br />
button = next<br />
config = mpc next<br />
repeat = 0<br />
end<br />
begin<br />
prog = irexec<br />
button = volup<br />
config = mpc volume +2<br />
repeat = 1<br />
end<br />
begin<br />
prog = irexec<br />
button = voldown<br />
config = mpc volume -2<br />
repeat = 1<br />
end<br />
begin<br />
prog = irexec<br />
button = pbc<br />
config = mpc random<br />
repeat = 0<br />
end<br />
begin<br />
prog = irexec<br />
button = pdvd<br />
config = mpc update<br />
repeat = 0<br />
end<br />
begin<br />
prog = irexec<br />
button = right<br />
config = mpc seek +00:00:05<br />
repeat = 0<br />
end<br />
begin<br />
prog = irexec<br />
button = left<br />
config = mpc seek -00:00:05<br />
repeat = 0<br />
end<br />
begin<br />
prog = irexec<br />
button = up<br />
config = mpc seek +1%<br />
repeat = 0<br />
end<br />
begin<br />
prog = irexec<br />
button = down<br />
config = mpc seek -1%<br />
repeat = 0<br />
end<br />
<br />
There are more functions for mpc, run {{Codeline|man mpc}} for more info.<br />
<br />
===Control MPD with bluetooth phone===<br />
You can also control MPD (to a certain extent) using a bluetooth enabled phone. You need to do the following:<br />
<br />
* install [http://remuco.sourceforge.net/index.php/Remuco remuco] -- a wireless remote control for several Linux media players ([http://aur.archlinux.org/packages.php?ID=25072 aur])<br />
* transfer remuco client -- jar/jad files from {{Filename|/usr/share/remuco/client/}} to your phone and install it<br />
* run {{Codeline|remuco-mpd}} (as current user)<br />
* run remuco on your phone, define a new bluetooth remuco connection (pair first if you haven't done this previously) and explore its capabilities<br />
<br />
More information about remuco including troubleshooting to be found at its [http://remuco.sourceforge.net/index.php/Remuco homepage]<br />
<br />
===MPD & PulseAudio===<br />
<br />
Edit {{Filename|/etc/mpd.conf}}, and uncomment the audio_output section for the type "pulse". The server and sink lines of it should be commented unless you know what you're doing.<br />
<br />
Then, add the mpd user (and yours if you haven't done so already) to the necessary pulse groups. The pulse-access group should be sufficient but you may want to add pulse-rt as well. The group "pulse" doesn't appear to be necessary.<br />
# gpasswd -a mpd pulse-access<br />
# gpasswd -a mpd pulse-rt<br />
<br />
Lastly, you may or may not need to copy {{Filename|~/.pulse-cookie}} from your current (pulse working) user's dir to your mpd user's home directory. It is likely to be {{Filename|/var/lib/mpd}} if you followed the first part of this wiki. This would probably only allow your current user to listen in on MPD's pulse. You may consider running pulse system-wide if that's insufficient.<br />
<br />
===Cue Files===<br />
<br />
To make cue file support actually work, you have to work around a nasty libcue bug. Libcue copied some files directly from libcdio, making it conflict with it. Steps to do to get proper cue support:<br />
<br />
* remove libcdio temporary (pacman -Rdd libcdio)<br />
* install libcue (pacman -S libcue)<br />
* install mpd with abs or from aur.<br />
* reinstall libcdio (pacman -S libcdio)<br />
<br />
At the point of writing mpd does not parse tracknumbers from cue sheets. There is a patch available (http://musicpd.org/mantis/view.php?id=3230)<br />
Once this patch is merged into mpd, i will remove this line :)<br />
<br />
==Troubleshooting==<br />
===Autodetection failed===<br />
During the start of MPD, it tries to autodetect your set-up and configure output and volume control accordingly. Though this mostly goes well, it will fail for some systems. It may help to tell MPD specifically what to use as output and mixer control. If you copied {{Filename|/etc/mpd.conf}} over from {{Filename|/etc/mpd.conf.example}} as mentioned above, you can simply uncomment:<br />
<br />
Example for alsa output type and alsa mixer:<br />
audio_output {<br />
type "alsa"<br />
name "My ALSA Device"<br />
device "hw:0,0" # optional<br />
format "44100:16:2" # optional<br />
mixer_type "hardware"<br />
mixer_device "default"<br />
mixer_control "PCM"<br />
}<br />
<br />
'''Note:''' in case of permission problems when using ESD with MPD run this as root:<br />
# chsh -s /bin/true mpd<br />
<br />
===Executable permissions===<br />
{{Warning|This is not good security practice and may be unnecessary.}}<br />
<br />
MPD needs to have +x permissions on '''ALL''' parent directories to your music collection (ie. if it's located outside of "mpd" home directory /var/lib/mpd). By default useradd sets permissions on home dir to 1700 drwx------. So if you're like me you will need to change permissions of /home/user. Example... my music collection is located /home/user/music. <br />
# chmod a+x /home/$USER<br />
# chmod -R a+X /home/$USER/music<br />
<br />
====Alternative solution====<br />
An alternative solution would be to use your group to share a selection of files, among them your music library. First remove all permissions for the group then add group permissions to read and execute home and music.<br />
# chmod -R g-rwx /home/$USER<br />
# chmod g+rx /home/$USER<br />
# chmod -R g+rX /home/$USER/music<br />
<br />
====Another alternative solution====<br />
Another alternative is to remount the music directory under a directory that mpd has access to. This does not entail the same security risks as modifying the permissions on one's home directory.<br />
# mkdir /var/lib/mpd/music<br />
# echo "/home/$USER/music /var/lib/mpd/music none bind" >> /etc/fstab<br />
# mount -a<br />
# /etc/rc.d/mpd restart<br />
And that should fix the problem. See also [https://bbs.archlinux.org/viewtopic.php?id=86449 the forum thread.]<br />
<br />
===Avoiding timeouts===<br />
To get rid of timeouts (i.e. when you paused music for long time) in gpmc and other clients uncomment and increase {{Codeline|connection_timeout}} option in {{Filename|mpd.conf}}.<br />
<br />
If files and/or titles are shown in wrong encoding, uncomment and change {{Codeline|filesystem_charset}} and {{Codeline|id3v1_encoding}} options.<br />
Note that you cannot set encoding for ID3 v2 tags. To workaround this you may use [http://mpd.wikia.com/wiki/GenericDecoder#Generic_Tagreader external tag readers].<br />
<br />
If you want to use another computer to control MPD over a network, the {{Codeline|bind_to_address}} option in {{Filename|mpd.conf}} will need to be set to either your IP address, or {{Codeline|any}} if your IP address changes frequently. <br />
<br />
'''Streaming'''<br><br />
With the latest version of MPD (0.15), built-in httpd streaming is now available.<br />
<br />
To activate this feature, you'll just need to add a new output of type httpd in {{Filename|mpd.conf}}:<br />
audio_output {<br />
type "httpd"<br />
name "What you want"<br />
encoder "lame" # vorbis or lame supported<br />
port "8000"<br />
bitrate "128"<br />
format "44100:16:2" # change 2 to 1 for mono<br />
}<br />
<br />
Restart the mpd deamon and, from another computer, simply load the stream as any other url. <br />
$ mplayer http://<server's IP>:8000<br />
<br />
{{Note | You must open the port on your router / firewall for the stream to be connectible to from another computer.}}<br />
<br />
Most players (i.e. vlc or xmms2) should also be able to load the stream via their "add url..." menu option.<br />
<br />
This is a nice clean way to replace your current icecast setup with something natively supported within MPD.<br />
<br />
===mpd hangs on first startup===<br />
This is a common error that's caused by corrupt mp3 tags.<br />
Here is an experimental way to solve this issue.<br />
Requirements:<br />
* kid3<br />
* easytag<br />
<br />
This method is very tedious, especially with a huge database. Just as a baseline it took 2.5h to fix a 16Gb DB.<br />
<br />
====Easy Tag====<br />
The purpose of easytag here is that easytag detects the error in the tags, but like MPD it hangs and dies. The trick here is that easy tags actually tells you what file is causing the problem on the status bar.<br />
Before starting easytag make sure to have a terminal close to be ready to kill easy tag to avoid a hang. Once you are ready, on the tree view select the directory where all your music is located. By default easytag starts to search all subdirectories for mp3 files. Once you notice that easytag stopped scanning for songs, make note of the culprit and kill easytag.<br />
<br />
====KID3====<br />
Here's where kid3 comes in handy. With kid3 go to the offending song and rewrite one of the tags. then save the file. This should force kid3 to rewrite the whole tag again fixing the problem with MPD and easy tag hanging.<br />
<br />
Repeat this procedure until your music library is done.<br />
<br />
===Cannot connect to mpd: host "localhost" not found: Temporary failure in name resolution===<br />
Cannot connect to MPD (with ncmpcpp), if you are disconnected from network. Solution is [[IPv6 - Disabling the Module|disable IPv6]] or add line to /etc/hosts<br />
::1 localhost.localdomain localhost<br />
<br />
===Other issues when attempting to connect to mpd with a client===<br />
Some have reported being unable to access mpd with various clients, for example seeing errors like these:<br />
$ ncmpcpp<br />
Cannot connect to mpd: Connection closed by the server<br />
$ sonata<br />
2011-02-13 18:33:05 Connection lost while reading MPD hello<br />
2011-02-13 18:33:05 Not connected<br />
2011-02-13 18:33:05 Not connected<br />
<br />
Please see posts on ncmpcpp on the Arch Forums [https://bbs.archlinux.org/viewtopic.php?id=109962 HERE] and [https://bbs.archlinux.org/viewtopic.php?id=113493 HERE]. Also see the Arch bug report on this issue [https://bugs.archlinux.org/task/22071 HERE]. <br />
<br />
====First fix====<br />
Check {{Filename|mpd.conf}} for a line like {{Codeline|mpd.error}} and remove it. The mpd error file is deprecated and has been removed.<br />
<br />
====Second fix====<br />
{{Note|I'm not so sure this is a good idea. There is a warning about changing the address to bind to in the default mpd.conf. If this does not help, you might want to comment out the changes.}}<br />
If that doesn't help, add the following to {{Filename|mpd.conf}}:<br />
<pre><br />
bind_to_address "127.0.0.1"<br />
port "6600"<br />
</pre><br />
<br />
Afterwards, instruct your client to connect via 127.0.0.1. For example, add the following to the ncmpcpp config file:<br />
<pre><br />
mpd_host "127.0.0.1"<br />
mpd_port "6600"<br />
</pre><br />
<br />
<br />
===Port 6600 already in use===<br />
MPD needs to bind to port 6600 and cannot start if it's already in use. The most common reason for this is that the user has started MPD once and then subsequently tried to start mpd again. In general, nothing should be done here.<br />
<br />
If port 6600 is tied up for some other reason, one can use the following command to find the offending process:<br />
# netstat -tulpan | grep 6600<br />
<br />
This will list IP:Port and the process name holding the connection (root privileges are required to see all processes).<br />
<br />
If you need to restart mpd for whatever reason, use:<br />
<pre><br />
$ mpd --kill<br />
$ mpd <br />
</pre><br />
A more brute-force approach:<br />
<pre><br />
$ killall mpd<br />
$ mpd <br />
</pre><br />
{{Note| If you typically run MPD as root, you will need to run the above commands as root.}}<br />
<br />
In the latest version of MPD, --create-db is completely deprecated. The database will be created automagically on first run and can subsequently be updated via your client (i.e. mpc update). You can now use inotify support to automatically update your music database. Add the following to {{File|name=mpd.conf|content=auto_update "yes"}} to enable it.<br />
<br />
===Binding to IPV6 before IPV4===<br />
If on startup, you see this message:<br />
listen: bind to '0.0.0.0:6600' failed: Address already in use (continuing anyway, because binding to '[::]:6600' succeeded)<br />
MPD is attempting to bind to the ipv6 interface before binding to ipv4. If you want to use your ipv4 interface, hardcode it in mpd.conf, like so:<br />
bind_to_address "127.0.0.1"<br />
Or, you could specify several binds, for example, to have MPD listen on localhost and the external IP of your network card:<br />
bind_to_address "127.0.0.1"<br />
bind_to_address "192.168.1.13"<br />
<br />
===Crackling sound with some audio files===<br />
This is usually a playback speed problem and can be fixed by uncommenting the audio_output_format line in:<br />
<br />
{{File|name=/etc/mpd.conf|content=<br />
audio_output_format "44100:16:2"}}<br />
<br />
This is usually a sane value for most mp3 files.<br />
<br />
===daemon: cannot setgid for user "mpd": Operation not permitted ===<br />
<br />
The error is stating that the user starting the process (you) does not have permissions to become another user (mpd) which the configuration has told that process to run as.<br />
<br />
To solve the issue, simply start mpd as root.<br />
su -c "/etc/rc.d/mpd start"<br />
or<br />
sudo /etc/rc.d/mpd start<br />
<br />
==External links==<br />
* [http://www.musicpd.org/ Official Web Site]<br />
* [http://mpd.wikia.com/wiki/Main_Page Official Wiki]<br />
* [http://mpd.wikia.com/wiki/Clients Sorted List of MPD Clients]<br />
* [http://www.musicpd.org/forum/ MPD forum]</div>Rasihttps://wiki.archlinux.org/index.php?title=Music_Player_Daemon&diff=150761Music Player Daemon2011-08-06T01:06:42Z<p>Rasi: /* lastfmsubmitd */</p>
<hr />
<div>[[fr:MPD]]<br />
[[Category:Audio/Video (English)]]<br />
[[Category:Daemons and system services (English)]]<br />
{{i18n|Music Player Daemon}}<br />
[[pl:Music Player Daemon]]<br />
<br />
'''MPD''' (music player daemon) is an audio player that has a server-client architecture. MPD runs in the background as a daemon, manages playlists and a music database, and uses very few resources. In order to interface with it, you need a separate client. More information can be found on their [http://www.musicpd.org/ website].<br />
<br />
''Please'' have a look at the official page for setup and troubleshooting instructions, the main developer called our wiki page in its current state ''"full of symptom killers"'', hence the official pages should contain better instructions.<br />
<br />
==Installing mpd==<br />
Install with [[pacman]]:<br />
# pacman -S mpd<br />
<br />
==Daemon Setup: Starting at Boot==<br />
General information about MPD configuration may be found at http://mpd.wikia.com/wiki/Configuration.<br />
<br />
===Sound setup===<br />
To make audio output actually work ensure that you have setup audio card and mixer correctly. See [[ALSA]], and [[PulseAudio]] if you are using Gnome 3. Do not forget to unmute the required channels in alsamixer, raise the volume and save changes with alsactl store. Run mpd with {{Filename|/usr/bin/mpd --stdout --no-daemon --verbose}} if that still doesn't work.<br />
<br />
Make sure your card can do hardware mixing (most of them can, including onboard audio). Or else this could cause problems with multiple sound playback. For example, this can prevent Mplayer from playing back sound while the mpd daemon is running, returning an audio error message stating the device is busy.<br />
<br />
===Timeline of MPD's behavior on a typical working setup when started as a daemon===<br />
# MPD is started on boot by {{Filename|/etc/rc.conf}}, by including it in the {{Codeline|DAEMONS}} array. (Or, this can be done manually each session by running {{Codeline|/etc/rc.d/mpd start}} with root privileges).<br />
# Since MPD is now started as root, it first reads the {{Filename|/etc/mpd.conf}} file.<br />
# MPD reads the user variable in the {{Filename|/etc/mpd.conf}} file, and changes from root to this user.<br />
# MPD then reads the contents of the {{Filename|/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 {{Filename|/etc/mpd.conf}} file. This way, uses of {{Codeline|~}} in the configuration file point correctly to the home user's directory, and not root's directory. It may be worthwhile to change all uses of {{Codeline|~}} to {{Codeline|/home/username}} to avoid any confusion over this aspect of MPD's behavior.<br />
<br />
===A clean configuration file===<br />
* As root, check if {{Filename|/etc/mpd.conf}} exists and delete the file if it does. This is safe.<br />
<br />
MPD comes with an example configuration file, available at {{Filename|/usr/share/mpd/mpd.conf.example}}. This file holds an abundance of information on MPD configuration, and holds default mixer values you can simply uncomment.<br />
<br />
* As root, copy this example file to {{Filename|/etc/mpd.conf}}.<br />
# cp /usr/share/mpd/mpd.conf.example /etc/mpd.conf<br />
({{Filename|/usr/share/mpd/mpd.conf.example}} is good for userspace setup)<br />
<br />
Since MPD is being set up to run as a daemon at boot, never put this file in the user's directory like some tutorials suggest, since it will not be read. Moreover, if you previously created a {{Filename|.mpdconf}} file in your home, remove it now (to set up MPD to run with user privileges alone, pleaser refer to the section [[Music_Player_Daemon#Alternative_Setup:_Starting_as_a_User | Alternative_Setup:_Starting_as_a_User]]). This is important to prevent conflicts. The presence of the configuration file in {{Filename|/etc}}, like is the case here, is what will enable MPD to run as a daemon at boot. Otherwise, a script would be needed to run MPD ''after'' the user has logged (like kdm or {{Filename|~/.fluxbox/startup}}) or it would require a manual move each time. For a single music collection, the method used here is simply better, even while the collection is shared to multiple users. Also, don't be afraid about root privileges: even while MPD runs as a daemon, it never completely runs as root since it automatically drops its root privileges after execution.<br />
<br />
===Edit {{Filename|mpd.conf}}===<br />
<br />
The default arch install keeps the setup in /var and uses "mpd" as default user, instead of cluttering up ~/.<br />
Edit {{Filename|/etc/mpd.conf}} to reflect as such.<br />
<br />
{{File|name=/etc/mpd.conf|content=<br />
music_directory "/home/user/music" # Your music dir.<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 "/var/run/mpd/mpd.pid" # Omit this line for systemd<br />
state_file "/var/lib/mpd/mpdstate"<br />
user "mpd"<br />
# Binding to address and port causing problems in mpd-0.14.2 best to leave<br />
# commented.<br />
# bind_to_address "127.0.0.1"<br />
# port "6600"<br />
}}<br />
<br />
* If your music collection is contained under multiple directories, you can make symbolic links under /var/lib/mpd then set 'music_directory' to the directory holding the symbolic links. Remember to set permissions accordingly on the directories being linked.<br />
<br />
* To change the volume of audio from mpd independent of other programs, uncomment or add the switch in mpd.conf:<br />
<br />
{{File|name=/etc/mpd.conf|content=<br />
mixer_type "software"<br />
}}<br />
<br />
* Lastly, if you are running pulseaudio under Gnome 3, the default setting of "alsa" for the audio output will not work. Make the modification from:<br />
{{File|name=/etc/mpd.conf|content=<br />
audio_output {<br />
type "alsa"<br />
name "Sound Card"<br />
}<br />
}}<br />
<br />
to<br />
<br />
{{File|name=/etc/mpd.conf|content=<br />
audio_output {<br />
type "pulse"<br />
name "Sound Card"<br />
}<br />
}}<br />
<br />
===Create files===<br />
<br />
* As root, create the directories and files you specified in {{Filename|/etc/mpd.conf}}.<br />
# mkdir -p /var/lib/mpd/playlists /var/run/mpd<br />
# touch /var/lib/mpd/{mpd.db,mpdstate} && touch /var/run/mpd/mpd.pid<br />
<br />
* You then need to change the file's permissions so that the daemon can modify them.<br />
# chown -R mpd /var/lib/mpd /var/run/mpd<br />
<br />
===Create database===<br />
<br />
Creating the database is now accomplished via the update feature of the client, for example 'mpc update'. The previous method, creating the MPD database as root (# mpd --create-db), is deprecated.<br />
<br />
==Alternative Setup: Starting as a User==<br />
MPD need not be started with root permissions. The only reason why MPD needs to be started as root (by being called from {{Filename|/etc/rc.conf}}) is because the default files and folders in the default configuration file points to directories owned by root (the /var directory). A less common, but perhaps more sensible, approach is to make MPD work with files and directories owned by a normal user. Running MPD as a normal user has several advantages: <br />
# You can easily have a single directory ~/.mpd (or any other directory under /home/username) for all MPD configuration files<br />
# No read/write permission errors<br />
# More flexible calls to MPD by using {{Filename|~/.xinitrc}} instead of including 'mpd' in the {{Filename|/etc/rc.conf}} DAEMONS array.<br />
<br />
The following steps shows how to run MPD as a normal user. '''Note''': this approach will not work if you want multiple users to have access to MPD.<br />
<br />
* Copy the contents of the default MPD configuration file in {{Filename|/usr/share/mpd/mpd.conf.example}} to your home directory. A good place would be {{Filename|"/home/user/.mpd/mpd.conf"}}.<br />
* Follow the 'old setup instructions' from above, ignoring the first part about copying the config to {{Filename|/etc/mpd.conf}} and do not set a user variable. <br />
* Create all of the requisite files in {{filename|"/home/user/.mpd/"}}:<br />
"~/.mpd/playlists/"<br />
"~/.mpd/db"<br />
"~/.mpd/mpd.db"<br />
"~/.mpd/mpd.log"<br />
"~/.mpd/mpd.error"<br />
"~/.mpd/mpd.pid"<br />
"~/.mpd/mpdstate"<br />
<br />
* Let MPD start on bootup by calling it from your {{Filename|~/.xinitrc}} as follows:<br />
# this starts mpd as normal user<br />
mpd ~/.mpd/mpd.conf<br />
{{Note| that you don't have to put a "&" at the end of the line here, since MPD will automatically daemonize itself.}}<br />
<br />
Lastly, delete the entry 'mpd' from your DAEMONS array in {{Filename|/etc/rc.conf}}, as you are not running it as root anymore.<br />
<br />
===Quick setup===<br />
<br />
The fastest way to do set up the structure is to do this:<br />
<br />
$ mkdir -p ~/.mpd/playlists && touch ~/.mpd/database && cp /usr/share/doc/mpd/mpdconf.example ~/.mpd/mpd.conf<br />
<br />
Then edit mpd.conf to your liking, in a manner similar to [[Music_Player_Daemon#Edit_mpd.conf]]. Beware that you must uncomment the db_file entry if you do edit mpd.conf.<br />
<br />
Then, to run it:<br />
<br />
$ mpd ~/.mpd/mpd.conf<br />
<br />
<br />
===Even quicker setup===<br />
I created a little script that will only ask for the location of your music and then creates the needed files and folders for you.<br />
You can find the script here:<br />
[http://karif.server-speed.net/~carnager/mpdsetup.tar]<br />
extract it<br />
$ tar xf mpdsetup.tar<br />
and run it<br />
$ ./mpdsetup.sh<br />
<br />
If you want to use this config in daemon mode, open it (~/.mpdconf) in an editor and find the "user" line. remove the comment (#) and fill in your own user name. Then copy the file to /etc/mpd.conf. If running mpd as user is fine for you, make sure to remove "mpd" from the daemons list in /etc/rc.conf<br />
<br />
===Multi-mpd setup===<br />
'''Useful if you want to run for example an icecast server.'''<br />
If you want a second MPD daemon (e.g., with icecast output to share music over the network) to use the same music and playlist as the one above, simply copy the above configuration file and make a new file (e.g., {{Filename|/home/username/.mpd/config-icecast}}), and only change the log_file, error_file, pid_file, and state_file parameters (e.g., {{Filename|mpd-icecast.log}}, {{Filename|mpd-icecast.error}}, and so on); using the same directory paths for the music and playlist directories would ensure that this second mpd daemon would use the same music collection as your first one (e.g., creating and editing a playlist under the first daemon would affect the second daemon as well, so that you don't have to create the same playlists all over again for the second daemon). Then, call this second daemon the same way from your {{Filename|~/.xinitrc}} above. (Just be sure to have a different port number, so as to not conflict with your first mpd daemon).<br />
<br />
==Clients==<br />
Install a client program for MPD. Popular options are:<br />
<br />
===Console===<br />
* '''mpc''' &ndash; Command Line Client (you'll probably want this one no matter what)<br />
# pacman -S mpc<br />
* [http://mpd.wikia.com/wiki/Client:Ncmpc/ ncmpc] &ndash; NCurses Client (this one is very handy for running in a console)<br />
# pacman -S ncmpc<br />
* [http://unkart.ovh.org/ncmpcpp/ ncmpcpp] &ndash; Clone of ncmpc with some new features written in C++<br />
# pacman -S ncmpcpp<br />
* [http://pms.sourceforge.net/ pms] &ndash; NCurses Client (highly configurable and accessible)<br />
Install [http://aur.archlinux.org/packages.php?ID=24378 pmus] from the [[AUR]].<br />
<br />
===Graphical===<br />
* [http://ario-player.sourceforge.net ario] &ndash; GTK+ Client with a Rhythmbox like library browser<br />
# pacman -S ario<br />
* [http://gmpcwiki.sarine.nl/index.php?title=GMPC gmpc] &ndash; GNOME Client<br />
# pacman -S gmpc<br />
* [http://bitcheese.net/wiki/QMPDClient QMPDClient] &ndash; Client written with Qt 4.x.<br />
# pacman -S qmpdclient<br />
* [http://sonata.berlios.de/ sonata] &ndash; Python GTK+ Client<br />
# pacman -S sonata<br />
* [http://aur.archlinux.org/packages.php?ID=33380 dmpc] &ndash; Dmenu-based MPC client with a playlist manager and state-saving on playlist changes<br />
Install [http://aur.archlinux.org/packages.php?ID=33380 dmpc] from the [[AUR]].<br />
<br />
See a long list of clients at the [http://mpd.wikia.com/wiki/Clients mpd wiki].<br />
<br />
==Extra stuff==<br />
===Last.fm scrobbling===<br />
To scrobble your songs to [http://www.last.fm Last.fm] using MPD there are several alternatives.<br />
<br />
====mpdscribble====<br />
mpdscribble is another daemon, available in the "community" repository (if you prefer, the "git" version is available in the [http://aur.archlinux.org/packages.php?ID=22274 AUR]). This is arguably the best alternative, because it's the semi-official MPD scrobbler and uses the new "idle" feature in MPD for more accurate scrobbling. Also, you don't need root access to configure it, because it doesn't need any changes to <tt>/etc</tt> at all. Visit [http://mpd.wikia.com/wiki/Client:Mpdscribble the official website] for more information.<br />
<br />
After you have installed mpdscribble, do the following (not as root):<br />
<br />
* {{Codeline|$ mkdir ~/.mpdscribble}}<br />
* Create the file {{Filename|~/.mpdscribble/mpdscribble.conf}} and add the following:<br />
<pre><br />
[mpdscribble] <br />
host = <your mpd host> # optional, defaults to $MPD_HOST or localhost<br />
port = <your mpd port> # optional, defaults to $MPD_PORT or 6600<br />
log = /home/<YOUR_USERNAME>/.mpdscribble/mpdscribble.log<br />
verbose = 2<br />
sleep = 1<br />
musicdir = <your music directory><br />
proxy = <your proxy> # optional, e. g. http://your.proxy:8080, defaults to none<br />
<br />
[last.fm]<br />
# last.fm section, comment if you don't use last.fm<br />
url = http://post.audioscrobbler.com/<br />
username = <your last.fm username><br />
password = <your last.fm password> # md5sum also possible: echo -n 'PASSWORD' | md5sum | cut -f 1 -d " "<br />
journal = /home/<YOUR_USERNAME>/.mpdscribble/lastfm.journal<br />
<br />
[libre.fm]<br />
# libre.fm section, comment if you don't use libre.fm<br />
url = http://turtle.libre.fm/<br />
username = <your libre.fm username><br />
password = <your libre.fm password> # md5sum also possible: echo -n 'PASSWORD' | md5sum | cut -f 1 -d " "<br />
journal = /home/<YOUR_USERNAME>/.mpdscribble/librefm.journal<br />
</pre><br />
* Add {{Codeline|mpdscribble}} to your {{Filename|~/.xinitrc}}:<br />
pidof mpdscribble >& /dev/null<br />
if [ $? -ne 0 ]; then<br />
mpdscribble &<br />
fi<br />
<br />
====Sonata & Ario====<br />
The easiest way, if you don't care about having to have a program window open all the time, is using Sonata or Ario which are graphical frontends to MPD. They have built-in support for Last.fm scrobbling in their preferences. A downside of this is that Sonata doesn't cache your songs if for some reason you don't happen to have an Internet connection at the time of playing.<br />
<br />
====lastfmsubmitd====<br />
lastfmsubmitd is a daemon which is available in the "community" repository. To install it, first edit {{Filename|/etc/lastfmsubmitd.conf}} and add both {{Codeline|lastfmsubmitd}} and {{Codeline|lastmp}} to the {{Codeline|DAEMONS}} array in {{Filename|/etc/rc.conf}}.<br />
<br />
===Last.fm playback with lastfmproxy===<br />
lastfmproxy is a python script that streams a last.fm music stream to another media player. To setup, install [http://aur.archlinux.org/packages.php?ID=14214 lastfmproxy] from the [[AUR]] and then edit {{Filename|/usr/share/lastfmproxy/config.py}}. If you plan to only stream to MPD on the same host, just edit the login info.<br />
<br />
{{Note | Since it installs to a read only directory but it requires read/write access for features like saving previously listened to stations, it would be wise to copy {{Filename|/usr/share/lastfmproxy}} to your home directory.}}<br />
<br />
Start lastfmproxy with {{Codeline|lastfmproxy}} and visit http://localhost:1881/ in your web browser. To add a last.fm station navigate to http://localhost:1881/ followed by the lastfm:// url. Example: http://localhost:1881/lastfm://globaltags/punk . Navigate back to http://localhost:1881/ and download the m3u file by selecting the ''Start Listening'' link. Simply add it to your music library path.<br />
<br />
<br />
===Native Last.fm playback===<br />
Since 0.16 mpd has a very well working method to play back last.fm streams.<br />
{{File|name=/etc/mpd.conf|content=<br />
$ playlist_plugin {<br />
name "lastfm"<br />
user "my_username"<br />
password "my_password"<br />
}<br />
}}<br />
Then use e.g. mpc to load streams<br />
$ mpc load "lastfm://artist/Beatles"<br />
<br />
===Never play on start===<br />
<br />
This feature has recently been added to mpd git by Martin Kellerman, see commits b57330cf75bcb339e3f268f1019c63e40d305145 and 2fb40fe728ac07574808c40034fc0f3d2254d49d.<br />
<br />
====[https://aur.archlinux.org/packages.php?ID=19676 mpd-git] Method====<br />
This is the best method currently available, but is only currently (April 2011) enabled in the git version. Install [https://aur.archlinux.org/packages.php?ID=19676 mpd-git] from the [[AUR]], then add {{Codeline|restore_paused "yes"}} to your {{Filename|mpd.conf}} file.<br />
<br />
If you have issues with connecting your client to [https://aur.archlinux.org/packages.php?ID=19676 mpd-git], see [[Music Player Daemon#Other issues when attempting to connect to mpd with a client]].<br />
<br />
====Method 1====<br />
If you don't want MPD to always play on your system start, but yet you want to preserve the other state information, add the following lines to your {{Filename|/etc/rc.d/mpd}} file:<br />
'' ...''<br />
'' stat_busy "Starting Music Player Daemon"''<br />
<br />
# always start in paused state<br />
awk '/^state_file[ \t]+"[^"]+"$/ {<br />
match($0, "\".+\"")<br />
sfile = substr($0, RSTART + 1, RLENGTH - 2)<br />
} /^user[ \t]+"[^"]+"$/ {<br />
match($0, "\".+\"")<br />
user = substr($0, RSTART + 1, RLENGTH - 2)<br />
} END {<br />
if (sfile == "")<br />
exit;<br />
if (user != "")<br />
sub(/^~/, "/home/" user, sfile)<br />
system("sed -i \x27s|^\\(state:[ \\t]\\{1,\\}\\)play$|\\1pause|\x27 \x27" sfile "\x27")<br />
}' /etc/mpd.conf<br />
<br />
'' /usr/bin/mpd /etc/mpd.conf &> /dev/null''<br />
'' ...''<br />
<br />
This will change the player status to "paused", if it was stopped while playing. Next, you want this file to be preserved, so MPD updates won't erase this edit. Add (or edit) this line to your {{Filename|/etc/pacman.conf}}:<br />
NoUpgrade = etc/rc.d/mpd<br />
<br />
====Method 2====<br />
<br />
Another simpler method, would be to add mpd to your {{Filename|[[rc.conf]]}} deamons array and add {{Codeline|mpc stop}} or {{Codeline|mpc pause}} to {{Filename|/etc/rc.local.shutdown}} and to {{Filename|/etc/rc.local}}. (Remember you must have mpc installed to use this method).<br />
<br />
Adding only the order in {{Filename|/etc/rc.local}} cannot assure that mpd will play absolutely nothing, since there may be a delay before the stop command is executed. <br />
On the other hand, if you only add the order to {{Filename|/etc/rc.local.shutdown}}, that will assure that mpd won't play at all, as long as you properly shutdown your system.<br />
Even though they are redundant, adding it to {{Filename|/etc/rc.local}} would serve as a safety for those, presumably, rare occasions when you do not shutdown the system properly.<br />
<br />
====Method 3====<br />
<br />
The general idea between this method is to ask mdp to pause music when user logs out so that during next restart, mdp will stick to that "pause" state. Sending such command can be achieve using [http://www.archlinux.org/packages/extra/x86_64/mpc/ mpc], the command line interface to MPD:<br />
pacman -S mpc<br />
<br />
GDM users can then add the next line to /etc/gdm/PostSession/Default (be sure to add it before "exit 0"):<br />
/usr/bin/mpc pause<br />
<br />
Non-GDM users can use their own login manager's method to launch the line at logout.<br />
<br />
===MPD & ALSA===<br />
Sometimes, when you use other audio output, e.g: some web pages containing Flash applets, MPD cannot reproduce anything anymore (until you restart). The error looks something like: (if you search the file {{Filename|/var/log/mpd/mpd.error}})<br />
<br />
Error opening alsa device "hw:0,0": Device or resource busy<br />
<br />
And here is the solution (dmix saving our life again). Apply these lines in your {{Filename|/etc/mpd.conf}}:<br />
<br />
<pre><br />
audio_output {<br />
type "alsa"<br />
name "Sound Card"<br />
options "dev=dmixer"<br />
device "plug:dmix"<br />
}<br />
</pre><br />
<br />
And then restart with {{Codeline|/etc/rc.d/mpd restart}}.<br />
<br />
Searching on Internet I found the reason for why that happens in Gentoo's wiki:<br />
* The sound card does not support hardware mixing (uses '''dmix''' plugin)<br />
* An application does not work with ALSA with it's default settings<br />
<br />
For a detailed description, it is recommended to take a look at [http://mpd.wikia.com/wiki/Alsa this] link. There you can find an example asound.conf which worked for me right out of the box.<br />
<br />
====High CPU usage with ALSA====<br />
When using MPD with ALSA, users may experience MPD taking up lots of CPU (around 20-30%). This is caused by most sound cards supporting 48kHz and most music being 44kHz, thus forcing MPD to resample it. This operation takes lots of CPU cycles and results into high usage.<br />
<br />
For most users the problem should be solved by telling MPD not to use resampling by adding {{Codeline|auto_resample "no"}} into audio_output-part of {{Filename|/etc/mpd.conf}}. This will degrade quality slightly, however.<br />
<br />
Example from {{Filename|mpd.conf}}:<br />
<br />
audio_output {<br />
type "alsa"<br />
name "My ALSA Device"<br />
auto_resample "no"<br />
}<br />
<br />
Although it may not give as drastic a speedup, enabling mmap may speed things up:<br />
<br />
audio_output {<br />
type "alsa"<br />
name "My ALSA Device"<br />
use_mmap "yes"<br />
}<br />
<br />
Some users might also want to tell dmix to use 44kHz as well. More info about tuning performance of your MPD can be found from: [http://mpd.wikia.com/wiki/Tuning MPD wiki]<br />
<br />
====Example configuration: Output with 44.1 KHz at e. g. 16 bit depth, multiple programs at once====<br />
<br />
''Why these formats?'' Because they are standard CDA, because ALSA on its own allows more than one program "to sound" only with dmix — whose resampling algorithm is inferior — and because dmix by default resamples anything lower to 48 KHz (or whatever higher format is playing at the time). Also, some get clicking sounds if at least {{Filename|mpd.conf}} is not changed this way.<br />
<br />
''What's the downside?'' These settings cause ''everything'' (if necessary) to be resampled to this format, such as material from DVD or TV which usually is at 48 KHz. But there is no known way to have ALSA dynamically change the format, and particularly if you listen to far more CDs than anything else the occasional 48 → 44.1 isn't too great a loss.<br />
<br />
The following assumes that there are not already other settings which conflict resp. overwrite it. This applies especially to the current user's potential {{Filename|~/.asoundrc}} — which MPD as its own user ignores, therefore the following should go to {{Filename|/etc/asound.conf}}:<br />
<br />
{{File|name=/etc/asound.conf|content=<br />
defaults.pcm.dmix.rate 44100 # Force 44.1 KHz<br />
defaults.pcm.dmix.format S16_LE # Force 16 bits<br />
}}<br />
<br />
{{File|name=/etc/mpd.conf|content=<br />
audio_output {<br />
type "alsa" # Use the ALSA output plugin.<br />
name "HDA Intel" # Can be called anything or nothing tmk, but must be present.<br />
options "dev=dmixer"<br />
device "plug:dmix" # Both lines cause MPD to output to dmix.<br />
format "44100:16:2" # the actual format<br />
auto_resample "no" # This bypasses ALSA's own algorithms, which generally are inferior. See below how to choose a different one.<br />
use_mmap "yes" # Minor speed improvement, should work with all modern cards.<br />
}<br />
<br />
samplerate_converter "0" # MPD's best, most CPU intensive algorithm. See 'man mpd.conf' for others — for anything other than the poorest "internal", libsamplerate must be installed.<br />
}}<br />
<br />
{{Note|MPD gives the mp3 format a special treatment at decoding: It's always outputted as 24 bit. (The conversion as forced by the ''format'' line only comes after that.)}}<br />
<br />
If one wants to leave the bit depth decision to ALSA resp. MPD, comment out resp. omit the ''dmix.format'' line and change the one for mpd with ''format'' to "44100:*:2".<br />
<br />
{{Note|''Crossfading'' between files decoded at two different bit depths (say, one mp3 and one 16 bit flac) does not work unless conversion is active.}}<br />
<br />
===Control MPD with lirc===<br />
There are already some clients designed for communications between lircd and MPD, however, as far as the practical use, they aren't very useful since their functions are limited.<br />
<br />
It's recommended to use mpc with irexec. mpc is a command line player which only sends the command to MPD and exits immediately, which is perfect for irexec, the command runner included in lirc. What irexec does is that it runs a specified command once received a remote control button.<br />
<br />
First of all, please setup your remotes as referred to the '''[[Lirc]]''' article.<br />
<br />
Edit your favored lirc startup configuration file, default location is {{Filename|~/.lircrc}}.<br />
<br />
Fill the file with the following pattern:<br />
begin<br />
prog = irexec<br />
button = <button_name><br />
config = <command_to_run><br />
repeat = <0 or 1><br />
end<br />
<br />
An useful example:<br />
## irexec<br />
begin<br />
prog = irexec<br />
button = play_pause<br />
config = mpc toggle<br />
repeat = 0<br />
end<br />
<br />
begin<br />
prog = irexec<br />
button = stop<br />
config = mpc stop<br />
repeat = 0<br />
end<br />
begin<br />
prog = irexec<br />
button = previous<br />
config = mpc prev<br />
repeat = 0<br />
end<br />
begin<br />
prog = irexec<br />
button = next<br />
config = mpc next<br />
repeat = 0<br />
end<br />
begin<br />
prog = irexec<br />
button = volup<br />
config = mpc volume +2<br />
repeat = 1<br />
end<br />
begin<br />
prog = irexec<br />
button = voldown<br />
config = mpc volume -2<br />
repeat = 1<br />
end<br />
begin<br />
prog = irexec<br />
button = pbc<br />
config = mpc random<br />
repeat = 0<br />
end<br />
begin<br />
prog = irexec<br />
button = pdvd<br />
config = mpc update<br />
repeat = 0<br />
end<br />
begin<br />
prog = irexec<br />
button = right<br />
config = mpc seek +00:00:05<br />
repeat = 0<br />
end<br />
begin<br />
prog = irexec<br />
button = left<br />
config = mpc seek -00:00:05<br />
repeat = 0<br />
end<br />
begin<br />
prog = irexec<br />
button = up<br />
config = mpc seek +1%<br />
repeat = 0<br />
end<br />
begin<br />
prog = irexec<br />
button = down<br />
config = mpc seek -1%<br />
repeat = 0<br />
end<br />
<br />
There are more functions for mpc, run {{Codeline|man mpc}} for more info.<br />
<br />
===Control MPD with bluetooth phone===<br />
You can also control MPD (to a certain extent) using a bluetooth enabled phone. You need to do the following:<br />
<br />
* install [http://remuco.sourceforge.net/index.php/Remuco remuco] -- a wireless remote control for several Linux media players ([http://aur.archlinux.org/packages.php?ID=25072 aur])<br />
* transfer remuco client -- jar/jad files from {{Filename|/usr/share/remuco/client/}} to your phone and install it<br />
* run {{Codeline|remuco-mpd}} (as current user)<br />
* run remuco on your phone, define a new bluetooth remuco connection (pair first if you haven't done this previously) and explore its capabilities<br />
<br />
More information about remuco including troubleshooting to be found at its [http://remuco.sourceforge.net/index.php/Remuco homepage]<br />
<br />
===MPD & PulseAudio===<br />
<br />
Edit {{Filename|/etc/mpd.conf}}, and uncomment the audio_output section for the type "pulse". The server and sink lines of it should be commented unless you know what you're doing.<br />
<br />
Then, add the mpd user (and yours if you haven't done so already) to the necessary pulse groups. The pulse-access group should be sufficient but you may want to add pulse-rt as well. The group "pulse" doesn't appear to be necessary.<br />
# gpasswd -a mpd pulse-access<br />
# gpasswd -a mpd pulse-rt<br />
<br />
Lastly, you may or may not need to copy {{Filename|~/.pulse-cookie}} from your current (pulse working) user's dir to your mpd user's home directory. It is likely to be {{Filename|/var/lib/mpd}} if you followed the first part of this wiki. This would probably only allow your current user to listen in on MPD's pulse. You may consider running pulse system-wide if that's insufficient.<br />
<br />
===Cue Files===<br />
<br />
To make cue file support actually work, you have to work around a nasty libcue bug. Libcue copied some files directly from libcdio, making it conflict with it. Steps to do to get proper cue support:<br />
<br />
* remove libcdio temporary (pacman -Rdd libcdio)<br />
* install libcue (pacman -S libcue)<br />
* install mpd with abs or from aur.<br />
* reinstall libcdio (pacman -S libcdio)<br />
<br />
At the point of writing mpd does not parse tracknumbers from cue sheets. There is a patch available (http://musicpd.org/mantis/view.php?id=3230)<br />
Once this patch is merged into mpd, i will remove this line :)<br />
<br />
==Troubleshooting==<br />
===Autodetection failed===<br />
During the start of MPD, it tries to autodetect your set-up and configure output and volume control accordingly. Though this mostly goes well, it will fail for some systems. It may help to tell MPD specifically what to use as output and mixer control. If you copied {{Filename|/etc/mpd.conf}} over from {{Filename|/etc/mpd.conf.example}} as mentioned above, you can simply uncomment:<br />
<br />
Example for alsa output type and alsa mixer:<br />
audio_output {<br />
type "alsa"<br />
name "My ALSA Device"<br />
device "hw:0,0" # optional<br />
format "44100:16:2" # optional<br />
mixer_type "hardware"<br />
mixer_device "default"<br />
mixer_control "PCM"<br />
}<br />
<br />
'''Note:''' in case of permission problems when using ESD with MPD run this as root:<br />
# chsh -s /bin/true mpd<br />
<br />
===Executable permissions===<br />
{{Warning|This is not good security practice and may be unnecessary.}}<br />
<br />
MPD needs to have +x permissions on '''ALL''' parent directories to your music collection (ie. if it's located outside of "mpd" home directory /var/lib/mpd). By default useradd sets permissions on home dir to 1700 drwx------. So if you're like me you will need to change permissions of /home/user. Example... my music collection is located /home/user/music. <br />
# chmod a+x /home/$USER<br />
# chmod -R a+X /home/$USER/music<br />
<br />
====Alternative solution====<br />
An alternative solution would be to use your group to share a selection of files, among them your music library. First remove all permissions for the group then add group permissions to read and execute home and music.<br />
# chmod -R g-rwx /home/$USER<br />
# chmod g+rx /home/$USER<br />
# chmod -R g+rX /home/$USER/music<br />
<br />
====Another alternative solution====<br />
Another alternative is to remount the music directory under a directory that mpd has access to. This does not entail the same security risks as modifying the permissions on one's home directory.<br />
# mkdir /var/lib/mpd/music<br />
# echo "/home/$USER/music /var/lib/mpd/music none bind" >> /etc/fstab<br />
# mount -a<br />
# /etc/rc.d/mpd restart<br />
And that should fix the problem. See also [https://bbs.archlinux.org/viewtopic.php?id=86449 the forum thread.]<br />
<br />
===Avoiding timeouts===<br />
To get rid of timeouts (i.e. when you paused music for long time) in gpmc and other clients uncomment and increase {{Codeline|connection_timeout}} option in {{Filename|mpd.conf}}.<br />
<br />
If files and/or titles are shown in wrong encoding, uncomment and change {{Codeline|filesystem_charset}} and {{Codeline|id3v1_encoding}} options.<br />
Note that you cannot set encoding for ID3 v2 tags. To workaround this you may use [http://mpd.wikia.com/wiki/GenericDecoder#Generic_Tagreader external tag readers].<br />
<br />
If you want to use another computer to control MPD over a network, the {{Codeline|bind_to_address}} option in {{Filename|mpd.conf}} will need to be set to either your IP address, or {{Codeline|any}} if your IP address changes frequently. <br />
<br />
'''Streaming'''<br><br />
With the latest version of MPD (0.15), built-in httpd streaming is now available.<br />
<br />
To activate this feature, you'll just need to add a new output of type httpd in {{Filename|mpd.conf}}:<br />
audio_output {<br />
type "httpd"<br />
name "What you want"<br />
encoder "lame" # vorbis or lame supported<br />
port "8000"<br />
bitrate "128"<br />
format "44100:16:2" # change 2 to 1 for mono<br />
}<br />
<br />
Restart the mpd deamon and, from another computer, simply load the stream as any other url. <br />
$ mplayer http://<server's IP>:8000<br />
<br />
{{Note | You must open the port on your router / firewall for the stream to be connectible to from another computer.}}<br />
<br />
Most players (i.e. vlc or xmms2) should also be able to load the stream via their "add url..." menu option.<br />
<br />
This is a nice clean way to replace your current icecast setup with something natively supported within MPD.<br />
<br />
===mpd hangs on first startup===<br />
This is a common error that's caused by corrupt mp3 tags.<br />
Here is an experimental way to solve this issue.<br />
Requirements:<br />
* kid3<br />
* easytag<br />
<br />
This method is very tedious, especially with a huge database. Just as a baseline it took 2.5h to fix a 16Gb DB.<br />
<br />
====Easy Tag====<br />
The purpose of easytag here is that easytag detects the error in the tags, but like MPD it hangs and dies. The trick here is that easy tags actually tells you what file is causing the problem on the status bar.<br />
Before starting easytag make sure to have a terminal close to be ready to kill easy tag to avoid a hang. Once you are ready, on the tree view select the directory where all your music is located. By default easytag starts to search all subdirectories for mp3 files. Once you notice that easytag stopped scanning for songs, make note of the culprit and kill easytag.<br />
<br />
====KID3====<br />
Here's where kid3 comes in handy. With kid3 go to the offending song and rewrite one of the tags. then save the file. This should force kid3 to rewrite the whole tag again fixing the problem with MPD and easy tag hanging.<br />
<br />
Repeat this procedure until your music library is done.<br />
<br />
===Cannot connect to mpd: host "localhost" not found: Temporary failure in name resolution===<br />
Cannot connect to MPD (with ncmpcpp), if you are disconnected from network. Solution is [[IPv6 - Disabling the Module|disable IPv6]] or add line to /etc/hosts<br />
::1 localhost.localdomain localhost<br />
<br />
===Other issues when attempting to connect to mpd with a client===<br />
Some have reported being unable to access mpd with various clients, for example seeing errors like these:<br />
$ ncmpcpp<br />
Cannot connect to mpd: Connection closed by the server<br />
$ sonata<br />
2011-02-13 18:33:05 Connection lost while reading MPD hello<br />
2011-02-13 18:33:05 Not connected<br />
2011-02-13 18:33:05 Not connected<br />
<br />
Please see posts on ncmpcpp on the Arch Forums [https://bbs.archlinux.org/viewtopic.php?id=109962 HERE] and [https://bbs.archlinux.org/viewtopic.php?id=113493 HERE]. Also see the Arch bug report on this issue [https://bugs.archlinux.org/task/22071 HERE]. <br />
<br />
====First fix====<br />
Check {{Filename|mpd.conf}} for a line like {{Codeline|mpd.error}} and remove it. The mpd error file is deprecated and has been removed.<br />
<br />
====Second fix====<br />
{{Note|I'm not so sure this is a good idea. There is a warning about changing the address to bind to in the default mpd.conf. If this does not help, you might want to comment out the changes.}}<br />
If that doesn't help, add the following to {{Filename|mpd.conf}}:<br />
<pre><br />
bind_to_address "127.0.0.1"<br />
port "6600"<br />
</pre><br />
<br />
Afterwards, instruct your client to connect via 127.0.0.1. For example, add the following to the ncmpcpp config file:<br />
<pre><br />
mpd_host "127.0.0.1"<br />
mpd_port "6600"<br />
</pre><br />
<br />
<br />
===Port 6600 already in use===<br />
MPD needs to bind to port 6600 and cannot start if it's already in use. The most common reason for this is that the user has started MPD once and then subsequently tried to start mpd again. In general, nothing should be done here.<br />
<br />
If port 6600 is tied up for some other reason, one can use the following command to find the offending process:<br />
# netstat -tulpan | grep 6600<br />
<br />
This will list IP:Port and the process name holding the connection (root privileges are required to see all processes).<br />
<br />
If you need to restart mpd for whatever reason, use:<br />
<pre><br />
$ mpd --kill<br />
$ mpd <br />
</pre><br />
A more brute-force approach:<br />
<pre><br />
$ killall mpd<br />
$ mpd <br />
</pre><br />
{{Note| If you typically run MPD as root, you will need to run the above commands as root.}}<br />
<br />
In the latest version of MPD, --create-db is completely deprecated. The database will be created automagically on first run and can subsequently be updated via your client (i.e. mpc update). You can now use inotify support to automatically update your music database. Add the following to {{File|name=mpd.conf|content=auto_update "yes"}} to enable it.<br />
<br />
===Binding to IPV6 before IPV4===<br />
If on startup, you see this message:<br />
listen: bind to '0.0.0.0:6600' failed: Address already in use (continuing anyway, because binding to '[::]:6600' succeeded)<br />
MPD is attempting to bind to the ipv6 interface before binding to ipv4. If you want to use your ipv4 interface, hardcode it in mpd.conf, like so:<br />
bind_to_address "127.0.0.1"<br />
Or, you could specify several binds, for example, to have MPD listen on localhost and the external IP of your network card:<br />
bind_to_address "127.0.0.1"<br />
bind_to_address "192.168.1.13"<br />
<br />
===Crackling sound with some audio files===<br />
This is usually a playback speed problem and can be fixed by uncommenting the audio_output_format line in:<br />
<br />
{{File|name=/etc/mpd.conf|content=<br />
audio_output_format "44100:16:2"}}<br />
<br />
This is usually a sane value for most mp3 files.<br />
<br />
===daemon: cannot setgid for user "mpd": Operation not permitted ===<br />
<br />
The error is stating that the user starting the process (you) does not have permissions to become another user (mpd) which the configuration has told that process to run as.<br />
<br />
To solve the issue, simply start mpd as root.<br />
su -c "/etc/rc.d/mpd start"<br />
or<br />
sudo /etc/rc.d/mpd start<br />
<br />
==External links==<br />
* [http://www.musicpd.org/ Official Web Site]<br />
* [http://mpd.wikia.com/wiki/Main_Page Official Wiki]<br />
* [http://mpd.wikia.com/wiki/Clients Sorted List of MPD Clients]<br />
* [http://www.musicpd.org/forum/ MPD forum]</div>Rasihttps://wiki.archlinux.org/index.php?title=Music_Player_Daemon&diff=150760Music Player Daemon2011-08-06T01:06:10Z<p>Rasi: /* Last.fm playback with lastfmproxy */</p>
<hr />
<div>[[fr:MPD]]<br />
[[Category:Audio/Video (English)]]<br />
[[Category:Daemons and system services (English)]]<br />
{{i18n|Music Player Daemon}}<br />
[[pl:Music Player Daemon]]<br />
<br />
'''MPD''' (music player daemon) is an audio player that has a server-client architecture. MPD runs in the background as a daemon, manages playlists and a music database, and uses very few resources. In order to interface with it, you need a separate client. More information can be found on their [http://www.musicpd.org/ website].<br />
<br />
''Please'' have a look at the official page for setup and troubleshooting instructions, the main developer called our wiki page in its current state ''"full of symptom killers"'', hence the official pages should contain better instructions.<br />
<br />
==Installing mpd==<br />
Install with [[pacman]]:<br />
# pacman -S mpd<br />
<br />
==Daemon Setup: Starting at Boot==<br />
General information about MPD configuration may be found at http://mpd.wikia.com/wiki/Configuration.<br />
<br />
===Sound setup===<br />
To make audio output actually work ensure that you have setup audio card and mixer correctly. See [[ALSA]], and [[PulseAudio]] if you are using Gnome 3. Do not forget to unmute the required channels in alsamixer, raise the volume and save changes with alsactl store. Run mpd with {{Filename|/usr/bin/mpd --stdout --no-daemon --verbose}} if that still doesn't work.<br />
<br />
Make sure your card can do hardware mixing (most of them can, including onboard audio). Or else this could cause problems with multiple sound playback. For example, this can prevent Mplayer from playing back sound while the mpd daemon is running, returning an audio error message stating the device is busy.<br />
<br />
===Timeline of MPD's behavior on a typical working setup when started as a daemon===<br />
# MPD is started on boot by {{Filename|/etc/rc.conf}}, by including it in the {{Codeline|DAEMONS}} array. (Or, this can be done manually each session by running {{Codeline|/etc/rc.d/mpd start}} with root privileges).<br />
# Since MPD is now started as root, it first reads the {{Filename|/etc/mpd.conf}} file.<br />
# MPD reads the user variable in the {{Filename|/etc/mpd.conf}} file, and changes from root to this user.<br />
# MPD then reads the contents of the {{Filename|/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 {{Filename|/etc/mpd.conf}} file. This way, uses of {{Codeline|~}} in the configuration file point correctly to the home user's directory, and not root's directory. It may be worthwhile to change all uses of {{Codeline|~}} to {{Codeline|/home/username}} to avoid any confusion over this aspect of MPD's behavior.<br />
<br />
===A clean configuration file===<br />
* As root, check if {{Filename|/etc/mpd.conf}} exists and delete the file if it does. This is safe.<br />
<br />
MPD comes with an example configuration file, available at {{Filename|/usr/share/mpd/mpd.conf.example}}. This file holds an abundance of information on MPD configuration, and holds default mixer values you can simply uncomment.<br />
<br />
* As root, copy this example file to {{Filename|/etc/mpd.conf}}.<br />
# cp /usr/share/mpd/mpd.conf.example /etc/mpd.conf<br />
({{Filename|/usr/share/mpd/mpd.conf.example}} is good for userspace setup)<br />
<br />
Since MPD is being set up to run as a daemon at boot, never put this file in the user's directory like some tutorials suggest, since it will not be read. Moreover, if you previously created a {{Filename|.mpdconf}} file in your home, remove it now (to set up MPD to run with user privileges alone, pleaser refer to the section [[Music_Player_Daemon#Alternative_Setup:_Starting_as_a_User | Alternative_Setup:_Starting_as_a_User]]). This is important to prevent conflicts. The presence of the configuration file in {{Filename|/etc}}, like is the case here, is what will enable MPD to run as a daemon at boot. Otherwise, a script would be needed to run MPD ''after'' the user has logged (like kdm or {{Filename|~/.fluxbox/startup}}) or it would require a manual move each time. For a single music collection, the method used here is simply better, even while the collection is shared to multiple users. Also, don't be afraid about root privileges: even while MPD runs as a daemon, it never completely runs as root since it automatically drops its root privileges after execution.<br />
<br />
===Edit {{Filename|mpd.conf}}===<br />
<br />
The default arch install keeps the setup in /var and uses "mpd" as default user, instead of cluttering up ~/.<br />
Edit {{Filename|/etc/mpd.conf}} to reflect as such.<br />
<br />
{{File|name=/etc/mpd.conf|content=<br />
music_directory "/home/user/music" # Your music dir.<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 "/var/run/mpd/mpd.pid" # Omit this line for systemd<br />
state_file "/var/lib/mpd/mpdstate"<br />
user "mpd"<br />
# Binding to address and port causing problems in mpd-0.14.2 best to leave<br />
# commented.<br />
# bind_to_address "127.0.0.1"<br />
# port "6600"<br />
}}<br />
<br />
* If your music collection is contained under multiple directories, you can make symbolic links under /var/lib/mpd then set 'music_directory' to the directory holding the symbolic links. Remember to set permissions accordingly on the directories being linked.<br />
<br />
* To change the volume of audio from mpd independent of other programs, uncomment or add the switch in mpd.conf:<br />
<br />
{{File|name=/etc/mpd.conf|content=<br />
mixer_type "software"<br />
}}<br />
<br />
* Lastly, if you are running pulseaudio under Gnome 3, the default setting of "alsa" for the audio output will not work. Make the modification from:<br />
{{File|name=/etc/mpd.conf|content=<br />
audio_output {<br />
type "alsa"<br />
name "Sound Card"<br />
}<br />
}}<br />
<br />
to<br />
<br />
{{File|name=/etc/mpd.conf|content=<br />
audio_output {<br />
type "pulse"<br />
name "Sound Card"<br />
}<br />
}}<br />
<br />
===Create files===<br />
<br />
* As root, create the directories and files you specified in {{Filename|/etc/mpd.conf}}.<br />
# mkdir -p /var/lib/mpd/playlists /var/run/mpd<br />
# touch /var/lib/mpd/{mpd.db,mpdstate} && touch /var/run/mpd/mpd.pid<br />
<br />
* You then need to change the file's permissions so that the daemon can modify them.<br />
# chown -R mpd /var/lib/mpd /var/run/mpd<br />
<br />
===Create database===<br />
<br />
Creating the database is now accomplished via the update feature of the client, for example 'mpc update'. The previous method, creating the MPD database as root (# mpd --create-db), is deprecated.<br />
<br />
==Alternative Setup: Starting as a User==<br />
MPD need not be started with root permissions. The only reason why MPD needs to be started as root (by being called from {{Filename|/etc/rc.conf}}) is because the default files and folders in the default configuration file points to directories owned by root (the /var directory). A less common, but perhaps more sensible, approach is to make MPD work with files and directories owned by a normal user. Running MPD as a normal user has several advantages: <br />
# You can easily have a single directory ~/.mpd (or any other directory under /home/username) for all MPD configuration files<br />
# No read/write permission errors<br />
# More flexible calls to MPD by using {{Filename|~/.xinitrc}} instead of including 'mpd' in the {{Filename|/etc/rc.conf}} DAEMONS array.<br />
<br />
The following steps shows how to run MPD as a normal user. '''Note''': this approach will not work if you want multiple users to have access to MPD.<br />
<br />
* Copy the contents of the default MPD configuration file in {{Filename|/usr/share/mpd/mpd.conf.example}} to your home directory. A good place would be {{Filename|"/home/user/.mpd/mpd.conf"}}.<br />
* Follow the 'old setup instructions' from above, ignoring the first part about copying the config to {{Filename|/etc/mpd.conf}} and do not set a user variable. <br />
* Create all of the requisite files in {{filename|"/home/user/.mpd/"}}:<br />
"~/.mpd/playlists/"<br />
"~/.mpd/db"<br />
"~/.mpd/mpd.db"<br />
"~/.mpd/mpd.log"<br />
"~/.mpd/mpd.error"<br />
"~/.mpd/mpd.pid"<br />
"~/.mpd/mpdstate"<br />
<br />
* Let MPD start on bootup by calling it from your {{Filename|~/.xinitrc}} as follows:<br />
# this starts mpd as normal user<br />
mpd ~/.mpd/mpd.conf<br />
{{Note| that you don't have to put a "&" at the end of the line here, since MPD will automatically daemonize itself.}}<br />
<br />
Lastly, delete the entry 'mpd' from your DAEMONS array in {{Filename|/etc/rc.conf}}, as you are not running it as root anymore.<br />
<br />
===Quick setup===<br />
<br />
The fastest way to do set up the structure is to do this:<br />
<br />
$ mkdir -p ~/.mpd/playlists && touch ~/.mpd/database && cp /usr/share/doc/mpd/mpdconf.example ~/.mpd/mpd.conf<br />
<br />
Then edit mpd.conf to your liking, in a manner similar to [[Music_Player_Daemon#Edit_mpd.conf]]. Beware that you must uncomment the db_file entry if you do edit mpd.conf.<br />
<br />
Then, to run it:<br />
<br />
$ mpd ~/.mpd/mpd.conf<br />
<br />
<br />
===Even quicker setup===<br />
I created a little script that will only ask for the location of your music and then creates the needed files and folders for you.<br />
You can find the script here:<br />
[http://karif.server-speed.net/~carnager/mpdsetup.tar]<br />
extract it<br />
$ tar xf mpdsetup.tar<br />
and run it<br />
$ ./mpdsetup.sh<br />
<br />
If you want to use this config in daemon mode, open it (~/.mpdconf) in an editor and find the "user" line. remove the comment (#) and fill in your own user name. Then copy the file to /etc/mpd.conf. If running mpd as user is fine for you, make sure to remove "mpd" from the daemons list in /etc/rc.conf<br />
<br />
===Multi-mpd setup===<br />
'''Useful if you want to run for example an icecast server.'''<br />
If you want a second MPD daemon (e.g., with icecast output to share music over the network) to use the same music and playlist as the one above, simply copy the above configuration file and make a new file (e.g., {{Filename|/home/username/.mpd/config-icecast}}), and only change the log_file, error_file, pid_file, and state_file parameters (e.g., {{Filename|mpd-icecast.log}}, {{Filename|mpd-icecast.error}}, and so on); using the same directory paths for the music and playlist directories would ensure that this second mpd daemon would use the same music collection as your first one (e.g., creating and editing a playlist under the first daemon would affect the second daemon as well, so that you don't have to create the same playlists all over again for the second daemon). Then, call this second daemon the same way from your {{Filename|~/.xinitrc}} above. (Just be sure to have a different port number, so as to not conflict with your first mpd daemon).<br />
<br />
==Clients==<br />
Install a client program for MPD. Popular options are:<br />
<br />
===Console===<br />
* '''mpc''' &ndash; Command Line Client (you'll probably want this one no matter what)<br />
# pacman -S mpc<br />
* [http://mpd.wikia.com/wiki/Client:Ncmpc/ ncmpc] &ndash; NCurses Client (this one is very handy for running in a console)<br />
# pacman -S ncmpc<br />
* [http://unkart.ovh.org/ncmpcpp/ ncmpcpp] &ndash; Clone of ncmpc with some new features written in C++<br />
# pacman -S ncmpcpp<br />
* [http://pms.sourceforge.net/ pms] &ndash; NCurses Client (highly configurable and accessible)<br />
Install [http://aur.archlinux.org/packages.php?ID=24378 pmus] from the [[AUR]].<br />
<br />
===Graphical===<br />
* [http://ario-player.sourceforge.net ario] &ndash; GTK+ Client with a Rhythmbox like library browser<br />
# pacman -S ario<br />
* [http://gmpcwiki.sarine.nl/index.php?title=GMPC gmpc] &ndash; GNOME Client<br />
# pacman -S gmpc<br />
* [http://bitcheese.net/wiki/QMPDClient QMPDClient] &ndash; Client written with Qt 4.x.<br />
# pacman -S qmpdclient<br />
* [http://sonata.berlios.de/ sonata] &ndash; Python GTK+ Client<br />
# pacman -S sonata<br />
* [http://aur.archlinux.org/packages.php?ID=33380 dmpc] &ndash; Dmenu-based MPC client with a playlist manager and state-saving on playlist changes<br />
Install [http://aur.archlinux.org/packages.php?ID=33380 dmpc] from the [[AUR]].<br />
<br />
See a long list of clients at the [http://mpd.wikia.com/wiki/Clients mpd wiki].<br />
<br />
==Extra stuff==<br />
===Last.fm scrobbling===<br />
To scrobble your songs to [http://www.last.fm Last.fm] using MPD there are several alternatives.<br />
<br />
====mpdscribble====<br />
mpdscribble is another daemon, available in the "community" repository (if you prefer, the "git" version is available in the [http://aur.archlinux.org/packages.php?ID=22274 AUR]). This is arguably the best alternative, because it's the semi-official MPD scrobbler and uses the new "idle" feature in MPD for more accurate scrobbling. Also, you don't need root access to configure it, because it doesn't need any changes to <tt>/etc</tt> at all. Visit [http://mpd.wikia.com/wiki/Client:Mpdscribble the official website] for more information.<br />
<br />
After you have installed mpdscribble, do the following (not as root):<br />
<br />
* {{Codeline|$ mkdir ~/.mpdscribble}}<br />
* Create the file {{Filename|~/.mpdscribble/mpdscribble.conf}} and add the following:<br />
<pre><br />
[mpdscribble] <br />
host = <your mpd host> # optional, defaults to $MPD_HOST or localhost<br />
port = <your mpd port> # optional, defaults to $MPD_PORT or 6600<br />
log = /home/<YOUR_USERNAME>/.mpdscribble/mpdscribble.log<br />
verbose = 2<br />
sleep = 1<br />
musicdir = <your music directory><br />
proxy = <your proxy> # optional, e. g. http://your.proxy:8080, defaults to none<br />
<br />
[last.fm]<br />
# last.fm section, comment if you don't use last.fm<br />
url = http://post.audioscrobbler.com/<br />
username = <your last.fm username><br />
password = <your last.fm password> # md5sum also possible: echo -n 'PASSWORD' | md5sum | cut -f 1 -d " "<br />
journal = /home/<YOUR_USERNAME>/.mpdscribble/lastfm.journal<br />
<br />
[libre.fm]<br />
# libre.fm section, comment if you don't use libre.fm<br />
url = http://turtle.libre.fm/<br />
username = <your libre.fm username><br />
password = <your libre.fm password> # md5sum also possible: echo -n 'PASSWORD' | md5sum | cut -f 1 -d " "<br />
journal = /home/<YOUR_USERNAME>/.mpdscribble/librefm.journal<br />
</pre><br />
* Add {{Codeline|mpdscribble}} to your {{Filename|~/.xinitrc}}:<br />
pidof mpdscribble >& /dev/null<br />
if [ $? -ne 0 ]; then<br />
mpdscribble &<br />
fi<br />
<br />
====Sonata & Ario====<br />
The easiest way, if you don't care about having to have a program window open all the time, is using Sonata or Ario which are graphical frontends to MPD. They have built-in support for Last.fm scrobbling in their preferences. A downside of this is that Sonata doesn't cache your songs if for some reason you don't happen to have an Internet connection at the time of playing.<br />
<br />
====lastfmsubmitd====<br />
lastfmsubmitd is a daemon which is available in the "community" repository. To install it, first edit {{Filename|/etc/lastfmsubmitd.conf}} and add both {{Codeline|lastfmsubmitd}} and {{Codeline|lastmp}} to the {{Codeline|DAEMONS}} array in {{Filename|/etc/rc.conf}}.<br />
<br />
*** NOTE *** this feature is built into MPD. look below<br />
<br />
<br />
===Last.fm playback with lastfmproxy===<br />
lastfmproxy is a python script that streams a last.fm music stream to another media player. To setup, install [http://aur.archlinux.org/packages.php?ID=14214 lastfmproxy] from the [[AUR]] and then edit {{Filename|/usr/share/lastfmproxy/config.py}}. If you plan to only stream to MPD on the same host, just edit the login info.<br />
<br />
{{Note | Since it installs to a read only directory but it requires read/write access for features like saving previously listened to stations, it would be wise to copy {{Filename|/usr/share/lastfmproxy}} to your home directory.}}<br />
<br />
Start lastfmproxy with {{Codeline|lastfmproxy}} and visit http://localhost:1881/ in your web browser. To add a last.fm station navigate to http://localhost:1881/ followed by the lastfm:// url. Example: http://localhost:1881/lastfm://globaltags/punk . Navigate back to http://localhost:1881/ and download the m3u file by selecting the ''Start Listening'' link. Simply add it to your music library path.<br />
<br />
<br />
===Native Last.fm playback===<br />
Since 0.16 mpd has a very well working method to play back last.fm streams.<br />
{{File|name=/etc/mpd.conf|content=<br />
$ playlist_plugin {<br />
name "lastfm"<br />
user "my_username"<br />
password "my_password"<br />
}<br />
}}<br />
Then use e.g. mpc to load streams<br />
$ mpc load "lastfm://artist/Beatles"<br />
<br />
===Never play on start===<br />
<br />
This feature has recently been added to mpd git by Martin Kellerman, see commits b57330cf75bcb339e3f268f1019c63e40d305145 and 2fb40fe728ac07574808c40034fc0f3d2254d49d.<br />
<br />
====[https://aur.archlinux.org/packages.php?ID=19676 mpd-git] Method====<br />
This is the best method currently available, but is only currently (April 2011) enabled in the git version. Install [https://aur.archlinux.org/packages.php?ID=19676 mpd-git] from the [[AUR]], then add {{Codeline|restore_paused "yes"}} to your {{Filename|mpd.conf}} file.<br />
<br />
If you have issues with connecting your client to [https://aur.archlinux.org/packages.php?ID=19676 mpd-git], see [[Music Player Daemon#Other issues when attempting to connect to mpd with a client]].<br />
<br />
====Method 1====<br />
If you don't want MPD to always play on your system start, but yet you want to preserve the other state information, add the following lines to your {{Filename|/etc/rc.d/mpd}} file:<br />
'' ...''<br />
'' stat_busy "Starting Music Player Daemon"''<br />
<br />
# always start in paused state<br />
awk '/^state_file[ \t]+"[^"]+"$/ {<br />
match($0, "\".+\"")<br />
sfile = substr($0, RSTART + 1, RLENGTH - 2)<br />
} /^user[ \t]+"[^"]+"$/ {<br />
match($0, "\".+\"")<br />
user = substr($0, RSTART + 1, RLENGTH - 2)<br />
} END {<br />
if (sfile == "")<br />
exit;<br />
if (user != "")<br />
sub(/^~/, "/home/" user, sfile)<br />
system("sed -i \x27s|^\\(state:[ \\t]\\{1,\\}\\)play$|\\1pause|\x27 \x27" sfile "\x27")<br />
}' /etc/mpd.conf<br />
<br />
'' /usr/bin/mpd /etc/mpd.conf &> /dev/null''<br />
'' ...''<br />
<br />
This will change the player status to "paused", if it was stopped while playing. Next, you want this file to be preserved, so MPD updates won't erase this edit. Add (or edit) this line to your {{Filename|/etc/pacman.conf}}:<br />
NoUpgrade = etc/rc.d/mpd<br />
<br />
====Method 2====<br />
<br />
Another simpler method, would be to add mpd to your {{Filename|[[rc.conf]]}} deamons array and add {{Codeline|mpc stop}} or {{Codeline|mpc pause}} to {{Filename|/etc/rc.local.shutdown}} and to {{Filename|/etc/rc.local}}. (Remember you must have mpc installed to use this method).<br />
<br />
Adding only the order in {{Filename|/etc/rc.local}} cannot assure that mpd will play absolutely nothing, since there may be a delay before the stop command is executed. <br />
On the other hand, if you only add the order to {{Filename|/etc/rc.local.shutdown}}, that will assure that mpd won't play at all, as long as you properly shutdown your system.<br />
Even though they are redundant, adding it to {{Filename|/etc/rc.local}} would serve as a safety for those, presumably, rare occasions when you do not shutdown the system properly.<br />
<br />
====Method 3====<br />
<br />
The general idea between this method is to ask mdp to pause music when user logs out so that during next restart, mdp will stick to that "pause" state. Sending such command can be achieve using [http://www.archlinux.org/packages/extra/x86_64/mpc/ mpc], the command line interface to MPD:<br />
pacman -S mpc<br />
<br />
GDM users can then add the next line to /etc/gdm/PostSession/Default (be sure to add it before "exit 0"):<br />
/usr/bin/mpc pause<br />
<br />
Non-GDM users can use their own login manager's method to launch the line at logout.<br />
<br />
===MPD & ALSA===<br />
Sometimes, when you use other audio output, e.g: some web pages containing Flash applets, MPD cannot reproduce anything anymore (until you restart). The error looks something like: (if you search the file {{Filename|/var/log/mpd/mpd.error}})<br />
<br />
Error opening alsa device "hw:0,0": Device or resource busy<br />
<br />
And here is the solution (dmix saving our life again). Apply these lines in your {{Filename|/etc/mpd.conf}}:<br />
<br />
<pre><br />
audio_output {<br />
type "alsa"<br />
name "Sound Card"<br />
options "dev=dmixer"<br />
device "plug:dmix"<br />
}<br />
</pre><br />
<br />
And then restart with {{Codeline|/etc/rc.d/mpd restart}}.<br />
<br />
Searching on Internet I found the reason for why that happens in Gentoo's wiki:<br />
* The sound card does not support hardware mixing (uses '''dmix''' plugin)<br />
* An application does not work with ALSA with it's default settings<br />
<br />
For a detailed description, it is recommended to take a look at [http://mpd.wikia.com/wiki/Alsa this] link. There you can find an example asound.conf which worked for me right out of the box.<br />
<br />
====High CPU usage with ALSA====<br />
When using MPD with ALSA, users may experience MPD taking up lots of CPU (around 20-30%). This is caused by most sound cards supporting 48kHz and most music being 44kHz, thus forcing MPD to resample it. This operation takes lots of CPU cycles and results into high usage.<br />
<br />
For most users the problem should be solved by telling MPD not to use resampling by adding {{Codeline|auto_resample "no"}} into audio_output-part of {{Filename|/etc/mpd.conf}}. This will degrade quality slightly, however.<br />
<br />
Example from {{Filename|mpd.conf}}:<br />
<br />
audio_output {<br />
type "alsa"<br />
name "My ALSA Device"<br />
auto_resample "no"<br />
}<br />
<br />
Although it may not give as drastic a speedup, enabling mmap may speed things up:<br />
<br />
audio_output {<br />
type "alsa"<br />
name "My ALSA Device"<br />
use_mmap "yes"<br />
}<br />
<br />
Some users might also want to tell dmix to use 44kHz as well. More info about tuning performance of your MPD can be found from: [http://mpd.wikia.com/wiki/Tuning MPD wiki]<br />
<br />
====Example configuration: Output with 44.1 KHz at e. g. 16 bit depth, multiple programs at once====<br />
<br />
''Why these formats?'' Because they are standard CDA, because ALSA on its own allows more than one program "to sound" only with dmix — whose resampling algorithm is inferior — and because dmix by default resamples anything lower to 48 KHz (or whatever higher format is playing at the time). Also, some get clicking sounds if at least {{Filename|mpd.conf}} is not changed this way.<br />
<br />
''What's the downside?'' These settings cause ''everything'' (if necessary) to be resampled to this format, such as material from DVD or TV which usually is at 48 KHz. But there is no known way to have ALSA dynamically change the format, and particularly if you listen to far more CDs than anything else the occasional 48 → 44.1 isn't too great a loss.<br />
<br />
The following assumes that there are not already other settings which conflict resp. overwrite it. This applies especially to the current user's potential {{Filename|~/.asoundrc}} — which MPD as its own user ignores, therefore the following should go to {{Filename|/etc/asound.conf}}:<br />
<br />
{{File|name=/etc/asound.conf|content=<br />
defaults.pcm.dmix.rate 44100 # Force 44.1 KHz<br />
defaults.pcm.dmix.format S16_LE # Force 16 bits<br />
}}<br />
<br />
{{File|name=/etc/mpd.conf|content=<br />
audio_output {<br />
type "alsa" # Use the ALSA output plugin.<br />
name "HDA Intel" # Can be called anything or nothing tmk, but must be present.<br />
options "dev=dmixer"<br />
device "plug:dmix" # Both lines cause MPD to output to dmix.<br />
format "44100:16:2" # the actual format<br />
auto_resample "no" # This bypasses ALSA's own algorithms, which generally are inferior. See below how to choose a different one.<br />
use_mmap "yes" # Minor speed improvement, should work with all modern cards.<br />
}<br />
<br />
samplerate_converter "0" # MPD's best, most CPU intensive algorithm. See 'man mpd.conf' for others — for anything other than the poorest "internal", libsamplerate must be installed.<br />
}}<br />
<br />
{{Note|MPD gives the mp3 format a special treatment at decoding: It's always outputted as 24 bit. (The conversion as forced by the ''format'' line only comes after that.)}}<br />
<br />
If one wants to leave the bit depth decision to ALSA resp. MPD, comment out resp. omit the ''dmix.format'' line and change the one for mpd with ''format'' to "44100:*:2".<br />
<br />
{{Note|''Crossfading'' between files decoded at two different bit depths (say, one mp3 and one 16 bit flac) does not work unless conversion is active.}}<br />
<br />
===Control MPD with lirc===<br />
There are already some clients designed for communications between lircd and MPD, however, as far as the practical use, they aren't very useful since their functions are limited.<br />
<br />
It's recommended to use mpc with irexec. mpc is a command line player which only sends the command to MPD and exits immediately, which is perfect for irexec, the command runner included in lirc. What irexec does is that it runs a specified command once received a remote control button.<br />
<br />
First of all, please setup your remotes as referred to the '''[[Lirc]]''' article.<br />
<br />
Edit your favored lirc startup configuration file, default location is {{Filename|~/.lircrc}}.<br />
<br />
Fill the file with the following pattern:<br />
begin<br />
prog = irexec<br />
button = <button_name><br />
config = <command_to_run><br />
repeat = <0 or 1><br />
end<br />
<br />
An useful example:<br />
## irexec<br />
begin<br />
prog = irexec<br />
button = play_pause<br />
config = mpc toggle<br />
repeat = 0<br />
end<br />
<br />
begin<br />
prog = irexec<br />
button = stop<br />
config = mpc stop<br />
repeat = 0<br />
end<br />
begin<br />
prog = irexec<br />
button = previous<br />
config = mpc prev<br />
repeat = 0<br />
end<br />
begin<br />
prog = irexec<br />
button = next<br />
config = mpc next<br />
repeat = 0<br />
end<br />
begin<br />
prog = irexec<br />
button = volup<br />
config = mpc volume +2<br />
repeat = 1<br />
end<br />
begin<br />
prog = irexec<br />
button = voldown<br />
config = mpc volume -2<br />
repeat = 1<br />
end<br />
begin<br />
prog = irexec<br />
button = pbc<br />
config = mpc random<br />
repeat = 0<br />
end<br />
begin<br />
prog = irexec<br />
button = pdvd<br />
config = mpc update<br />
repeat = 0<br />
end<br />
begin<br />
prog = irexec<br />
button = right<br />
config = mpc seek +00:00:05<br />
repeat = 0<br />
end<br />
begin<br />
prog = irexec<br />
button = left<br />
config = mpc seek -00:00:05<br />
repeat = 0<br />
end<br />
begin<br />
prog = irexec<br />
button = up<br />
config = mpc seek +1%<br />
repeat = 0<br />
end<br />
begin<br />
prog = irexec<br />
button = down<br />
config = mpc seek -1%<br />
repeat = 0<br />
end<br />
<br />
There are more functions for mpc, run {{Codeline|man mpc}} for more info.<br />
<br />
===Control MPD with bluetooth phone===<br />
You can also control MPD (to a certain extent) using a bluetooth enabled phone. You need to do the following:<br />
<br />
* install [http://remuco.sourceforge.net/index.php/Remuco remuco] -- a wireless remote control for several Linux media players ([http://aur.archlinux.org/packages.php?ID=25072 aur])<br />
* transfer remuco client -- jar/jad files from {{Filename|/usr/share/remuco/client/}} to your phone and install it<br />
* run {{Codeline|remuco-mpd}} (as current user)<br />
* run remuco on your phone, define a new bluetooth remuco connection (pair first if you haven't done this previously) and explore its capabilities<br />
<br />
More information about remuco including troubleshooting to be found at its [http://remuco.sourceforge.net/index.php/Remuco homepage]<br />
<br />
===MPD & PulseAudio===<br />
<br />
Edit {{Filename|/etc/mpd.conf}}, and uncomment the audio_output section for the type "pulse". The server and sink lines of it should be commented unless you know what you're doing.<br />
<br />
Then, add the mpd user (and yours if you haven't done so already) to the necessary pulse groups. The pulse-access group should be sufficient but you may want to add pulse-rt as well. The group "pulse" doesn't appear to be necessary.<br />
# gpasswd -a mpd pulse-access<br />
# gpasswd -a mpd pulse-rt<br />
<br />
Lastly, you may or may not need to copy {{Filename|~/.pulse-cookie}} from your current (pulse working) user's dir to your mpd user's home directory. It is likely to be {{Filename|/var/lib/mpd}} if you followed the first part of this wiki. This would probably only allow your current user to listen in on MPD's pulse. You may consider running pulse system-wide if that's insufficient.<br />
<br />
===Cue Files===<br />
<br />
To make cue file support actually work, you have to work around a nasty libcue bug. Libcue copied some files directly from libcdio, making it conflict with it. Steps to do to get proper cue support:<br />
<br />
* remove libcdio temporary (pacman -Rdd libcdio)<br />
* install libcue (pacman -S libcue)<br />
* install mpd with abs or from aur.<br />
* reinstall libcdio (pacman -S libcdio)<br />
<br />
At the point of writing mpd does not parse tracknumbers from cue sheets. There is a patch available (http://musicpd.org/mantis/view.php?id=3230)<br />
Once this patch is merged into mpd, i will remove this line :)<br />
<br />
==Troubleshooting==<br />
===Autodetection failed===<br />
During the start of MPD, it tries to autodetect your set-up and configure output and volume control accordingly. Though this mostly goes well, it will fail for some systems. It may help to tell MPD specifically what to use as output and mixer control. If you copied {{Filename|/etc/mpd.conf}} over from {{Filename|/etc/mpd.conf.example}} as mentioned above, you can simply uncomment:<br />
<br />
Example for alsa output type and alsa mixer:<br />
audio_output {<br />
type "alsa"<br />
name "My ALSA Device"<br />
device "hw:0,0" # optional<br />
format "44100:16:2" # optional<br />
mixer_type "hardware"<br />
mixer_device "default"<br />
mixer_control "PCM"<br />
}<br />
<br />
'''Note:''' in case of permission problems when using ESD with MPD run this as root:<br />
# chsh -s /bin/true mpd<br />
<br />
===Executable permissions===<br />
{{Warning|This is not good security practice and may be unnecessary.}}<br />
<br />
MPD needs to have +x permissions on '''ALL''' parent directories to your music collection (ie. if it's located outside of "mpd" home directory /var/lib/mpd). By default useradd sets permissions on home dir to 1700 drwx------. So if you're like me you will need to change permissions of /home/user. Example... my music collection is located /home/user/music. <br />
# chmod a+x /home/$USER<br />
# chmod -R a+X /home/$USER/music<br />
<br />
====Alternative solution====<br />
An alternative solution would be to use your group to share a selection of files, among them your music library. First remove all permissions for the group then add group permissions to read and execute home and music.<br />
# chmod -R g-rwx /home/$USER<br />
# chmod g+rx /home/$USER<br />
# chmod -R g+rX /home/$USER/music<br />
<br />
====Another alternative solution====<br />
Another alternative is to remount the music directory under a directory that mpd has access to. This does not entail the same security risks as modifying the permissions on one's home directory.<br />
# mkdir /var/lib/mpd/music<br />
# echo "/home/$USER/music /var/lib/mpd/music none bind" >> /etc/fstab<br />
# mount -a<br />
# /etc/rc.d/mpd restart<br />
And that should fix the problem. See also [https://bbs.archlinux.org/viewtopic.php?id=86449 the forum thread.]<br />
<br />
===Avoiding timeouts===<br />
To get rid of timeouts (i.e. when you paused music for long time) in gpmc and other clients uncomment and increase {{Codeline|connection_timeout}} option in {{Filename|mpd.conf}}.<br />
<br />
If files and/or titles are shown in wrong encoding, uncomment and change {{Codeline|filesystem_charset}} and {{Codeline|id3v1_encoding}} options.<br />
Note that you cannot set encoding for ID3 v2 tags. To workaround this you may use [http://mpd.wikia.com/wiki/GenericDecoder#Generic_Tagreader external tag readers].<br />
<br />
If you want to use another computer to control MPD over a network, the {{Codeline|bind_to_address}} option in {{Filename|mpd.conf}} will need to be set to either your IP address, or {{Codeline|any}} if your IP address changes frequently. <br />
<br />
'''Streaming'''<br><br />
With the latest version of MPD (0.15), built-in httpd streaming is now available.<br />
<br />
To activate this feature, you'll just need to add a new output of type httpd in {{Filename|mpd.conf}}:<br />
audio_output {<br />
type "httpd"<br />
name "What you want"<br />
encoder "lame" # vorbis or lame supported<br />
port "8000"<br />
bitrate "128"<br />
format "44100:16:2" # change 2 to 1 for mono<br />
}<br />
<br />
Restart the mpd deamon and, from another computer, simply load the stream as any other url. <br />
$ mplayer http://<server's IP>:8000<br />
<br />
{{Note | You must open the port on your router / firewall for the stream to be connectible to from another computer.}}<br />
<br />
Most players (i.e. vlc or xmms2) should also be able to load the stream via their "add url..." menu option.<br />
<br />
This is a nice clean way to replace your current icecast setup with something natively supported within MPD.<br />
<br />
===mpd hangs on first startup===<br />
This is a common error that's caused by corrupt mp3 tags.<br />
Here is an experimental way to solve this issue.<br />
Requirements:<br />
* kid3<br />
* easytag<br />
<br />
This method is very tedious, especially with a huge database. Just as a baseline it took 2.5h to fix a 16Gb DB.<br />
<br />
====Easy Tag====<br />
The purpose of easytag here is that easytag detects the error in the tags, but like MPD it hangs and dies. The trick here is that easy tags actually tells you what file is causing the problem on the status bar.<br />
Before starting easytag make sure to have a terminal close to be ready to kill easy tag to avoid a hang. Once you are ready, on the tree view select the directory where all your music is located. By default easytag starts to search all subdirectories for mp3 files. Once you notice that easytag stopped scanning for songs, make note of the culprit and kill easytag.<br />
<br />
====KID3====<br />
Here's where kid3 comes in handy. With kid3 go to the offending song and rewrite one of the tags. then save the file. This should force kid3 to rewrite the whole tag again fixing the problem with MPD and easy tag hanging.<br />
<br />
Repeat this procedure until your music library is done.<br />
<br />
===Cannot connect to mpd: host "localhost" not found: Temporary failure in name resolution===<br />
Cannot connect to MPD (with ncmpcpp), if you are disconnected from network. Solution is [[IPv6 - Disabling the Module|disable IPv6]] or add line to /etc/hosts<br />
::1 localhost.localdomain localhost<br />
<br />
===Other issues when attempting to connect to mpd with a client===<br />
Some have reported being unable to access mpd with various clients, for example seeing errors like these:<br />
$ ncmpcpp<br />
Cannot connect to mpd: Connection closed by the server<br />
$ sonata<br />
2011-02-13 18:33:05 Connection lost while reading MPD hello<br />
2011-02-13 18:33:05 Not connected<br />
2011-02-13 18:33:05 Not connected<br />
<br />
Please see posts on ncmpcpp on the Arch Forums [https://bbs.archlinux.org/viewtopic.php?id=109962 HERE] and [https://bbs.archlinux.org/viewtopic.php?id=113493 HERE]. Also see the Arch bug report on this issue [https://bugs.archlinux.org/task/22071 HERE]. <br />
<br />
====First fix====<br />
Check {{Filename|mpd.conf}} for a line like {{Codeline|mpd.error}} and remove it. The mpd error file is deprecated and has been removed.<br />
<br />
====Second fix====<br />
{{Note|I'm not so sure this is a good idea. There is a warning about changing the address to bind to in the default mpd.conf. If this does not help, you might want to comment out the changes.}}<br />
If that doesn't help, add the following to {{Filename|mpd.conf}}:<br />
<pre><br />
bind_to_address "127.0.0.1"<br />
port "6600"<br />
</pre><br />
<br />
Afterwards, instruct your client to connect via 127.0.0.1. For example, add the following to the ncmpcpp config file:<br />
<pre><br />
mpd_host "127.0.0.1"<br />
mpd_port "6600"<br />
</pre><br />
<br />
<br />
===Port 6600 already in use===<br />
MPD needs to bind to port 6600 and cannot start if it's already in use. The most common reason for this is that the user has started MPD once and then subsequently tried to start mpd again. In general, nothing should be done here.<br />
<br />
If port 6600 is tied up for some other reason, one can use the following command to find the offending process:<br />
# netstat -tulpan | grep 6600<br />
<br />
This will list IP:Port and the process name holding the connection (root privileges are required to see all processes).<br />
<br />
If you need to restart mpd for whatever reason, use:<br />
<pre><br />
$ mpd --kill<br />
$ mpd <br />
</pre><br />
A more brute-force approach:<br />
<pre><br />
$ killall mpd<br />
$ mpd <br />
</pre><br />
{{Note| If you typically run MPD as root, you will need to run the above commands as root.}}<br />
<br />
In the latest version of MPD, --create-db is completely deprecated. The database will be created automagically on first run and can subsequently be updated via your client (i.e. mpc update). You can now use inotify support to automatically update your music database. Add the following to {{File|name=mpd.conf|content=auto_update "yes"}} to enable it.<br />
<br />
===Binding to IPV6 before IPV4===<br />
If on startup, you see this message:<br />
listen: bind to '0.0.0.0:6600' failed: Address already in use (continuing anyway, because binding to '[::]:6600' succeeded)<br />
MPD is attempting to bind to the ipv6 interface before binding to ipv4. If you want to use your ipv4 interface, hardcode it in mpd.conf, like so:<br />
bind_to_address "127.0.0.1"<br />
Or, you could specify several binds, for example, to have MPD listen on localhost and the external IP of your network card:<br />
bind_to_address "127.0.0.1"<br />
bind_to_address "192.168.1.13"<br />
<br />
===Crackling sound with some audio files===<br />
This is usually a playback speed problem and can be fixed by uncommenting the audio_output_format line in:<br />
<br />
{{File|name=/etc/mpd.conf|content=<br />
audio_output_format "44100:16:2"}}<br />
<br />
This is usually a sane value for most mp3 files.<br />
<br />
===daemon: cannot setgid for user "mpd": Operation not permitted ===<br />
<br />
The error is stating that the user starting the process (you) does not have permissions to become another user (mpd) which the configuration has told that process to run as.<br />
<br />
To solve the issue, simply start mpd as root.<br />
su -c "/etc/rc.d/mpd start"<br />
or<br />
sudo /etc/rc.d/mpd start<br />
<br />
==External links==<br />
* [http://www.musicpd.org/ Official Web Site]<br />
* [http://mpd.wikia.com/wiki/Main_Page Official Wiki]<br />
* [http://mpd.wikia.com/wiki/Clients Sorted List of MPD Clients]<br />
* [http://www.musicpd.org/forum/ MPD forum]</div>Rasihttps://wiki.archlinux.org/index.php?title=Music_Player_Daemon&diff=150557Music Player Daemon2011-08-03T13:15:07Z<p>Rasi: /* Even quicker setup */</p>
<hr />
<div>[[fr:MPD]]<br />
[[Category:Audio/Video (English)]]<br />
[[Category:Daemons and system services (English)]]<br />
{{i18n|Music Player Daemon}}<br />
[[pl:Music Player Daemon]]<br />
<br />
'''MPD''' (music player daemon) is an audio player that has a server-client architecture. MPD runs in the background as a daemon, manages playlists and a music database, and uses very few resources. In order to interface with it, you need a separate client. More information can be found on their [http://www.musicpd.org/ website].<br />
<br />
''Please'' have a look at the official page for setup and troubleshooting instructions, the main developer called our wiki page in its current state ''"full of symptom killers"'', hence the official pages should contain better instructions.<br />
<br />
==Installing mpd==<br />
Install with [[pacman]]:<br />
# pacman -S mpd<br />
<br />
==Daemon Setup: Starting at Boot==<br />
General information about MPD configuration may be found at http://mpd.wikia.com/wiki/Configuration.<br />
<br />
===Sound setup===<br />
To make audio output actually work ensure that you have setup audio card and mixer correctly. See [[ALSA]], and [[PulseAudio]] if you are using Gnome 3. Do not forget to unmute the required channels in alsamixer, raise the volume and save changes with alsactl store. Run mpd with {{Filename|/usr/bin/mpd --stdout --no-daemon --verbose}} if that still doesn't work.<br />
<br />
Make sure your card can do hardware mixing (most of them can, including onboard audio). Or else this could cause problems with multiple sound playback. For example, this can prevent Mplayer from playing back sound while the mpd daemon is running, returning an audio error message stating the device is busy.<br />
<br />
===Timeline of MPD's behavior on a typical working setup when started as a daemon===<br />
# MPD is started on boot by {{Filename|/etc/rc.conf}}, by including it in the {{Codeline|DAEMONS}} array. (Or, this can be done manually each session by running {{Codeline|/etc/rc.d/mpd start}} with root privileges).<br />
# Since MPD is now started as root, it first reads the {{Filename|/etc/mpd.conf}} file.<br />
# MPD reads the user variable in the {{Filename|/etc/mpd.conf}} file, and changes from root to this user.<br />
# MPD then reads the contents of the {{Filename|/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 {{Filename|/etc/mpd.conf}} file. This way, uses of {{Codeline|~}} in the configuration file point correctly to the home user's directory, and not root's directory. It may be worthwhile to change all uses of {{Codeline|~}} to {{Codeline|/home/username}} to avoid any confusion over this aspect of MPD's behavior.<br />
<br />
===A clean configuration file===<br />
* As root, check if {{Filename|/etc/mpd.conf}} exists and delete the file if it does. This is safe.<br />
<br />
MPD comes with an example configuration file, available at {{Filename|/usr/share/mpd/mpd.conf.example}}. This file holds an abundance of information on MPD configuration, and holds default mixer values you can simply uncomment.<br />
<br />
* As root, copy this example file to {{Filename|/etc/mpd.conf}}.<br />
# cp /usr/share/mpd/mpd.conf.example /etc/mpd.conf<br />
({{Filename|/usr/share/mpd/mpd.conf.example}} is good for userspace setup)<br />
<br />
Since MPD is being set up to run as a daemon at boot, never put this file in the user's directory like some tutorials suggest, since it will not be read. Moreover, if you previously created a {{Filename|.mpdconf}} file in your home, remove it now (to set up MPD to run with user privileges alone, pleaser refer to the section [[Music_Player_Daemon#Alternative_Setup:_Starting_as_a_User | Alternative_Setup:_Starting_as_a_User]]). This is important to prevent conflicts. The presence of the configuration file in {{Filename|/etc}}, like is the case here, is what will enable MPD to run as a daemon at boot. Otherwise, a script would be needed to run MPD ''after'' the user has logged (like kdm or {{Filename|~/.fluxbox/startup}}) or it would require a manual move each time. For a single music collection, the method used here is simply better, even while the collection is shared to multiple users. Also, don't be afraid about root privileges: even while MPD runs as a daemon, it never completely runs as root since it automatically drops its root privileges after execution.<br />
<br />
===Edit {{Filename|mpd.conf}}===<br />
<br />
The default arch install keeps the setup in /var and uses "mpd" as default user, instead of cluttering up ~/.<br />
Edit {{Filename|/etc/mpd.conf}} to reflect as such.<br />
<br />
{{File|name=/etc/mpd.conf|content=<br />
music_directory "/home/user/music" # Your music dir.<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 "/var/run/mpd/mpd.pid" # Omit this line for systemd<br />
state_file "/var/lib/mpd/mpdstate"<br />
user "mpd"<br />
# Binding to address and port causing problems in mpd-0.14.2 best to leave<br />
# commented.<br />
# bind_to_address "127.0.0.1"<br />
# port "6600"<br />
}}<br />
<br />
* If your music collection is contained under multiple directories, you can make symbolic links under /var/lib/mpd then set 'music_directory' to the directory holding the symbolic links. Remember to set permissions accordingly on the directories being linked.<br />
<br />
* To change the volume of audio from mpd independent of other programs, uncomment or add the switch in mpd.conf:<br />
<br />
{{File|name=/etc/mpd.conf|content=<br />
mixer_type "software"<br />
}}<br />
<br />
* Lastly, if you are running pulseaudio under Gnome 3, the default setting of "alsa" for the audio output will not work. Make the modification from:<br />
{{File|name=/etc/mpd.conf|content=<br />
audio_output {<br />
type "alsa"<br />
name "Sound Card"<br />
}<br />
}}<br />
<br />
to<br />
<br />
{{File|name=/etc/mpd.conf|content=<br />
audio_output {<br />
type "pulse"<br />
name "Sound Card"<br />
}<br />
}}<br />
<br />
===Create files===<br />
<br />
* As root, create the directories and files you specified in {{Filename|/etc/mpd.conf}}.<br />
# mkdir -p /var/lib/mpd/playlists /var/run/mpd<br />
# touch /var/lib/mpd/{mpd.db,mpdstate} && touch /var/run/mpd/mpd.pid<br />
<br />
* You then need to change the file's permissions so that the daemon can modify them.<br />
# chown -R mpd /var/lib/mpd /var/run/mpd<br />
<br />
===Create database===<br />
<br />
Creating the database is now accomplished via the update feature of the client, for example 'mpc update'. The previous method, creating the MPD database as root (# mpd --create-db), is deprecated.<br />
<br />
==Alternative Setup: Starting as a User==<br />
MPD need not be started with root permissions. The only reason why MPD needs to be started as root (by being called from {{Filename|/etc/rc.conf}}) is because the default files and folders in the default configuration file points to directories owned by root (the /var directory). A less common, but perhaps more sensible, approach is to make MPD work with files and directories owned by a normal user. Running MPD as a normal user has several advantages: <br />
# You can easily have a single directory ~/.mpd (or any other directory under /home/username) for all MPD configuration files<br />
# No read/write permission errors<br />
# More flexible calls to MPD by using {{Filename|~/.xinitrc}} instead of including 'mpd' in the {{Filename|/etc/rc.conf}} DAEMONS array.<br />
<br />
The following steps shows how to run MPD as a normal user. '''Note''': this approach will not work if you want multiple users to have access to MPD.<br />
<br />
* Copy the contents of the default MPD configuration file in {{Filename|/usr/share/mpd/mpd.conf.example}} to your home directory. A good place would be {{Filename|"/home/user/.mpd/mpd.conf"}}.<br />
* Follow the 'old setup instructions' from above, ignoring the first part about copying the config to {{Filename|/etc/mpd.conf}} and do not set a user variable. <br />
* Create all of the requisite files in {{filename|"/home/user/.mpd/"}}:<br />
"~/.mpd/playlists/"<br />
"~/.mpd/db"<br />
"~/.mpd/mpd.db"<br />
"~/.mpd/mpd.log"<br />
"~/.mpd/mpd.error"<br />
"~/.mpd/mpd.pid"<br />
"~/.mpd/mpdstate"<br />
<br />
* Let MPD start on bootup by calling it from your {{Filename|~/.xinitrc}} as follows:<br />
# this starts mpd as normal user<br />
mpd ~/.mpd/mpd.conf<br />
{{Note| that you don't have to put a "&" at the end of the line here, since MPD will automatically daemonize itself.}}<br />
<br />
Lastly, delete the entry 'mpd' from your DAEMONS array in {{Filename|/etc/rc.conf}}, as you are not running it as root anymore.<br />
<br />
===Quick setup===<br />
<br />
The fastest way to do set up the structure is to do this:<br />
<br />
$ mkdir -p ~/.mpd/playlists && touch ~/.mpd/database && cp /usr/share/doc/mpd/mpdconf.example ~/.mpd/mpd.conf<br />
<br />
Then edit mpd.conf to your liking, in a manner similar to [[Music_Player_Daemon#Edit_mpd.conf]]. Beware that you must uncomment the db_file entry if you do edit mpd.conf.<br />
<br />
Then, to run it:<br />
<br />
$ mpd ~/.mpd/mpd.conf<br />
<br />
<br />
===Even quicker setup===<br />
I created a little script that will only ask for the location of your music and then creates the needed files and folders for you.<br />
You can find the script here:<br />
[http://karif.server-speed.net/~carnager/mpdsetup.tar]<br />
extract it<br />
$ tar xf mpdsetup.tar<br />
and run it<br />
$ ./mpdsetup.sh<br />
<br />
If you want to use this config in daemon mode, open it (~/.mpdconf) in an editor and find the "user" line. remove the comment (#) and fill in your own user name. Then copy the file to /etc/mpd.conf. If running mpd as user is fine for you, make sure to remove "mpd" from the daemons list in /etc/rc.conf<br />
<br />
===Multi-mpd setup===<br />
'''Useful if you want to run for example an icecast server.'''<br />
If you want a second MPD daemon (e.g., with icecast output to share music over the network) to use the same music and playlist as the one above, simply copy the above configuration file and make a new file (e.g., {{Filename|/home/username/.mpd/config-icecast}}), and only change the log_file, error_file, pid_file, and state_file parameters (e.g., {{Filename|mpd-icecast.log}}, {{Filename|mpd-icecast.error}}, and so on); using the same directory paths for the music and playlist directories would ensure that this second mpd daemon would use the same music collection as your first one (e.g., creating and editing a playlist under the first daemon would affect the second daemon as well, so that you don't have to create the same playlists all over again for the second daemon). Then, call this second daemon the same way from your {{Filename|~/.xinitrc}} above. (Just be sure to have a different port number, so as to not conflict with your first mpd daemon).<br />
<br />
==Clients==<br />
Install a client program for MPD. Popular options are:<br />
<br />
===Console===<br />
* '''mpc''' &ndash; Command Line Client (you'll probably want this one no matter what)<br />
# pacman -S mpc<br />
* [http://mpd.wikia.com/wiki/Client:Ncmpc/ ncmpc] &ndash; NCurses Client (this one is very handy for running in a console)<br />
# pacman -S ncmpc<br />
* [http://unkart.ovh.org/ncmpcpp/ ncmpcpp] &ndash; Clone of ncmpc with some new features written in C++<br />
# pacman -S ncmpcpp<br />
* [http://pms.sourceforge.net/ pms] &ndash; NCurses Client (highly configurable and accessible)<br />
Install [http://aur.archlinux.org/packages.php?ID=24378 pmus] from the [[AUR]].<br />
<br />
===Graphical===<br />
* [http://ario-player.sourceforge.net ario] &ndash; GTK+ Client with a Rhythmbox like library browser<br />
# pacman -S ario<br />
* [http://gmpcwiki.sarine.nl/index.php?title=GMPC gmpc] &ndash; GNOME Client<br />
# pacman -S gmpc<br />
* [http://bitcheese.net/wiki/QMPDClient QMPDClient] &ndash; Client written with Qt 4.x.<br />
# pacman -S qmpdclient<br />
* [http://sonata.berlios.de/ sonata] &ndash; Python GTK+ Client<br />
# pacman -S sonata<br />
* [http://aur.archlinux.org/packages.php?ID=33380 dmpc] &ndash; Dmenu-based MPC client with a playlist manager and state-saving on playlist changes<br />
Install [http://aur.archlinux.org/packages.php?ID=33380 dmpc] from the [[AUR]].<br />
<br />
See a long list of clients at the [http://mpd.wikia.com/wiki/Clients mpd wiki].<br />
<br />
==Extra stuff==<br />
===Last.fm scrobbling===<br />
To scrobble your songs to [http://www.last.fm Last.fm] using MPD there are several alternatives.<br />
<br />
====mpdscribble====<br />
mpdscribble is another daemon, available in the "community" repository (if you prefer, the "git" version is available in the [http://aur.archlinux.org/packages.php?ID=22274 AUR]). This is arguably the best alternative, because it's the semi-official MPD scrobbler and uses the new "idle" feature in MPD for more accurate scrobbling. Also, you don't need root access to configure it, because it doesn't need any changes to <tt>/etc</tt> at all. Visit [http://mpd.wikia.com/wiki/Client:Mpdscribble the official website] for more information.<br />
<br />
After you have installed mpdscribble, do the following (not as root):<br />
<br />
* {{Codeline|$ mkdir ~/.mpdscribble}}<br />
* Create the file {{Filename|~/.mpdscribble/mpdscribble.conf}} and add the following:<br />
<pre><br />
[mpdscribble] <br />
host = <your mpd host> # optional, defaults to $MPD_HOST or localhost<br />
port = <your mpd port> # optional, defaults to $MPD_PORT or 6600<br />
log = /home/<YOUR_USERNAME>/.mpdscribble/mpdscribble.log<br />
verbose = 2<br />
sleep = 1<br />
musicdir = <your music directory><br />
proxy = <your proxy> # optional, e. g. http://your.proxy:8080, defaults to none<br />
<br />
[last.fm]<br />
# last.fm section, comment if you don't use last.fm<br />
url = http://post.audioscrobbler.com/<br />
username = <your last.fm username><br />
password = <your last.fm password> # md5sum also possible: echo -n 'PASSWORD' | md5sum | cut -f 1 -d " "<br />
journal = /home/<YOUR_USERNAME>/.mpdscribble/lastfm.journal<br />
<br />
[libre.fm]<br />
# libre.fm section, comment if you don't use libre.fm<br />
url = http://turtle.libre.fm/<br />
username = <your libre.fm username><br />
password = <your libre.fm password> # md5sum also possible: echo -n 'PASSWORD' | md5sum | cut -f 1 -d " "<br />
journal = /home/<YOUR_USERNAME>/.mpdscribble/librefm.journal<br />
</pre><br />
* Add {{Codeline|mpdscribble}} to your {{Filename|~/.xinitrc}}:<br />
pidof mpdscribble >& /dev/null<br />
if [ $? -ne 0 ]; then<br />
mpdscribble &<br />
fi<br />
<br />
====Sonata & Ario====<br />
The easiest way, if you don't care about having to have a program window open all the time, is using Sonata or Ario which are graphical frontends to MPD. They have built-in support for Last.fm scrobbling in their preferences. A downside of this is that Sonata doesn't cache your songs if for some reason you don't happen to have an Internet connection at the time of playing.<br />
<br />
====lastfmsubmitd====<br />
lastfmsubmitd is a daemon which is available in the "community" repository. To install it, first edit {{Filename|/etc/lastfmsubmitd.conf}} and add both {{Codeline|lastfmsubmitd}} and {{Codeline|lastmp}} to the {{Codeline|DAEMONS}} array in {{Filename|/etc/rc.conf}}.<br />
<br />
===Last.fm playback with lastfmproxy===<br />
lastfmproxy is a python script that streams a last.fm music stream to another media player. To setup, install [http://aur.archlinux.org/packages.php?ID=14214 lastfmproxy] from the [[AUR]] and then edit {{Filename|/usr/share/lastfmproxy/config.py}}. If you plan to only stream to MPD on the same host, just edit the login info.<br />
<br />
{{Note | Since it installs to a read only directory but it requires read/write access for features like saving previously listened to stations, it would be wise to copy {{Filename|/usr/share/lastfmproxy}} to your home directory.}}<br />
<br />
Start lastfmproxy with {{Codeline|lastfmproxy}} and visit http://localhost:1881/ in your web browser. To add a last.fm station navigate to http://localhost:1881/ followed by the lastfm:// url. Example: http://localhost:1881/lastfm://globaltags/punk . Navigate back to http://localhost:1881/ and download the m3u file by selecting the ''Start Listening'' link. Simply add it to your music library path.<br />
<br />
===Never play on start===<br />
<br />
This feature has recently been added to mpd git by Martin Kellerman, see commits b57330cf75bcb339e3f268f1019c63e40d305145 and 2fb40fe728ac07574808c40034fc0f3d2254d49d.<br />
<br />
====[https://aur.archlinux.org/packages.php?ID=19676 mpd-git] Method====<br />
This is the best method currently available, but is only currently (April 2011) enabled in the git version. Install [https://aur.archlinux.org/packages.php?ID=19676 mpd-git] from the [[AUR]], then add {{Codeline|restore_paused "yes"}} to your {{Filename|mpd.conf}} file.<br />
<br />
If you have issues with connecting your client to [https://aur.archlinux.org/packages.php?ID=19676 mpd-git], see [[Music Player Daemon#Other issues when attempting to connect to mpd with a client]].<br />
<br />
====Method 1====<br />
If you don't want MPD to always play on your system start, but yet you want to preserve the other state information, add the following lines to your {{Filename|/etc/rc.d/mpd}} file:<br />
'' ...''<br />
'' stat_busy "Starting Music Player Daemon"''<br />
<br />
# always start in paused state<br />
awk '/^state_file[ \t]+"[^"]+"$/ {<br />
match($0, "\".+\"")<br />
sfile = substr($0, RSTART + 1, RLENGTH - 2)<br />
} /^user[ \t]+"[^"]+"$/ {<br />
match($0, "\".+\"")<br />
user = substr($0, RSTART + 1, RLENGTH - 2)<br />
} END {<br />
if (sfile == "")<br />
exit;<br />
if (user != "")<br />
sub(/^~/, "/home/" user, sfile)<br />
system("sed -i \x27s|^\\(state:[ \\t]\\{1,\\}\\)play$|\\1pause|\x27 \x27" sfile "\x27")<br />
}' /etc/mpd.conf<br />
<br />
'' /usr/bin/mpd /etc/mpd.conf &> /dev/null''<br />
'' ...''<br />
<br />
This will change the player status to "paused", if it was stopped while playing. Next, you want this file to be preserved, so MPD updates won't erase this edit. Add (or edit) this line to your {{Filename|/etc/pacman.conf}}:<br />
NoUpgrade = etc/rc.d/mpd<br />
<br />
====Method 2====<br />
<br />
Another simpler method, would be to add mpd to your {{Filename|[[rc.conf]]}} deamons array and add {{Codeline|mpc stop}} or {{Codeline|mpc pause}} to {{Filename|/etc/rc.local.shutdown}} and to {{Filename|/etc/rc.local}}. (Remember you must have mpc installed to use this method).<br />
<br />
Adding only the order in {{Filename|/etc/rc.local}} cannot assure that mpd will play absolutely nothing, since there may be a delay before the stop command is executed. <br />
On the other hand, if you only add the order to {{Filename|/etc/rc.local.shutdown}}, that will assure that mpd won't play at all, as long as you properly shutdown your system.<br />
Even though they are redundant, adding it to {{Filename|/etc/rc.local}} would serve as a safety for those, presumably, rare occasions when you do not shutdown the system properly.<br />
<br />
====Method 3====<br />
<br />
The general idea between this method is to ask mdp to pause music when user logs out so that during next restart, mdp will stick to that "pause" state. Sending such command can be achieve using [http://www.archlinux.org/packages/extra/x86_64/mpc/ mpc], the command line interface to MPD:<br />
pacman -S mpc<br />
<br />
GDM users can then add the next line to /etc/gdm/PostSession/Default (be sure to add it before "exit 0"):<br />
/usr/bin/mpc pause<br />
<br />
Non-GDM users can use their own login manager's method to launch the line at logout.<br />
<br />
===MPD & ALSA===<br />
Sometimes, when you use other audio output, e.g: some web pages containing Flash applets, MPD cannot reproduce anything anymore (until you restart). The error looks something like: (if you search the file {{Filename|/var/log/mpd/mpd.error}})<br />
<br />
Error opening alsa device "hw:0,0": Device or resource busy<br />
<br />
And here is the solution (dmix saving our life again). Apply these lines in your {{Filename|/etc/mpd.conf}}:<br />
<br />
<pre><br />
audio_output {<br />
type "alsa"<br />
name "Sound Card"<br />
options "dev=dmixer"<br />
device "plug:dmix"<br />
}<br />
</pre><br />
<br />
And then restart with {{Codeline|/etc/rc.d/mpd restart}}.<br />
<br />
Searching on Internet I found the reason for why that happens in Gentoo's wiki:<br />
* The sound card does not support hardware mixing (uses '''dmix''' plugin)<br />
* An application does not work with ALSA with it's default settings<br />
<br />
For a detailed description, it is recommended to take a look at [http://mpd.wikia.com/wiki/Alsa this] link. There you can find an example asound.conf which worked for me right out of the box.<br />
<br />
====High CPU usage with ALSA====<br />
When using MPD with ALSA, users may experience MPD taking up lots of CPU (around 20-30%). This is caused by most sound cards supporting 48kHz and most music being 44kHz, thus forcing MPD to resample it. This operation takes lots of CPU cycles and results into high usage.<br />
<br />
For most users the problem should be solved by telling MPD not to use resampling by adding {{Codeline|auto_resample "no"}} into audio_output-part of {{Filename|/etc/mpd.conf}}. This will degrade quality slightly, however.<br />
<br />
Example from {{Filename|mpd.conf}}:<br />
<br />
audio_output {<br />
type "alsa"<br />
name "My ALSA Device"<br />
auto_resample "no"<br />
}<br />
<br />
Although it may not give as drastic a speedup, enabling mmap may speed things up:<br />
<br />
audio_output {<br />
type "alsa"<br />
name "My ALSA Device"<br />
use_mmap "yes"<br />
}<br />
<br />
Some users might also want to tell dmix to use 44kHz as well. More info about tuning performance of your MPD can be found from: [http://mpd.wikia.com/wiki/Tuning MPD wiki]<br />
<br />
====Example configuration: Output with 44.1 KHz at e. g. 16 bit depth, multiple programs at once====<br />
<br />
''Why these formats?'' Because they are standard CDA, because ALSA on its own allows more than one program "to sound" only with dmix — whose resampling algorithm is inferior — and because dmix by default resamples anything lower to 48 KHz (or whatever higher format is playing at the time). Also, some get clicking sounds if at least {{Filename|mpd.conf}} is not changed this way.<br />
<br />
''What's the downside?'' These settings cause ''everything'' (if necessary) to be resampled to this format, such as material from DVD or TV which usually is at 48 KHz. But there is no known way to have ALSA dynamically change the format, and particularly if you listen to far more CDs than anything else the occasional 48 → 44.1 isn't too great a loss.<br />
<br />
The following assumes that there are not already other settings which conflict resp. overwrite it. This applies especially to the current user's potential {{Filename|~/.asoundrc}} — which MPD as its own user ignores, therefore the following should go to {{Filename|/etc/asound.conf}}:<br />
<br />
{{File|name=/etc/asound.conf|content=<br />
defaults.pcm.dmix.rate 44100 # Force 44.1 KHz<br />
defaults.pcm.dmix.format S16_LE # Force 16 bits<br />
}}<br />
<br />
{{File|name=/etc/mpd.conf|content=<br />
audio_output {<br />
type "alsa" # Use the ALSA output plugin.<br />
name "HDA Intel" # Can be called anything or nothing tmk, but must be present.<br />
options "dev=dmixer"<br />
device "plug:dmix" # Both lines cause MPD to output to dmix.<br />
format "44100:16:2" # the actual format<br />
auto_resample "no" # This bypasses ALSA's own algorithms, which generally are inferior. See below how to choose a different one.<br />
use_mmap "yes" # Minor speed improvement, should work with all modern cards.<br />
}<br />
<br />
samplerate_converter "0" # MPD's best, most CPU intensive algorithm. See 'man mpd.conf' for others — for anything other than the poorest "internal", libsamplerate must be installed.<br />
}}<br />
<br />
{{Note|MPD gives the mp3 format a special treatment at decoding: It's always outputted as 24 bit. (The conversion as forced by the ''format'' line only comes after that.)}}<br />
<br />
If one wants to leave the bit depth decision to ALSA resp. MPD, comment out resp. omit the ''dmix.format'' line and change the one for mpd with ''format'' to "44100:*:2".<br />
<br />
{{Note|''Crossfading'' between files decoded at two different bit depths (say, one mp3 and one 16 bit flac) does not work unless conversion is active.}}<br />
<br />
===Control MPD with lirc===<br />
There are already some clients designed for communications between lircd and MPD, however, as far as the practical use, they aren't very useful since their functions are limited.<br />
<br />
It's recommended to use mpc with irexec. mpc is a command line player which only sends the command to MPD and exits immediately, which is perfect for irexec, the command runner included in lirc. What irexec does is that it runs a specified command once received a remote control button.<br />
<br />
First of all, please setup your remotes as referred to the '''[[Lirc]]''' article.<br />
<br />
Edit your favored lirc startup configuration file, default location is {{Filename|~/.lircrc}}.<br />
<br />
Fill the file with the following pattern:<br />
begin<br />
prog = irexec<br />
button = <button_name><br />
config = <command_to_run><br />
repeat = <0 or 1><br />
end<br />
<br />
An useful example:<br />
## irexec<br />
begin<br />
prog = irexec<br />
button = play_pause<br />
config = mpc toggle<br />
repeat = 0<br />
end<br />
<br />
begin<br />
prog = irexec<br />
button = stop<br />
config = mpc stop<br />
repeat = 0<br />
end<br />
begin<br />
prog = irexec<br />
button = previous<br />
config = mpc prev<br />
repeat = 0<br />
end<br />
begin<br />
prog = irexec<br />
button = next<br />
config = mpc next<br />
repeat = 0<br />
end<br />
begin<br />
prog = irexec<br />
button = volup<br />
config = mpc volume +2<br />
repeat = 1<br />
end<br />
begin<br />
prog = irexec<br />
button = voldown<br />
config = mpc volume -2<br />
repeat = 1<br />
end<br />
begin<br />
prog = irexec<br />
button = pbc<br />
config = mpc random<br />
repeat = 0<br />
end<br />
begin<br />
prog = irexec<br />
button = pdvd<br />
config = mpc update<br />
repeat = 0<br />
end<br />
begin<br />
prog = irexec<br />
button = right<br />
config = mpc seek +00:00:05<br />
repeat = 0<br />
end<br />
begin<br />
prog = irexec<br />
button = left<br />
config = mpc seek -00:00:05<br />
repeat = 0<br />
end<br />
begin<br />
prog = irexec<br />
button = up<br />
config = mpc seek +1%<br />
repeat = 0<br />
end<br />
begin<br />
prog = irexec<br />
button = down<br />
config = mpc seek -1%<br />
repeat = 0<br />
end<br />
<br />
There are more functions for mpc, run {{Codeline|man mpc}} for more info.<br />
<br />
===Control MPD with bluetooth phone===<br />
You can also control MPD (to a certain extent) using a bluetooth enabled phone. You need to do the following:<br />
<br />
* install [http://remuco.sourceforge.net/index.php/Remuco remuco] -- a wireless remote control for several Linux media players ([http://aur.archlinux.org/packages.php?ID=25072 aur])<br />
* transfer remuco client -- jar/jad files from {{Filename|/usr/share/remuco/client/}} to your phone and install it<br />
* run {{Codeline|remuco-mpd}} (as current user)<br />
* run remuco on your phone, define a new bluetooth remuco connection (pair first if you haven't done this previously) and explore its capabilities<br />
<br />
More information about remuco including troubleshooting to be found at its [http://remuco.sourceforge.net/index.php/Remuco homepage]<br />
<br />
===MPD & PulseAudio===<br />
<br />
Edit {{Filename|/etc/mpd.conf}}, and uncomment the audio_output section for the type "pulse". The server and sink lines of it should be commented unless you know what you're doing.<br />
<br />
Then, add the mpd user (and yours if you haven't done so already) to the necessary pulse groups. The pulse-access group should be sufficient but you may want to add pulse-rt as well. The group "pulse" doesn't appear to be necessary.<br />
# gpasswd -a mpd pulse-access<br />
# gpasswd -a mpd pulse-rt<br />
<br />
Lastly, you may or may not need to copy {{Filename|~/.pulse-cookie}} from your current (pulse working) user's dir to your mpd user's home directory. It is likely to be {{Filename|/var/lib/mpd}} if you followed the first part of this wiki. This would probably only allow your current user to listen in on MPD's pulse. You may consider running pulse system-wide if that's insufficient.<br />
<br />
===Cue Files===<br />
<br />
To make cue file support actually work, you have to work around a nasty libcue bug. Libcue copied some files directly from libcdio, making it conflict with it. Steps to do to get proper cue support:<br />
<br />
* remove libcdio temporary (pacman -Rdd libcdio)<br />
* install libcue (pacman -S libcue)<br />
* install mpd with abs or from aur.<br />
* reinstall libcdio (pacman -S libcdio)<br />
<br />
At the point of writing mpd does not parse tracknumbers from cue sheets. There is a patch available (http://musicpd.org/mantis/view.php?id=3230)<br />
Once this patch is merged into mpd, i will remove this line :)<br />
<br />
==Troubleshooting==<br />
===Autodetection failed===<br />
During the start of MPD, it tries to autodetect your set-up and configure output and volume control accordingly. Though this mostly goes well, it will fail for some systems. It may help to tell MPD specifically what to use as output and mixer control. If you copied {{Filename|/etc/mpd.conf}} over from {{Filename|/etc/mpd.conf.example}} as mentioned above, you can simply uncomment:<br />
<br />
Example for alsa output type and alsa mixer:<br />
audio_output {<br />
type "alsa"<br />
name "My ALSA Device"<br />
device "hw:0,0" # optional<br />
format "44100:16:2" # optional<br />
mixer_type "hardware"<br />
mixer_device "default"<br />
mixer_control "PCM"<br />
}<br />
<br />
'''Note:''' in case of permission problems when using ESD with MPD run this as root:<br />
# chsh -s /bin/true mpd<br />
<br />
===Executable permissions===<br />
{{Warning|This is not good security practice and may be unnecessary.}}<br />
<br />
MPD needs to have +x permissions on '''ALL''' parent directories to your music collection (ie. if it's located outside of "mpd" home directory /var/lib/mpd). By default useradd sets permissions on home dir to 1700 drwx------. So if you're like me you will need to change permissions of /home/user. Example... my music collection is located /home/user/music. <br />
# chmod a+x /home/$USER<br />
# chmod -R a+X /home/$USER/music<br />
<br />
====Alternative solution====<br />
An alternative solution would be to use your group to share a selection of files, among them your music library. First remove all permissions for the group then add group permissions to read and execute home and music.<br />
# chmod -R g-rwx /home/$USER<br />
# chmod g+rx /home/$USER<br />
# chmod -R g+rX /home/$USER/music<br />
<br />
====Another alternative solution====<br />
Another alternative is to remount the music directory under a directory that mpd has access to. This does not entail the same security risks as modifying the permissions on one's home directory.<br />
# mkdir /var/lib/mpd/music<br />
# echo "/home/$USER/music /var/lib/mpd/music none bind" >> /etc/fstab<br />
# mount -a<br />
# /etc/rc.d/mpd restart<br />
And that should fix the problem. See also [https://bbs.archlinux.org/viewtopic.php?id=86449 the forum thread.]<br />
<br />
===Avoiding timeouts===<br />
To get rid of timeouts (i.e. when you paused music for long time) in gpmc and other clients uncomment and increase {{Codeline|connection_timeout}} option in {{Filename|mpd.conf}}.<br />
<br />
If files and/or titles are shown in wrong encoding, uncomment and change {{Codeline|filesystem_charset}} and {{Codeline|id3v1_encoding}} options.<br />
Note that you cannot set encoding for ID3 v2 tags. To workaround this you may use [http://mpd.wikia.com/wiki/GenericDecoder#Generic_Tagreader external tag readers].<br />
<br />
If you want to use another computer to control MPD over a network, the {{Codeline|bind_to_address}} option in {{Filename|mpd.conf}} will need to be set to either your IP address, or {{Codeline|any}} if your IP address changes frequently. <br />
<br />
'''Streaming'''<br><br />
With the latest version of MPD (0.15), built-in httpd streaming is now available.<br />
<br />
To activate this feature, you'll just need to add a new output of type httpd in {{Filename|mpd.conf}}:<br />
audio_output {<br />
type "httpd"<br />
name "What you want"<br />
encoder "lame" # vorbis or lame supported<br />
port "8000"<br />
bitrate "128"<br />
format "44100:16:2" # change 2 to 1 for mono<br />
}<br />
<br />
Restart the mpd deamon and, from another computer, simply load the stream as any other url. <br />
$ mplayer http://<server's IP>:8000<br />
<br />
{{Note | You must open the port on your router / firewall for the stream to be connectible to from another computer.}}<br />
<br />
Most players (i.e. vlc or xmms2) should also be able to load the stream via their "add url..." menu option.<br />
<br />
This is a nice clean way to replace your current icecast setup with something natively supported within MPD.<br />
<br />
===mpd hangs on first startup===<br />
This is a common error that's caused by corrupt mp3 tags.<br />
Here is an experimental way to solve this issue.<br />
Requirements:<br />
* kid3<br />
* easytag<br />
<br />
This method is very tedious, especially with a huge database. Just as a baseline it took 2.5h to fix a 16Gb DB.<br />
<br />
====Easy Tag====<br />
The purpose of easytag here is that easytag detects the error in the tags, but like MPD it hangs and dies. The trick here is that easy tags actually tells you what file is causing the problem on the status bar.<br />
Before starting easytag make sure to have a terminal close to be ready to kill easy tag to avoid a hang. Once you are ready, on the tree view select the directory where all your music is located. By default easytag starts to search all subdirectories for mp3 files. Once you notice that easytag stopped scanning for songs, make note of the culprit and kill easytag.<br />
<br />
====KID3====<br />
Here's where kid3 comes in handy. With kid3 go to the offending song and rewrite one of the tags. then save the file. This should force kid3 to rewrite the whole tag again fixing the problem with MPD and easy tag hanging.<br />
<br />
Repeat this procedure until your music library is done.<br />
<br />
===Cannot connect to mpd: host "localhost" not found: Temporary failure in name resolution===<br />
Cannot connect to MPD (with ncmpcpp), if you are disconnected from network. Solution is [[IPv6 - Disabling the Module|disable IPv6]] or add line to /etc/hosts<br />
::1 localhost.localdomain localhost<br />
<br />
===Other issues when attempting to connect to mpd with a client===<br />
Some have reported being unable to access mpd with various clients, for example seeing errors like these:<br />
$ ncmpcpp<br />
Cannot connect to mpd: Connection closed by the server<br />
$ sonata<br />
2011-02-13 18:33:05 Connection lost while reading MPD hello<br />
2011-02-13 18:33:05 Not connected<br />
2011-02-13 18:33:05 Not connected<br />
<br />
Please see posts on ncmpcpp on the Arch Forums [https://bbs.archlinux.org/viewtopic.php?id=109962 HERE] and [https://bbs.archlinux.org/viewtopic.php?id=113493 HERE]. Also see the Arch bug report on this issue [https://bugs.archlinux.org/task/22071 HERE]. <br />
<br />
====First fix====<br />
Check {{Filename|mpd.conf}} for a line like {{Codeline|mpd.error}} and remove it. The mpd error file is deprecated and has been removed.<br />
<br />
====Second fix====<br />
{{Note|I'm not so sure this is a good idea. There is a warning about changing the address to bind to in the default mpd.conf. If this does not help, you might want to comment out the changes.}}<br />
If that doesn't help, add the following to {{Filename|mpd.conf}}:<br />
<pre><br />
bind_to_address "127.0.0.1"<br />
port "6600"<br />
</pre><br />
<br />
Afterwards, instruct your client to connect via 127.0.0.1. For example, add the following to the ncmpcpp config file:<br />
<pre><br />
mpd_host "127.0.0.1"<br />
mpd_port "6600"<br />
</pre><br />
<br />
<br />
===Port 6600 already in use===<br />
MPD needs to bind to port 6600 and cannot start if it's already in use. The most common reason for this is that the user has started MPD once and then subsequently tried to start mpd again. In general, nothing should be done here.<br />
<br />
If port 6600 is tied up for some other reason, one can use the following command to find the offending process:<br />
# netstat -tulpan | grep 6600<br />
<br />
This will list IP:Port and the process name holding the connection (root privileges are required to see all processes).<br />
<br />
If you need to restart mpd for whatever reason, use:<br />
<pre><br />
$ mpd --kill<br />
$ mpd <br />
</pre><br />
A more brute-force approach:<br />
<pre><br />
$ killall mpd<br />
$ mpd <br />
</pre><br />
{{Note| If you typically run MPD as root, you will need to run the above commands as root.}}<br />
<br />
In the latest version of MPD, --create-db is completely deprecated. The database will be created automagically on first run and can subsequently be updated via your client (i.e. mpc update). You can now use inotify support to automatically update your music database. Add the following to {{File|name=mpd.conf|content=auto_update "yes"}} to enable it.<br />
<br />
===Binding to IPV6 before IPV4===<br />
If on startup, you see this message:<br />
listen: bind to '0.0.0.0:6600' failed: Address already in use (continuing anyway, because binding to '[::]:6600' succeeded)<br />
MPD is attempting to bind to the ipv6 interface before binding to ipv4. If you want to use your ipv4 interface, hardcode it in mpd.conf, like so:<br />
bind_to_address "127.0.0.1"<br />
Or, you could specify several binds, for example, to have MPD listen on localhost and the external IP of your network card:<br />
bind_to_address "127.0.0.1"<br />
bind_to_address "192.168.1.13"<br />
<br />
===Crackling sound with some audio files===<br />
This is usually a playback speed problem and can be fixed by uncommenting the audio_output_format line in:<br />
<br />
{{File|name=/etc/mpd.conf|content=<br />
audio_output_format "44100:16:2"}}<br />
<br />
This is usually a sane value for most mp3 files.<br />
<br />
===daemon: cannot setgid for user "mpd": Operation not permitted ===<br />
<br />
The error is stating that the user starting the process (you) does not have permissions to become another user (mpd) which the configuration has told that process to run as.<br />
<br />
To solve the issue, simply start mpd as root.<br />
su -c "/etc/rc.d/mpd start"<br />
or<br />
sudo /etc/rc.d/mpd start<br />
<br />
==External links==<br />
* [http://www.musicpd.org/ Official Web Site]<br />
* [http://mpd.wikia.com/wiki/Main_Page Official Wiki]<br />
* [http://mpd.wikia.com/wiki/Clients Sorted List of MPD Clients]<br />
* [http://www.musicpd.org/forum/ MPD forum]</div>Rasihttps://wiki.archlinux.org/index.php?title=Music_Player_Daemon&diff=150556Music Player Daemon2011-08-03T13:14:46Z<p>Rasi: /* Even quicker setup */</p>
<hr />
<div>[[fr:MPD]]<br />
[[Category:Audio/Video (English)]]<br />
[[Category:Daemons and system services (English)]]<br />
{{i18n|Music Player Daemon}}<br />
[[pl:Music Player Daemon]]<br />
<br />
'''MPD''' (music player daemon) is an audio player that has a server-client architecture. MPD runs in the background as a daemon, manages playlists and a music database, and uses very few resources. In order to interface with it, you need a separate client. More information can be found on their [http://www.musicpd.org/ website].<br />
<br />
''Please'' have a look at the official page for setup and troubleshooting instructions, the main developer called our wiki page in its current state ''"full of symptom killers"'', hence the official pages should contain better instructions.<br />
<br />
==Installing mpd==<br />
Install with [[pacman]]:<br />
# pacman -S mpd<br />
<br />
==Daemon Setup: Starting at Boot==<br />
General information about MPD configuration may be found at http://mpd.wikia.com/wiki/Configuration.<br />
<br />
===Sound setup===<br />
To make audio output actually work ensure that you have setup audio card and mixer correctly. See [[ALSA]], and [[PulseAudio]] if you are using Gnome 3. Do not forget to unmute the required channels in alsamixer, raise the volume and save changes with alsactl store. Run mpd with {{Filename|/usr/bin/mpd --stdout --no-daemon --verbose}} if that still doesn't work.<br />
<br />
Make sure your card can do hardware mixing (most of them can, including onboard audio). Or else this could cause problems with multiple sound playback. For example, this can prevent Mplayer from playing back sound while the mpd daemon is running, returning an audio error message stating the device is busy.<br />
<br />
===Timeline of MPD's behavior on a typical working setup when started as a daemon===<br />
# MPD is started on boot by {{Filename|/etc/rc.conf}}, by including it in the {{Codeline|DAEMONS}} array. (Or, this can be done manually each session by running {{Codeline|/etc/rc.d/mpd start}} with root privileges).<br />
# Since MPD is now started as root, it first reads the {{Filename|/etc/mpd.conf}} file.<br />
# MPD reads the user variable in the {{Filename|/etc/mpd.conf}} file, and changes from root to this user.<br />
# MPD then reads the contents of the {{Filename|/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 {{Filename|/etc/mpd.conf}} file. This way, uses of {{Codeline|~}} in the configuration file point correctly to the home user's directory, and not root's directory. It may be worthwhile to change all uses of {{Codeline|~}} to {{Codeline|/home/username}} to avoid any confusion over this aspect of MPD's behavior.<br />
<br />
===A clean configuration file===<br />
* As root, check if {{Filename|/etc/mpd.conf}} exists and delete the file if it does. This is safe.<br />
<br />
MPD comes with an example configuration file, available at {{Filename|/usr/share/mpd/mpd.conf.example}}. This file holds an abundance of information on MPD configuration, and holds default mixer values you can simply uncomment.<br />
<br />
* As root, copy this example file to {{Filename|/etc/mpd.conf}}.<br />
# cp /usr/share/mpd/mpd.conf.example /etc/mpd.conf<br />
({{Filename|/usr/share/mpd/mpd.conf.example}} is good for userspace setup)<br />
<br />
Since MPD is being set up to run as a daemon at boot, never put this file in the user's directory like some tutorials suggest, since it will not be read. Moreover, if you previously created a {{Filename|.mpdconf}} file in your home, remove it now (to set up MPD to run with user privileges alone, pleaser refer to the section [[Music_Player_Daemon#Alternative_Setup:_Starting_as_a_User | Alternative_Setup:_Starting_as_a_User]]). This is important to prevent conflicts. The presence of the configuration file in {{Filename|/etc}}, like is the case here, is what will enable MPD to run as a daemon at boot. Otherwise, a script would be needed to run MPD ''after'' the user has logged (like kdm or {{Filename|~/.fluxbox/startup}}) or it would require a manual move each time. For a single music collection, the method used here is simply better, even while the collection is shared to multiple users. Also, don't be afraid about root privileges: even while MPD runs as a daemon, it never completely runs as root since it automatically drops its root privileges after execution.<br />
<br />
===Edit {{Filename|mpd.conf}}===<br />
<br />
The default arch install keeps the setup in /var and uses "mpd" as default user, instead of cluttering up ~/.<br />
Edit {{Filename|/etc/mpd.conf}} to reflect as such.<br />
<br />
{{File|name=/etc/mpd.conf|content=<br />
music_directory "/home/user/music" # Your music dir.<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 "/var/run/mpd/mpd.pid" # Omit this line for systemd<br />
state_file "/var/lib/mpd/mpdstate"<br />
user "mpd"<br />
# Binding to address and port causing problems in mpd-0.14.2 best to leave<br />
# commented.<br />
# bind_to_address "127.0.0.1"<br />
# port "6600"<br />
}}<br />
<br />
* If your music collection is contained under multiple directories, you can make symbolic links under /var/lib/mpd then set 'music_directory' to the directory holding the symbolic links. Remember to set permissions accordingly on the directories being linked.<br />
<br />
* To change the volume of audio from mpd independent of other programs, uncomment or add the switch in mpd.conf:<br />
<br />
{{File|name=/etc/mpd.conf|content=<br />
mixer_type "software"<br />
}}<br />
<br />
* Lastly, if you are running pulseaudio under Gnome 3, the default setting of "alsa" for the audio output will not work. Make the modification from:<br />
{{File|name=/etc/mpd.conf|content=<br />
audio_output {<br />
type "alsa"<br />
name "Sound Card"<br />
}<br />
}}<br />
<br />
to<br />
<br />
{{File|name=/etc/mpd.conf|content=<br />
audio_output {<br />
type "pulse"<br />
name "Sound Card"<br />
}<br />
}}<br />
<br />
===Create files===<br />
<br />
* As root, create the directories and files you specified in {{Filename|/etc/mpd.conf}}.<br />
# mkdir -p /var/lib/mpd/playlists /var/run/mpd<br />
# touch /var/lib/mpd/{mpd.db,mpdstate} && touch /var/run/mpd/mpd.pid<br />
<br />
* You then need to change the file's permissions so that the daemon can modify them.<br />
# chown -R mpd /var/lib/mpd /var/run/mpd<br />
<br />
===Create database===<br />
<br />
Creating the database is now accomplished via the update feature of the client, for example 'mpc update'. The previous method, creating the MPD database as root (# mpd --create-db), is deprecated.<br />
<br />
==Alternative Setup: Starting as a User==<br />
MPD need not be started with root permissions. The only reason why MPD needs to be started as root (by being called from {{Filename|/etc/rc.conf}}) is because the default files and folders in the default configuration file points to directories owned by root (the /var directory). A less common, but perhaps more sensible, approach is to make MPD work with files and directories owned by a normal user. Running MPD as a normal user has several advantages: <br />
# You can easily have a single directory ~/.mpd (or any other directory under /home/username) for all MPD configuration files<br />
# No read/write permission errors<br />
# More flexible calls to MPD by using {{Filename|~/.xinitrc}} instead of including 'mpd' in the {{Filename|/etc/rc.conf}} DAEMONS array.<br />
<br />
The following steps shows how to run MPD as a normal user. '''Note''': this approach will not work if you want multiple users to have access to MPD.<br />
<br />
* Copy the contents of the default MPD configuration file in {{Filename|/usr/share/mpd/mpd.conf.example}} to your home directory. A good place would be {{Filename|"/home/user/.mpd/mpd.conf"}}.<br />
* Follow the 'old setup instructions' from above, ignoring the first part about copying the config to {{Filename|/etc/mpd.conf}} and do not set a user variable. <br />
* Create all of the requisite files in {{filename|"/home/user/.mpd/"}}:<br />
"~/.mpd/playlists/"<br />
"~/.mpd/db"<br />
"~/.mpd/mpd.db"<br />
"~/.mpd/mpd.log"<br />
"~/.mpd/mpd.error"<br />
"~/.mpd/mpd.pid"<br />
"~/.mpd/mpdstate"<br />
<br />
* Let MPD start on bootup by calling it from your {{Filename|~/.xinitrc}} as follows:<br />
# this starts mpd as normal user<br />
mpd ~/.mpd/mpd.conf<br />
{{Note| that you don't have to put a "&" at the end of the line here, since MPD will automatically daemonize itself.}}<br />
<br />
Lastly, delete the entry 'mpd' from your DAEMONS array in {{Filename|/etc/rc.conf}}, as you are not running it as root anymore.<br />
<br />
===Quick setup===<br />
<br />
The fastest way to do set up the structure is to do this:<br />
<br />
$ mkdir -p ~/.mpd/playlists && touch ~/.mpd/database && cp /usr/share/doc/mpd/mpdconf.example ~/.mpd/mpd.conf<br />
<br />
Then edit mpd.conf to your liking, in a manner similar to [[Music_Player_Daemon#Edit_mpd.conf]]. Beware that you must uncomment the db_file entry if you do edit mpd.conf.<br />
<br />
Then, to run it:<br />
<br />
$ mpd ~/.mpd/mpd.conf<br />
<br />
<br />
===Even quicker setup===<br />
I created a little script that will only ask for the location of your music and then creates the needed files and folders for you.<br />
You can find the script here:<br />
[http://karif.server-speed.net/~carnager/mpdsetup.tar]<br />
extract it<br />
$ tar xf mpdsetup.tar<br />
and run it<br />
$ ./mpdsetup.sh<br />
<br />
If you want to use this config in daemon mode, open it (~/.mpdconf) in an editor and finde the "user" line. remove the comment (#) and fill in your own user name. Then copy the file to /etc/mpd.conf. If running mpd as user is fine for you, make sure to remove "mpd" from the daemons list in /etc/rc.conf<br />
<br />
===Multi-mpd setup===<br />
'''Useful if you want to run for example an icecast server.'''<br />
If you want a second MPD daemon (e.g., with icecast output to share music over the network) to use the same music and playlist as the one above, simply copy the above configuration file and make a new file (e.g., {{Filename|/home/username/.mpd/config-icecast}}), and only change the log_file, error_file, pid_file, and state_file parameters (e.g., {{Filename|mpd-icecast.log}}, {{Filename|mpd-icecast.error}}, and so on); using the same directory paths for the music and playlist directories would ensure that this second mpd daemon would use the same music collection as your first one (e.g., creating and editing a playlist under the first daemon would affect the second daemon as well, so that you don't have to create the same playlists all over again for the second daemon). Then, call this second daemon the same way from your {{Filename|~/.xinitrc}} above. (Just be sure to have a different port number, so as to not conflict with your first mpd daemon).<br />
<br />
==Clients==<br />
Install a client program for MPD. Popular options are:<br />
<br />
===Console===<br />
* '''mpc''' &ndash; Command Line Client (you'll probably want this one no matter what)<br />
# pacman -S mpc<br />
* [http://mpd.wikia.com/wiki/Client:Ncmpc/ ncmpc] &ndash; NCurses Client (this one is very handy for running in a console)<br />
# pacman -S ncmpc<br />
* [http://unkart.ovh.org/ncmpcpp/ ncmpcpp] &ndash; Clone of ncmpc with some new features written in C++<br />
# pacman -S ncmpcpp<br />
* [http://pms.sourceforge.net/ pms] &ndash; NCurses Client (highly configurable and accessible)<br />
Install [http://aur.archlinux.org/packages.php?ID=24378 pmus] from the [[AUR]].<br />
<br />
===Graphical===<br />
* [http://ario-player.sourceforge.net ario] &ndash; GTK+ Client with a Rhythmbox like library browser<br />
# pacman -S ario<br />
* [http://gmpcwiki.sarine.nl/index.php?title=GMPC gmpc] &ndash; GNOME Client<br />
# pacman -S gmpc<br />
* [http://bitcheese.net/wiki/QMPDClient QMPDClient] &ndash; Client written with Qt 4.x.<br />
# pacman -S qmpdclient<br />
* [http://sonata.berlios.de/ sonata] &ndash; Python GTK+ Client<br />
# pacman -S sonata<br />
* [http://aur.archlinux.org/packages.php?ID=33380 dmpc] &ndash; Dmenu-based MPC client with a playlist manager and state-saving on playlist changes<br />
Install [http://aur.archlinux.org/packages.php?ID=33380 dmpc] from the [[AUR]].<br />
<br />
See a long list of clients at the [http://mpd.wikia.com/wiki/Clients mpd wiki].<br />
<br />
==Extra stuff==<br />
===Last.fm scrobbling===<br />
To scrobble your songs to [http://www.last.fm Last.fm] using MPD there are several alternatives.<br />
<br />
====mpdscribble====<br />
mpdscribble is another daemon, available in the "community" repository (if you prefer, the "git" version is available in the [http://aur.archlinux.org/packages.php?ID=22274 AUR]). This is arguably the best alternative, because it's the semi-official MPD scrobbler and uses the new "idle" feature in MPD for more accurate scrobbling. Also, you don't need root access to configure it, because it doesn't need any changes to <tt>/etc</tt> at all. Visit [http://mpd.wikia.com/wiki/Client:Mpdscribble the official website] for more information.<br />
<br />
After you have installed mpdscribble, do the following (not as root):<br />
<br />
* {{Codeline|$ mkdir ~/.mpdscribble}}<br />
* Create the file {{Filename|~/.mpdscribble/mpdscribble.conf}} and add the following:<br />
<pre><br />
[mpdscribble] <br />
host = <your mpd host> # optional, defaults to $MPD_HOST or localhost<br />
port = <your mpd port> # optional, defaults to $MPD_PORT or 6600<br />
log = /home/<YOUR_USERNAME>/.mpdscribble/mpdscribble.log<br />
verbose = 2<br />
sleep = 1<br />
musicdir = <your music directory><br />
proxy = <your proxy> # optional, e. g. http://your.proxy:8080, defaults to none<br />
<br />
[last.fm]<br />
# last.fm section, comment if you don't use last.fm<br />
url = http://post.audioscrobbler.com/<br />
username = <your last.fm username><br />
password = <your last.fm password> # md5sum also possible: echo -n 'PASSWORD' | md5sum | cut -f 1 -d " "<br />
journal = /home/<YOUR_USERNAME>/.mpdscribble/lastfm.journal<br />
<br />
[libre.fm]<br />
# libre.fm section, comment if you don't use libre.fm<br />
url = http://turtle.libre.fm/<br />
username = <your libre.fm username><br />
password = <your libre.fm password> # md5sum also possible: echo -n 'PASSWORD' | md5sum | cut -f 1 -d " "<br />
journal = /home/<YOUR_USERNAME>/.mpdscribble/librefm.journal<br />
</pre><br />
* Add {{Codeline|mpdscribble}} to your {{Filename|~/.xinitrc}}:<br />
pidof mpdscribble >& /dev/null<br />
if [ $? -ne 0 ]; then<br />
mpdscribble &<br />
fi<br />
<br />
====Sonata & Ario====<br />
The easiest way, if you don't care about having to have a program window open all the time, is using Sonata or Ario which are graphical frontends to MPD. They have built-in support for Last.fm scrobbling in their preferences. A downside of this is that Sonata doesn't cache your songs if for some reason you don't happen to have an Internet connection at the time of playing.<br />
<br />
====lastfmsubmitd====<br />
lastfmsubmitd is a daemon which is available in the "community" repository. To install it, first edit {{Filename|/etc/lastfmsubmitd.conf}} and add both {{Codeline|lastfmsubmitd}} and {{Codeline|lastmp}} to the {{Codeline|DAEMONS}} array in {{Filename|/etc/rc.conf}}.<br />
<br />
===Last.fm playback with lastfmproxy===<br />
lastfmproxy is a python script that streams a last.fm music stream to another media player. To setup, install [http://aur.archlinux.org/packages.php?ID=14214 lastfmproxy] from the [[AUR]] and then edit {{Filename|/usr/share/lastfmproxy/config.py}}. If you plan to only stream to MPD on the same host, just edit the login info.<br />
<br />
{{Note | Since it installs to a read only directory but it requires read/write access for features like saving previously listened to stations, it would be wise to copy {{Filename|/usr/share/lastfmproxy}} to your home directory.}}<br />
<br />
Start lastfmproxy with {{Codeline|lastfmproxy}} and visit http://localhost:1881/ in your web browser. To add a last.fm station navigate to http://localhost:1881/ followed by the lastfm:// url. Example: http://localhost:1881/lastfm://globaltags/punk . Navigate back to http://localhost:1881/ and download the m3u file by selecting the ''Start Listening'' link. Simply add it to your music library path.<br />
<br />
===Never play on start===<br />
<br />
This feature has recently been added to mpd git by Martin Kellerman, see commits b57330cf75bcb339e3f268f1019c63e40d305145 and 2fb40fe728ac07574808c40034fc0f3d2254d49d.<br />
<br />
====[https://aur.archlinux.org/packages.php?ID=19676 mpd-git] Method====<br />
This is the best method currently available, but is only currently (April 2011) enabled in the git version. Install [https://aur.archlinux.org/packages.php?ID=19676 mpd-git] from the [[AUR]], then add {{Codeline|restore_paused "yes"}} to your {{Filename|mpd.conf}} file.<br />
<br />
If you have issues with connecting your client to [https://aur.archlinux.org/packages.php?ID=19676 mpd-git], see [[Music Player Daemon#Other issues when attempting to connect to mpd with a client]].<br />
<br />
====Method 1====<br />
If you don't want MPD to always play on your system start, but yet you want to preserve the other state information, add the following lines to your {{Filename|/etc/rc.d/mpd}} file:<br />
'' ...''<br />
'' stat_busy "Starting Music Player Daemon"''<br />
<br />
# always start in paused state<br />
awk '/^state_file[ \t]+"[^"]+"$/ {<br />
match($0, "\".+\"")<br />
sfile = substr($0, RSTART + 1, RLENGTH - 2)<br />
} /^user[ \t]+"[^"]+"$/ {<br />
match($0, "\".+\"")<br />
user = substr($0, RSTART + 1, RLENGTH - 2)<br />
} END {<br />
if (sfile == "")<br />
exit;<br />
if (user != "")<br />
sub(/^~/, "/home/" user, sfile)<br />
system("sed -i \x27s|^\\(state:[ \\t]\\{1,\\}\\)play$|\\1pause|\x27 \x27" sfile "\x27")<br />
}' /etc/mpd.conf<br />
<br />
'' /usr/bin/mpd /etc/mpd.conf &> /dev/null''<br />
'' ...''<br />
<br />
This will change the player status to "paused", if it was stopped while playing. Next, you want this file to be preserved, so MPD updates won't erase this edit. Add (or edit) this line to your {{Filename|/etc/pacman.conf}}:<br />
NoUpgrade = etc/rc.d/mpd<br />
<br />
====Method 2====<br />
<br />
Another simpler method, would be to add mpd to your {{Filename|[[rc.conf]]}} deamons array and add {{Codeline|mpc stop}} or {{Codeline|mpc pause}} to {{Filename|/etc/rc.local.shutdown}} and to {{Filename|/etc/rc.local}}. (Remember you must have mpc installed to use this method).<br />
<br />
Adding only the order in {{Filename|/etc/rc.local}} cannot assure that mpd will play absolutely nothing, since there may be a delay before the stop command is executed. <br />
On the other hand, if you only add the order to {{Filename|/etc/rc.local.shutdown}}, that will assure that mpd won't play at all, as long as you properly shutdown your system.<br />
Even though they are redundant, adding it to {{Filename|/etc/rc.local}} would serve as a safety for those, presumably, rare occasions when you do not shutdown the system properly.<br />
<br />
====Method 3====<br />
<br />
The general idea between this method is to ask mdp to pause music when user logs out so that during next restart, mdp will stick to that "pause" state. Sending such command can be achieve using [http://www.archlinux.org/packages/extra/x86_64/mpc/ mpc], the command line interface to MPD:<br />
pacman -S mpc<br />
<br />
GDM users can then add the next line to /etc/gdm/PostSession/Default (be sure to add it before "exit 0"):<br />
/usr/bin/mpc pause<br />
<br />
Non-GDM users can use their own login manager's method to launch the line at logout.<br />
<br />
===MPD & ALSA===<br />
Sometimes, when you use other audio output, e.g: some web pages containing Flash applets, MPD cannot reproduce anything anymore (until you restart). The error looks something like: (if you search the file {{Filename|/var/log/mpd/mpd.error}})<br />
<br />
Error opening alsa device "hw:0,0": Device or resource busy<br />
<br />
And here is the solution (dmix saving our life again). Apply these lines in your {{Filename|/etc/mpd.conf}}:<br />
<br />
<pre><br />
audio_output {<br />
type "alsa"<br />
name "Sound Card"<br />
options "dev=dmixer"<br />
device "plug:dmix"<br />
}<br />
</pre><br />
<br />
And then restart with {{Codeline|/etc/rc.d/mpd restart}}.<br />
<br />
Searching on Internet I found the reason for why that happens in Gentoo's wiki:<br />
* The sound card does not support hardware mixing (uses '''dmix''' plugin)<br />
* An application does not work with ALSA with it's default settings<br />
<br />
For a detailed description, it is recommended to take a look at [http://mpd.wikia.com/wiki/Alsa this] link. There you can find an example asound.conf which worked for me right out of the box.<br />
<br />
====High CPU usage with ALSA====<br />
When using MPD with ALSA, users may experience MPD taking up lots of CPU (around 20-30%). This is caused by most sound cards supporting 48kHz and most music being 44kHz, thus forcing MPD to resample it. This operation takes lots of CPU cycles and results into high usage.<br />
<br />
For most users the problem should be solved by telling MPD not to use resampling by adding {{Codeline|auto_resample "no"}} into audio_output-part of {{Filename|/etc/mpd.conf}}. This will degrade quality slightly, however.<br />
<br />
Example from {{Filename|mpd.conf}}:<br />
<br />
audio_output {<br />
type "alsa"<br />
name "My ALSA Device"<br />
auto_resample "no"<br />
}<br />
<br />
Although it may not give as drastic a speedup, enabling mmap may speed things up:<br />
<br />
audio_output {<br />
type "alsa"<br />
name "My ALSA Device"<br />
use_mmap "yes"<br />
}<br />
<br />
Some users might also want to tell dmix to use 44kHz as well. More info about tuning performance of your MPD can be found from: [http://mpd.wikia.com/wiki/Tuning MPD wiki]<br />
<br />
====Example configuration: Output with 44.1 KHz at e. g. 16 bit depth, multiple programs at once====<br />
<br />
''Why these formats?'' Because they are standard CDA, because ALSA on its own allows more than one program "to sound" only with dmix — whose resampling algorithm is inferior — and because dmix by default resamples anything lower to 48 KHz (or whatever higher format is playing at the time). Also, some get clicking sounds if at least {{Filename|mpd.conf}} is not changed this way.<br />
<br />
''What's the downside?'' These settings cause ''everything'' (if necessary) to be resampled to this format, such as material from DVD or TV which usually is at 48 KHz. But there is no known way to have ALSA dynamically change the format, and particularly if you listen to far more CDs than anything else the occasional 48 → 44.1 isn't too great a loss.<br />
<br />
The following assumes that there are not already other settings which conflict resp. overwrite it. This applies especially to the current user's potential {{Filename|~/.asoundrc}} — which MPD as its own user ignores, therefore the following should go to {{Filename|/etc/asound.conf}}:<br />
<br />
{{File|name=/etc/asound.conf|content=<br />
defaults.pcm.dmix.rate 44100 # Force 44.1 KHz<br />
defaults.pcm.dmix.format S16_LE # Force 16 bits<br />
}}<br />
<br />
{{File|name=/etc/mpd.conf|content=<br />
audio_output {<br />
type "alsa" # Use the ALSA output plugin.<br />
name "HDA Intel" # Can be called anything or nothing tmk, but must be present.<br />
options "dev=dmixer"<br />
device "plug:dmix" # Both lines cause MPD to output to dmix.<br />
format "44100:16:2" # the actual format<br />
auto_resample "no" # This bypasses ALSA's own algorithms, which generally are inferior. See below how to choose a different one.<br />
use_mmap "yes" # Minor speed improvement, should work with all modern cards.<br />
}<br />
<br />
samplerate_converter "0" # MPD's best, most CPU intensive algorithm. See 'man mpd.conf' for others — for anything other than the poorest "internal", libsamplerate must be installed.<br />
}}<br />
<br />
{{Note|MPD gives the mp3 format a special treatment at decoding: It's always outputted as 24 bit. (The conversion as forced by the ''format'' line only comes after that.)}}<br />
<br />
If one wants to leave the bit depth decision to ALSA resp. MPD, comment out resp. omit the ''dmix.format'' line and change the one for mpd with ''format'' to "44100:*:2".<br />
<br />
{{Note|''Crossfading'' between files decoded at two different bit depths (say, one mp3 and one 16 bit flac) does not work unless conversion is active.}}<br />
<br />
===Control MPD with lirc===<br />
There are already some clients designed for communications between lircd and MPD, however, as far as the practical use, they aren't very useful since their functions are limited.<br />
<br />
It's recommended to use mpc with irexec. mpc is a command line player which only sends the command to MPD and exits immediately, which is perfect for irexec, the command runner included in lirc. What irexec does is that it runs a specified command once received a remote control button.<br />
<br />
First of all, please setup your remotes as referred to the '''[[Lirc]]''' article.<br />
<br />
Edit your favored lirc startup configuration file, default location is {{Filename|~/.lircrc}}.<br />
<br />
Fill the file with the following pattern:<br />
begin<br />
prog = irexec<br />
button = <button_name><br />
config = <command_to_run><br />
repeat = <0 or 1><br />
end<br />
<br />
An useful example:<br />
## irexec<br />
begin<br />
prog = irexec<br />
button = play_pause<br />
config = mpc toggle<br />
repeat = 0<br />
end<br />
<br />
begin<br />
prog = irexec<br />
button = stop<br />
config = mpc stop<br />
repeat = 0<br />
end<br />
begin<br />
prog = irexec<br />
button = previous<br />
config = mpc prev<br />
repeat = 0<br />
end<br />
begin<br />
prog = irexec<br />
button = next<br />
config = mpc next<br />
repeat = 0<br />
end<br />
begin<br />
prog = irexec<br />
button = volup<br />
config = mpc volume +2<br />
repeat = 1<br />
end<br />
begin<br />
prog = irexec<br />
button = voldown<br />
config = mpc volume -2<br />
repeat = 1<br />
end<br />
begin<br />
prog = irexec<br />
button = pbc<br />
config = mpc random<br />
repeat = 0<br />
end<br />
begin<br />
prog = irexec<br />
button = pdvd<br />
config = mpc update<br />
repeat = 0<br />
end<br />
begin<br />
prog = irexec<br />
button = right<br />
config = mpc seek +00:00:05<br />
repeat = 0<br />
end<br />
begin<br />
prog = irexec<br />
button = left<br />
config = mpc seek -00:00:05<br />
repeat = 0<br />
end<br />
begin<br />
prog = irexec<br />
button = up<br />
config = mpc seek +1%<br />
repeat = 0<br />
end<br />
begin<br />
prog = irexec<br />
button = down<br />
config = mpc seek -1%<br />
repeat = 0<br />
end<br />
<br />
There are more functions for mpc, run {{Codeline|man mpc}} for more info.<br />
<br />
===Control MPD with bluetooth phone===<br />
You can also control MPD (to a certain extent) using a bluetooth enabled phone. You need to do the following:<br />
<br />
* install [http://remuco.sourceforge.net/index.php/Remuco remuco] -- a wireless remote control for several Linux media players ([http://aur.archlinux.org/packages.php?ID=25072 aur])<br />
* transfer remuco client -- jar/jad files from {{Filename|/usr/share/remuco/client/}} to your phone and install it<br />
* run {{Codeline|remuco-mpd}} (as current user)<br />
* run remuco on your phone, define a new bluetooth remuco connection (pair first if you haven't done this previously) and explore its capabilities<br />
<br />
More information about remuco including troubleshooting to be found at its [http://remuco.sourceforge.net/index.php/Remuco homepage]<br />
<br />
===MPD & PulseAudio===<br />
<br />
Edit {{Filename|/etc/mpd.conf}}, and uncomment the audio_output section for the type "pulse". The server and sink lines of it should be commented unless you know what you're doing.<br />
<br />
Then, add the mpd user (and yours if you haven't done so already) to the necessary pulse groups. The pulse-access group should be sufficient but you may want to add pulse-rt as well. The group "pulse" doesn't appear to be necessary.<br />
# gpasswd -a mpd pulse-access<br />
# gpasswd -a mpd pulse-rt<br />
<br />
Lastly, you may or may not need to copy {{Filename|~/.pulse-cookie}} from your current (pulse working) user's dir to your mpd user's home directory. It is likely to be {{Filename|/var/lib/mpd}} if you followed the first part of this wiki. This would probably only allow your current user to listen in on MPD's pulse. You may consider running pulse system-wide if that's insufficient.<br />
<br />
===Cue Files===<br />
<br />
To make cue file support actually work, you have to work around a nasty libcue bug. Libcue copied some files directly from libcdio, making it conflict with it. Steps to do to get proper cue support:<br />
<br />
* remove libcdio temporary (pacman -Rdd libcdio)<br />
* install libcue (pacman -S libcue)<br />
* install mpd with abs or from aur.<br />
* reinstall libcdio (pacman -S libcdio)<br />
<br />
At the point of writing mpd does not parse tracknumbers from cue sheets. There is a patch available (http://musicpd.org/mantis/view.php?id=3230)<br />
Once this patch is merged into mpd, i will remove this line :)<br />
<br />
==Troubleshooting==<br />
===Autodetection failed===<br />
During the start of MPD, it tries to autodetect your set-up and configure output and volume control accordingly. Though this mostly goes well, it will fail for some systems. It may help to tell MPD specifically what to use as output and mixer control. If you copied {{Filename|/etc/mpd.conf}} over from {{Filename|/etc/mpd.conf.example}} as mentioned above, you can simply uncomment:<br />
<br />
Example for alsa output type and alsa mixer:<br />
audio_output {<br />
type "alsa"<br />
name "My ALSA Device"<br />
device "hw:0,0" # optional<br />
format "44100:16:2" # optional<br />
mixer_type "hardware"<br />
mixer_device "default"<br />
mixer_control "PCM"<br />
}<br />
<br />
'''Note:''' in case of permission problems when using ESD with MPD run this as root:<br />
# chsh -s /bin/true mpd<br />
<br />
===Executable permissions===<br />
{{Warning|This is not good security practice and may be unnecessary.}}<br />
<br />
MPD needs to have +x permissions on '''ALL''' parent directories to your music collection (ie. if it's located outside of "mpd" home directory /var/lib/mpd). By default useradd sets permissions on home dir to 1700 drwx------. So if you're like me you will need to change permissions of /home/user. Example... my music collection is located /home/user/music. <br />
# chmod a+x /home/$USER<br />
# chmod -R a+X /home/$USER/music<br />
<br />
====Alternative solution====<br />
An alternative solution would be to use your group to share a selection of files, among them your music library. First remove all permissions for the group then add group permissions to read and execute home and music.<br />
# chmod -R g-rwx /home/$USER<br />
# chmod g+rx /home/$USER<br />
# chmod -R g+rX /home/$USER/music<br />
<br />
====Another alternative solution====<br />
Another alternative is to remount the music directory under a directory that mpd has access to. This does not entail the same security risks as modifying the permissions on one's home directory.<br />
# mkdir /var/lib/mpd/music<br />
# echo "/home/$USER/music /var/lib/mpd/music none bind" >> /etc/fstab<br />
# mount -a<br />
# /etc/rc.d/mpd restart<br />
And that should fix the problem. See also [https://bbs.archlinux.org/viewtopic.php?id=86449 the forum thread.]<br />
<br />
===Avoiding timeouts===<br />
To get rid of timeouts (i.e. when you paused music for long time) in gpmc and other clients uncomment and increase {{Codeline|connection_timeout}} option in {{Filename|mpd.conf}}.<br />
<br />
If files and/or titles are shown in wrong encoding, uncomment and change {{Codeline|filesystem_charset}} and {{Codeline|id3v1_encoding}} options.<br />
Note that you cannot set encoding for ID3 v2 tags. To workaround this you may use [http://mpd.wikia.com/wiki/GenericDecoder#Generic_Tagreader external tag readers].<br />
<br />
If you want to use another computer to control MPD over a network, the {{Codeline|bind_to_address}} option in {{Filename|mpd.conf}} will need to be set to either your IP address, or {{Codeline|any}} if your IP address changes frequently. <br />
<br />
'''Streaming'''<br><br />
With the latest version of MPD (0.15), built-in httpd streaming is now available.<br />
<br />
To activate this feature, you'll just need to add a new output of type httpd in {{Filename|mpd.conf}}:<br />
audio_output {<br />
type "httpd"<br />
name "What you want"<br />
encoder "lame" # vorbis or lame supported<br />
port "8000"<br />
bitrate "128"<br />
format "44100:16:2" # change 2 to 1 for mono<br />
}<br />
<br />
Restart the mpd deamon and, from another computer, simply load the stream as any other url. <br />
$ mplayer http://<server's IP>:8000<br />
<br />
{{Note | You must open the port on your router / firewall for the stream to be connectible to from another computer.}}<br />
<br />
Most players (i.e. vlc or xmms2) should also be able to load the stream via their "add url..." menu option.<br />
<br />
This is a nice clean way to replace your current icecast setup with something natively supported within MPD.<br />
<br />
===mpd hangs on first startup===<br />
This is a common error that's caused by corrupt mp3 tags.<br />
Here is an experimental way to solve this issue.<br />
Requirements:<br />
* kid3<br />
* easytag<br />
<br />
This method is very tedious, especially with a huge database. Just as a baseline it took 2.5h to fix a 16Gb DB.<br />
<br />
====Easy Tag====<br />
The purpose of easytag here is that easytag detects the error in the tags, but like MPD it hangs and dies. The trick here is that easy tags actually tells you what file is causing the problem on the status bar.<br />
Before starting easytag make sure to have a terminal close to be ready to kill easy tag to avoid a hang. Once you are ready, on the tree view select the directory where all your music is located. By default easytag starts to search all subdirectories for mp3 files. Once you notice that easytag stopped scanning for songs, make note of the culprit and kill easytag.<br />
<br />
====KID3====<br />
Here's where kid3 comes in handy. With kid3 go to the offending song and rewrite one of the tags. then save the file. This should force kid3 to rewrite the whole tag again fixing the problem with MPD and easy tag hanging.<br />
<br />
Repeat this procedure until your music library is done.<br />
<br />
===Cannot connect to mpd: host "localhost" not found: Temporary failure in name resolution===<br />
Cannot connect to MPD (with ncmpcpp), if you are disconnected from network. Solution is [[IPv6 - Disabling the Module|disable IPv6]] or add line to /etc/hosts<br />
::1 localhost.localdomain localhost<br />
<br />
===Other issues when attempting to connect to mpd with a client===<br />
Some have reported being unable to access mpd with various clients, for example seeing errors like these:<br />
$ ncmpcpp<br />
Cannot connect to mpd: Connection closed by the server<br />
$ sonata<br />
2011-02-13 18:33:05 Connection lost while reading MPD hello<br />
2011-02-13 18:33:05 Not connected<br />
2011-02-13 18:33:05 Not connected<br />
<br />
Please see posts on ncmpcpp on the Arch Forums [https://bbs.archlinux.org/viewtopic.php?id=109962 HERE] and [https://bbs.archlinux.org/viewtopic.php?id=113493 HERE]. Also see the Arch bug report on this issue [https://bugs.archlinux.org/task/22071 HERE]. <br />
<br />
====First fix====<br />
Check {{Filename|mpd.conf}} for a line like {{Codeline|mpd.error}} and remove it. The mpd error file is deprecated and has been removed.<br />
<br />
====Second fix====<br />
{{Note|I'm not so sure this is a good idea. There is a warning about changing the address to bind to in the default mpd.conf. If this does not help, you might want to comment out the changes.}}<br />
If that doesn't help, add the following to {{Filename|mpd.conf}}:<br />
<pre><br />
bind_to_address "127.0.0.1"<br />
port "6600"<br />
</pre><br />
<br />
Afterwards, instruct your client to connect via 127.0.0.1. For example, add the following to the ncmpcpp config file:<br />
<pre><br />
mpd_host "127.0.0.1"<br />
mpd_port "6600"<br />
</pre><br />
<br />
<br />
===Port 6600 already in use===<br />
MPD needs to bind to port 6600 and cannot start if it's already in use. The most common reason for this is that the user has started MPD once and then subsequently tried to start mpd again. In general, nothing should be done here.<br />
<br />
If port 6600 is tied up for some other reason, one can use the following command to find the offending process:<br />
# netstat -tulpan | grep 6600<br />
<br />
This will list IP:Port and the process name holding the connection (root privileges are required to see all processes).<br />
<br />
If you need to restart mpd for whatever reason, use:<br />
<pre><br />
$ mpd --kill<br />
$ mpd <br />
</pre><br />
A more brute-force approach:<br />
<pre><br />
$ killall mpd<br />
$ mpd <br />
</pre><br />
{{Note| If you typically run MPD as root, you will need to run the above commands as root.}}<br />
<br />
In the latest version of MPD, --create-db is completely deprecated. The database will be created automagically on first run and can subsequently be updated via your client (i.e. mpc update). You can now use inotify support to automatically update your music database. Add the following to {{File|name=mpd.conf|content=auto_update "yes"}} to enable it.<br />
<br />
===Binding to IPV6 before IPV4===<br />
If on startup, you see this message:<br />
listen: bind to '0.0.0.0:6600' failed: Address already in use (continuing anyway, because binding to '[::]:6600' succeeded)<br />
MPD is attempting to bind to the ipv6 interface before binding to ipv4. If you want to use your ipv4 interface, hardcode it in mpd.conf, like so:<br />
bind_to_address "127.0.0.1"<br />
Or, you could specify several binds, for example, to have MPD listen on localhost and the external IP of your network card:<br />
bind_to_address "127.0.0.1"<br />
bind_to_address "192.168.1.13"<br />
<br />
===Crackling sound with some audio files===<br />
This is usually a playback speed problem and can be fixed by uncommenting the audio_output_format line in:<br />
<br />
{{File|name=/etc/mpd.conf|content=<br />
audio_output_format "44100:16:2"}}<br />
<br />
This is usually a sane value for most mp3 files.<br />
<br />
===daemon: cannot setgid for user "mpd": Operation not permitted ===<br />
<br />
The error is stating that the user starting the process (you) does not have permissions to become another user (mpd) which the configuration has told that process to run as.<br />
<br />
To solve the issue, simply start mpd as root.<br />
su -c "/etc/rc.d/mpd start"<br />
or<br />
sudo /etc/rc.d/mpd start<br />
<br />
==External links==<br />
* [http://www.musicpd.org/ Official Web Site]<br />
* [http://mpd.wikia.com/wiki/Main_Page Official Wiki]<br />
* [http://mpd.wikia.com/wiki/Clients Sorted List of MPD Clients]<br />
* [http://www.musicpd.org/forum/ MPD forum]</div>Rasihttps://wiki.archlinux.org/index.php?title=Music_Player_Daemon&diff=150555Music Player Daemon2011-08-03T13:13:48Z<p>Rasi: /* Even quicker setup */</p>
<hr />
<div>[[fr:MPD]]<br />
[[Category:Audio/Video (English)]]<br />
[[Category:Daemons and system services (English)]]<br />
{{i18n|Music Player Daemon}}<br />
[[pl:Music Player Daemon]]<br />
<br />
'''MPD''' (music player daemon) is an audio player that has a server-client architecture. MPD runs in the background as a daemon, manages playlists and a music database, and uses very few resources. In order to interface with it, you need a separate client. More information can be found on their [http://www.musicpd.org/ website].<br />
<br />
''Please'' have a look at the official page for setup and troubleshooting instructions, the main developer called our wiki page in its current state ''"full of symptom killers"'', hence the official pages should contain better instructions.<br />
<br />
==Installing mpd==<br />
Install with [[pacman]]:<br />
# pacman -S mpd<br />
<br />
==Daemon Setup: Starting at Boot==<br />
General information about MPD configuration may be found at http://mpd.wikia.com/wiki/Configuration.<br />
<br />
===Sound setup===<br />
To make audio output actually work ensure that you have setup audio card and mixer correctly. See [[ALSA]], and [[PulseAudio]] if you are using Gnome 3. Do not forget to unmute the required channels in alsamixer, raise the volume and save changes with alsactl store. Run mpd with {{Filename|/usr/bin/mpd --stdout --no-daemon --verbose}} if that still doesn't work.<br />
<br />
Make sure your card can do hardware mixing (most of them can, including onboard audio). Or else this could cause problems with multiple sound playback. For example, this can prevent Mplayer from playing back sound while the mpd daemon is running, returning an audio error message stating the device is busy.<br />
<br />
===Timeline of MPD's behavior on a typical working setup when started as a daemon===<br />
# MPD is started on boot by {{Filename|/etc/rc.conf}}, by including it in the {{Codeline|DAEMONS}} array. (Or, this can be done manually each session by running {{Codeline|/etc/rc.d/mpd start}} with root privileges).<br />
# Since MPD is now started as root, it first reads the {{Filename|/etc/mpd.conf}} file.<br />
# MPD reads the user variable in the {{Filename|/etc/mpd.conf}} file, and changes from root to this user.<br />
# MPD then reads the contents of the {{Filename|/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 {{Filename|/etc/mpd.conf}} file. This way, uses of {{Codeline|~}} in the configuration file point correctly to the home user's directory, and not root's directory. It may be worthwhile to change all uses of {{Codeline|~}} to {{Codeline|/home/username}} to avoid any confusion over this aspect of MPD's behavior.<br />
<br />
===A clean configuration file===<br />
* As root, check if {{Filename|/etc/mpd.conf}} exists and delete the file if it does. This is safe.<br />
<br />
MPD comes with an example configuration file, available at {{Filename|/usr/share/mpd/mpd.conf.example}}. This file holds an abundance of information on MPD configuration, and holds default mixer values you can simply uncomment.<br />
<br />
* As root, copy this example file to {{Filename|/etc/mpd.conf}}.<br />
# cp /usr/share/mpd/mpd.conf.example /etc/mpd.conf<br />
({{Filename|/usr/share/mpd/mpd.conf.example}} is good for userspace setup)<br />
<br />
Since MPD is being set up to run as a daemon at boot, never put this file in the user's directory like some tutorials suggest, since it will not be read. Moreover, if you previously created a {{Filename|.mpdconf}} file in your home, remove it now (to set up MPD to run with user privileges alone, pleaser refer to the section [[Music_Player_Daemon#Alternative_Setup:_Starting_as_a_User | Alternative_Setup:_Starting_as_a_User]]). This is important to prevent conflicts. The presence of the configuration file in {{Filename|/etc}}, like is the case here, is what will enable MPD to run as a daemon at boot. Otherwise, a script would be needed to run MPD ''after'' the user has logged (like kdm or {{Filename|~/.fluxbox/startup}}) or it would require a manual move each time. For a single music collection, the method used here is simply better, even while the collection is shared to multiple users. Also, don't be afraid about root privileges: even while MPD runs as a daemon, it never completely runs as root since it automatically drops its root privileges after execution.<br />
<br />
===Edit {{Filename|mpd.conf}}===<br />
<br />
The default arch install keeps the setup in /var and uses "mpd" as default user, instead of cluttering up ~/.<br />
Edit {{Filename|/etc/mpd.conf}} to reflect as such.<br />
<br />
{{File|name=/etc/mpd.conf|content=<br />
music_directory "/home/user/music" # Your music dir.<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 "/var/run/mpd/mpd.pid" # Omit this line for systemd<br />
state_file "/var/lib/mpd/mpdstate"<br />
user "mpd"<br />
# Binding to address and port causing problems in mpd-0.14.2 best to leave<br />
# commented.<br />
# bind_to_address "127.0.0.1"<br />
# port "6600"<br />
}}<br />
<br />
* If your music collection is contained under multiple directories, you can make symbolic links under /var/lib/mpd then set 'music_directory' to the directory holding the symbolic links. Remember to set permissions accordingly on the directories being linked.<br />
<br />
* To change the volume of audio from mpd independent of other programs, uncomment or add the switch in mpd.conf:<br />
<br />
{{File|name=/etc/mpd.conf|content=<br />
mixer_type "software"<br />
}}<br />
<br />
* Lastly, if you are running pulseaudio under Gnome 3, the default setting of "alsa" for the audio output will not work. Make the modification from:<br />
{{File|name=/etc/mpd.conf|content=<br />
audio_output {<br />
type "alsa"<br />
name "Sound Card"<br />
}<br />
}}<br />
<br />
to<br />
<br />
{{File|name=/etc/mpd.conf|content=<br />
audio_output {<br />
type "pulse"<br />
name "Sound Card"<br />
}<br />
}}<br />
<br />
===Create files===<br />
<br />
* As root, create the directories and files you specified in {{Filename|/etc/mpd.conf}}.<br />
# mkdir -p /var/lib/mpd/playlists /var/run/mpd<br />
# touch /var/lib/mpd/{mpd.db,mpdstate} && touch /var/run/mpd/mpd.pid<br />
<br />
* You then need to change the file's permissions so that the daemon can modify them.<br />
# chown -R mpd /var/lib/mpd /var/run/mpd<br />
<br />
===Create database===<br />
<br />
Creating the database is now accomplished via the update feature of the client, for example 'mpc update'. The previous method, creating the MPD database as root (# mpd --create-db), is deprecated.<br />
<br />
==Alternative Setup: Starting as a User==<br />
MPD need not be started with root permissions. The only reason why MPD needs to be started as root (by being called from {{Filename|/etc/rc.conf}}) is because the default files and folders in the default configuration file points to directories owned by root (the /var directory). A less common, but perhaps more sensible, approach is to make MPD work with files and directories owned by a normal user. Running MPD as a normal user has several advantages: <br />
# You can easily have a single directory ~/.mpd (or any other directory under /home/username) for all MPD configuration files<br />
# No read/write permission errors<br />
# More flexible calls to MPD by using {{Filename|~/.xinitrc}} instead of including 'mpd' in the {{Filename|/etc/rc.conf}} DAEMONS array.<br />
<br />
The following steps shows how to run MPD as a normal user. '''Note''': this approach will not work if you want multiple users to have access to MPD.<br />
<br />
* Copy the contents of the default MPD configuration file in {{Filename|/usr/share/mpd/mpd.conf.example}} to your home directory. A good place would be {{Filename|"/home/user/.mpd/mpd.conf"}}.<br />
* Follow the 'old setup instructions' from above, ignoring the first part about copying the config to {{Filename|/etc/mpd.conf}} and do not set a user variable. <br />
* Create all of the requisite files in {{filename|"/home/user/.mpd/"}}:<br />
"~/.mpd/playlists/"<br />
"~/.mpd/db"<br />
"~/.mpd/mpd.db"<br />
"~/.mpd/mpd.log"<br />
"~/.mpd/mpd.error"<br />
"~/.mpd/mpd.pid"<br />
"~/.mpd/mpdstate"<br />
<br />
* Let MPD start on bootup by calling it from your {{Filename|~/.xinitrc}} as follows:<br />
# this starts mpd as normal user<br />
mpd ~/.mpd/mpd.conf<br />
{{Note| that you don't have to put a "&" at the end of the line here, since MPD will automatically daemonize itself.}}<br />
<br />
Lastly, delete the entry 'mpd' from your DAEMONS array in {{Filename|/etc/rc.conf}}, as you are not running it as root anymore.<br />
<br />
===Quick setup===<br />
<br />
The fastest way to do set up the structure is to do this:<br />
<br />
$ mkdir -p ~/.mpd/playlists && touch ~/.mpd/database && cp /usr/share/doc/mpd/mpdconf.example ~/.mpd/mpd.conf<br />
<br />
Then edit mpd.conf to your liking, in a manner similar to [[Music_Player_Daemon#Edit_mpd.conf]]. Beware that you must uncomment the db_file entry if you do edit mpd.conf.<br />
<br />
Then, to run it:<br />
<br />
$ mpd ~/.mpd/mpd.conf<br />
<br />
<br />
===Even quicker setup===<br />
I created a little script that will only ask for the location of your music and then creates the needed files and folders for you.<br />
You can find the script here:<br />
[http://karif.server-speed.net/~carnager/mpdsetup.tar]<br />
extract it<br />
$ tar xf mpdsetup.tar<br />
and run it<br />
$ ./mpdsetup.sh<br />
<br />
Keep in mind, that this is a user install, so remove the DAEMON. If you want to use this config in daemon mode, open it (~/.mpdconf) in an editor and finde the "user" line. remove the comment (#) and fill in your own user name. Then copy the file to /etc/mpd.conf<br />
<br />
===Multi-mpd setup===<br />
'''Useful if you want to run for example an icecast server.'''<br />
If you want a second MPD daemon (e.g., with icecast output to share music over the network) to use the same music and playlist as the one above, simply copy the above configuration file and make a new file (e.g., {{Filename|/home/username/.mpd/config-icecast}}), and only change the log_file, error_file, pid_file, and state_file parameters (e.g., {{Filename|mpd-icecast.log}}, {{Filename|mpd-icecast.error}}, and so on); using the same directory paths for the music and playlist directories would ensure that this second mpd daemon would use the same music collection as your first one (e.g., creating and editing a playlist under the first daemon would affect the second daemon as well, so that you don't have to create the same playlists all over again for the second daemon). Then, call this second daemon the same way from your {{Filename|~/.xinitrc}} above. (Just be sure to have a different port number, so as to not conflict with your first mpd daemon).<br />
<br />
==Clients==<br />
Install a client program for MPD. Popular options are:<br />
<br />
===Console===<br />
* '''mpc''' &ndash; Command Line Client (you'll probably want this one no matter what)<br />
# pacman -S mpc<br />
* [http://mpd.wikia.com/wiki/Client:Ncmpc/ ncmpc] &ndash; NCurses Client (this one is very handy for running in a console)<br />
# pacman -S ncmpc<br />
* [http://unkart.ovh.org/ncmpcpp/ ncmpcpp] &ndash; Clone of ncmpc with some new features written in C++<br />
# pacman -S ncmpcpp<br />
* [http://pms.sourceforge.net/ pms] &ndash; NCurses Client (highly configurable and accessible)<br />
Install [http://aur.archlinux.org/packages.php?ID=24378 pmus] from the [[AUR]].<br />
<br />
===Graphical===<br />
* [http://ario-player.sourceforge.net ario] &ndash; GTK+ Client with a Rhythmbox like library browser<br />
# pacman -S ario<br />
* [http://gmpcwiki.sarine.nl/index.php?title=GMPC gmpc] &ndash; GNOME Client<br />
# pacman -S gmpc<br />
* [http://bitcheese.net/wiki/QMPDClient QMPDClient] &ndash; Client written with Qt 4.x.<br />
# pacman -S qmpdclient<br />
* [http://sonata.berlios.de/ sonata] &ndash; Python GTK+ Client<br />
# pacman -S sonata<br />
* [http://aur.archlinux.org/packages.php?ID=33380 dmpc] &ndash; Dmenu-based MPC client with a playlist manager and state-saving on playlist changes<br />
Install [http://aur.archlinux.org/packages.php?ID=33380 dmpc] from the [[AUR]].<br />
<br />
See a long list of clients at the [http://mpd.wikia.com/wiki/Clients mpd wiki].<br />
<br />
==Extra stuff==<br />
===Last.fm scrobbling===<br />
To scrobble your songs to [http://www.last.fm Last.fm] using MPD there are several alternatives.<br />
<br />
====mpdscribble====<br />
mpdscribble is another daemon, available in the "community" repository (if you prefer, the "git" version is available in the [http://aur.archlinux.org/packages.php?ID=22274 AUR]). This is arguably the best alternative, because it's the semi-official MPD scrobbler and uses the new "idle" feature in MPD for more accurate scrobbling. Also, you don't need root access to configure it, because it doesn't need any changes to <tt>/etc</tt> at all. Visit [http://mpd.wikia.com/wiki/Client:Mpdscribble the official website] for more information.<br />
<br />
After you have installed mpdscribble, do the following (not as root):<br />
<br />
* {{Codeline|$ mkdir ~/.mpdscribble}}<br />
* Create the file {{Filename|~/.mpdscribble/mpdscribble.conf}} and add the following:<br />
<pre><br />
[mpdscribble] <br />
host = <your mpd host> # optional, defaults to $MPD_HOST or localhost<br />
port = <your mpd port> # optional, defaults to $MPD_PORT or 6600<br />
log = /home/<YOUR_USERNAME>/.mpdscribble/mpdscribble.log<br />
verbose = 2<br />
sleep = 1<br />
musicdir = <your music directory><br />
proxy = <your proxy> # optional, e. g. http://your.proxy:8080, defaults to none<br />
<br />
[last.fm]<br />
# last.fm section, comment if you don't use last.fm<br />
url = http://post.audioscrobbler.com/<br />
username = <your last.fm username><br />
password = <your last.fm password> # md5sum also possible: echo -n 'PASSWORD' | md5sum | cut -f 1 -d " "<br />
journal = /home/<YOUR_USERNAME>/.mpdscribble/lastfm.journal<br />
<br />
[libre.fm]<br />
# libre.fm section, comment if you don't use libre.fm<br />
url = http://turtle.libre.fm/<br />
username = <your libre.fm username><br />
password = <your libre.fm password> # md5sum also possible: echo -n 'PASSWORD' | md5sum | cut -f 1 -d " "<br />
journal = /home/<YOUR_USERNAME>/.mpdscribble/librefm.journal<br />
</pre><br />
* Add {{Codeline|mpdscribble}} to your {{Filename|~/.xinitrc}}:<br />
pidof mpdscribble >& /dev/null<br />
if [ $? -ne 0 ]; then<br />
mpdscribble &<br />
fi<br />
<br />
====Sonata & Ario====<br />
The easiest way, if you don't care about having to have a program window open all the time, is using Sonata or Ario which are graphical frontends to MPD. They have built-in support for Last.fm scrobbling in their preferences. A downside of this is that Sonata doesn't cache your songs if for some reason you don't happen to have an Internet connection at the time of playing.<br />
<br />
====lastfmsubmitd====<br />
lastfmsubmitd is a daemon which is available in the "community" repository. To install it, first edit {{Filename|/etc/lastfmsubmitd.conf}} and add both {{Codeline|lastfmsubmitd}} and {{Codeline|lastmp}} to the {{Codeline|DAEMONS}} array in {{Filename|/etc/rc.conf}}.<br />
<br />
===Last.fm playback with lastfmproxy===<br />
lastfmproxy is a python script that streams a last.fm music stream to another media player. To setup, install [http://aur.archlinux.org/packages.php?ID=14214 lastfmproxy] from the [[AUR]] and then edit {{Filename|/usr/share/lastfmproxy/config.py}}. If you plan to only stream to MPD on the same host, just edit the login info.<br />
<br />
{{Note | Since it installs to a read only directory but it requires read/write access for features like saving previously listened to stations, it would be wise to copy {{Filename|/usr/share/lastfmproxy}} to your home directory.}}<br />
<br />
Start lastfmproxy with {{Codeline|lastfmproxy}} and visit http://localhost:1881/ in your web browser. To add a last.fm station navigate to http://localhost:1881/ followed by the lastfm:// url. Example: http://localhost:1881/lastfm://globaltags/punk . Navigate back to http://localhost:1881/ and download the m3u file by selecting the ''Start Listening'' link. Simply add it to your music library path.<br />
<br />
===Never play on start===<br />
<br />
This feature has recently been added to mpd git by Martin Kellerman, see commits b57330cf75bcb339e3f268f1019c63e40d305145 and 2fb40fe728ac07574808c40034fc0f3d2254d49d.<br />
<br />
====[https://aur.archlinux.org/packages.php?ID=19676 mpd-git] Method====<br />
This is the best method currently available, but is only currently (April 2011) enabled in the git version. Install [https://aur.archlinux.org/packages.php?ID=19676 mpd-git] from the [[AUR]], then add {{Codeline|restore_paused "yes"}} to your {{Filename|mpd.conf}} file.<br />
<br />
If you have issues with connecting your client to [https://aur.archlinux.org/packages.php?ID=19676 mpd-git], see [[Music Player Daemon#Other issues when attempting to connect to mpd with a client]].<br />
<br />
====Method 1====<br />
If you don't want MPD to always play on your system start, but yet you want to preserve the other state information, add the following lines to your {{Filename|/etc/rc.d/mpd}} file:<br />
'' ...''<br />
'' stat_busy "Starting Music Player Daemon"''<br />
<br />
# always start in paused state<br />
awk '/^state_file[ \t]+"[^"]+"$/ {<br />
match($0, "\".+\"")<br />
sfile = substr($0, RSTART + 1, RLENGTH - 2)<br />
} /^user[ \t]+"[^"]+"$/ {<br />
match($0, "\".+\"")<br />
user = substr($0, RSTART + 1, RLENGTH - 2)<br />
} END {<br />
if (sfile == "")<br />
exit;<br />
if (user != "")<br />
sub(/^~/, "/home/" user, sfile)<br />
system("sed -i \x27s|^\\(state:[ \\t]\\{1,\\}\\)play$|\\1pause|\x27 \x27" sfile "\x27")<br />
}' /etc/mpd.conf<br />
<br />
'' /usr/bin/mpd /etc/mpd.conf &> /dev/null''<br />
'' ...''<br />
<br />
This will change the player status to "paused", if it was stopped while playing. Next, you want this file to be preserved, so MPD updates won't erase this edit. Add (or edit) this line to your {{Filename|/etc/pacman.conf}}:<br />
NoUpgrade = etc/rc.d/mpd<br />
<br />
====Method 2====<br />
<br />
Another simpler method, would be to add mpd to your {{Filename|[[rc.conf]]}} deamons array and add {{Codeline|mpc stop}} or {{Codeline|mpc pause}} to {{Filename|/etc/rc.local.shutdown}} and to {{Filename|/etc/rc.local}}. (Remember you must have mpc installed to use this method).<br />
<br />
Adding only the order in {{Filename|/etc/rc.local}} cannot assure that mpd will play absolutely nothing, since there may be a delay before the stop command is executed. <br />
On the other hand, if you only add the order to {{Filename|/etc/rc.local.shutdown}}, that will assure that mpd won't play at all, as long as you properly shutdown your system.<br />
Even though they are redundant, adding it to {{Filename|/etc/rc.local}} would serve as a safety for those, presumably, rare occasions when you do not shutdown the system properly.<br />
<br />
====Method 3====<br />
<br />
The general idea between this method is to ask mdp to pause music when user logs out so that during next restart, mdp will stick to that "pause" state. Sending such command can be achieve using [http://www.archlinux.org/packages/extra/x86_64/mpc/ mpc], the command line interface to MPD:<br />
pacman -S mpc<br />
<br />
GDM users can then add the next line to /etc/gdm/PostSession/Default (be sure to add it before "exit 0"):<br />
/usr/bin/mpc pause<br />
<br />
Non-GDM users can use their own login manager's method to launch the line at logout.<br />
<br />
===MPD & ALSA===<br />
Sometimes, when you use other audio output, e.g: some web pages containing Flash applets, MPD cannot reproduce anything anymore (until you restart). The error looks something like: (if you search the file {{Filename|/var/log/mpd/mpd.error}})<br />
<br />
Error opening alsa device "hw:0,0": Device or resource busy<br />
<br />
And here is the solution (dmix saving our life again). Apply these lines in your {{Filename|/etc/mpd.conf}}:<br />
<br />
<pre><br />
audio_output {<br />
type "alsa"<br />
name "Sound Card"<br />
options "dev=dmixer"<br />
device "plug:dmix"<br />
}<br />
</pre><br />
<br />
And then restart with {{Codeline|/etc/rc.d/mpd restart}}.<br />
<br />
Searching on Internet I found the reason for why that happens in Gentoo's wiki:<br />
* The sound card does not support hardware mixing (uses '''dmix''' plugin)<br />
* An application does not work with ALSA with it's default settings<br />
<br />
For a detailed description, it is recommended to take a look at [http://mpd.wikia.com/wiki/Alsa this] link. There you can find an example asound.conf which worked for me right out of the box.<br />
<br />
====High CPU usage with ALSA====<br />
When using MPD with ALSA, users may experience MPD taking up lots of CPU (around 20-30%). This is caused by most sound cards supporting 48kHz and most music being 44kHz, thus forcing MPD to resample it. This operation takes lots of CPU cycles and results into high usage.<br />
<br />
For most users the problem should be solved by telling MPD not to use resampling by adding {{Codeline|auto_resample "no"}} into audio_output-part of {{Filename|/etc/mpd.conf}}. This will degrade quality slightly, however.<br />
<br />
Example from {{Filename|mpd.conf}}:<br />
<br />
audio_output {<br />
type "alsa"<br />
name "My ALSA Device"<br />
auto_resample "no"<br />
}<br />
<br />
Although it may not give as drastic a speedup, enabling mmap may speed things up:<br />
<br />
audio_output {<br />
type "alsa"<br />
name "My ALSA Device"<br />
use_mmap "yes"<br />
}<br />
<br />
Some users might also want to tell dmix to use 44kHz as well. More info about tuning performance of your MPD can be found from: [http://mpd.wikia.com/wiki/Tuning MPD wiki]<br />
<br />
====Example configuration: Output with 44.1 KHz at e. g. 16 bit depth, multiple programs at once====<br />
<br />
''Why these formats?'' Because they are standard CDA, because ALSA on its own allows more than one program "to sound" only with dmix — whose resampling algorithm is inferior — and because dmix by default resamples anything lower to 48 KHz (or whatever higher format is playing at the time). Also, some get clicking sounds if at least {{Filename|mpd.conf}} is not changed this way.<br />
<br />
''What's the downside?'' These settings cause ''everything'' (if necessary) to be resampled to this format, such as material from DVD or TV which usually is at 48 KHz. But there is no known way to have ALSA dynamically change the format, and particularly if you listen to far more CDs than anything else the occasional 48 → 44.1 isn't too great a loss.<br />
<br />
The following assumes that there are not already other settings which conflict resp. overwrite it. This applies especially to the current user's potential {{Filename|~/.asoundrc}} — which MPD as its own user ignores, therefore the following should go to {{Filename|/etc/asound.conf}}:<br />
<br />
{{File|name=/etc/asound.conf|content=<br />
defaults.pcm.dmix.rate 44100 # Force 44.1 KHz<br />
defaults.pcm.dmix.format S16_LE # Force 16 bits<br />
}}<br />
<br />
{{File|name=/etc/mpd.conf|content=<br />
audio_output {<br />
type "alsa" # Use the ALSA output plugin.<br />
name "HDA Intel" # Can be called anything or nothing tmk, but must be present.<br />
options "dev=dmixer"<br />
device "plug:dmix" # Both lines cause MPD to output to dmix.<br />
format "44100:16:2" # the actual format<br />
auto_resample "no" # This bypasses ALSA's own algorithms, which generally are inferior. See below how to choose a different one.<br />
use_mmap "yes" # Minor speed improvement, should work with all modern cards.<br />
}<br />
<br />
samplerate_converter "0" # MPD's best, most CPU intensive algorithm. See 'man mpd.conf' for others — for anything other than the poorest "internal", libsamplerate must be installed.<br />
}}<br />
<br />
{{Note|MPD gives the mp3 format a special treatment at decoding: It's always outputted as 24 bit. (The conversion as forced by the ''format'' line only comes after that.)}}<br />
<br />
If one wants to leave the bit depth decision to ALSA resp. MPD, comment out resp. omit the ''dmix.format'' line and change the one for mpd with ''format'' to "44100:*:2".<br />
<br />
{{Note|''Crossfading'' between files decoded at two different bit depths (say, one mp3 and one 16 bit flac) does not work unless conversion is active.}}<br />
<br />
===Control MPD with lirc===<br />
There are already some clients designed for communications between lircd and MPD, however, as far as the practical use, they aren't very useful since their functions are limited.<br />
<br />
It's recommended to use mpc with irexec. mpc is a command line player which only sends the command to MPD and exits immediately, which is perfect for irexec, the command runner included in lirc. What irexec does is that it runs a specified command once received a remote control button.<br />
<br />
First of all, please setup your remotes as referred to the '''[[Lirc]]''' article.<br />
<br />
Edit your favored lirc startup configuration file, default location is {{Filename|~/.lircrc}}.<br />
<br />
Fill the file with the following pattern:<br />
begin<br />
prog = irexec<br />
button = <button_name><br />
config = <command_to_run><br />
repeat = <0 or 1><br />
end<br />
<br />
An useful example:<br />
## irexec<br />
begin<br />
prog = irexec<br />
button = play_pause<br />
config = mpc toggle<br />
repeat = 0<br />
end<br />
<br />
begin<br />
prog = irexec<br />
button = stop<br />
config = mpc stop<br />
repeat = 0<br />
end<br />
begin<br />
prog = irexec<br />
button = previous<br />
config = mpc prev<br />
repeat = 0<br />
end<br />
begin<br />
prog = irexec<br />
button = next<br />
config = mpc next<br />
repeat = 0<br />
end<br />
begin<br />
prog = irexec<br />
button = volup<br />
config = mpc volume +2<br />
repeat = 1<br />
end<br />
begin<br />
prog = irexec<br />
button = voldown<br />
config = mpc volume -2<br />
repeat = 1<br />
end<br />
begin<br />
prog = irexec<br />
button = pbc<br />
config = mpc random<br />
repeat = 0<br />
end<br />
begin<br />
prog = irexec<br />
button = pdvd<br />
config = mpc update<br />
repeat = 0<br />
end<br />
begin<br />
prog = irexec<br />
button = right<br />
config = mpc seek +00:00:05<br />
repeat = 0<br />
end<br />
begin<br />
prog = irexec<br />
button = left<br />
config = mpc seek -00:00:05<br />
repeat = 0<br />
end<br />
begin<br />
prog = irexec<br />
button = up<br />
config = mpc seek +1%<br />
repeat = 0<br />
end<br />
begin<br />
prog = irexec<br />
button = down<br />
config = mpc seek -1%<br />
repeat = 0<br />
end<br />
<br />
There are more functions for mpc, run {{Codeline|man mpc}} for more info.<br />
<br />
===Control MPD with bluetooth phone===<br />
You can also control MPD (to a certain extent) using a bluetooth enabled phone. You need to do the following:<br />
<br />
* install [http://remuco.sourceforge.net/index.php/Remuco remuco] -- a wireless remote control for several Linux media players ([http://aur.archlinux.org/packages.php?ID=25072 aur])<br />
* transfer remuco client -- jar/jad files from {{Filename|/usr/share/remuco/client/}} to your phone and install it<br />
* run {{Codeline|remuco-mpd}} (as current user)<br />
* run remuco on your phone, define a new bluetooth remuco connection (pair first if you haven't done this previously) and explore its capabilities<br />
<br />
More information about remuco including troubleshooting to be found at its [http://remuco.sourceforge.net/index.php/Remuco homepage]<br />
<br />
===MPD & PulseAudio===<br />
<br />
Edit {{Filename|/etc/mpd.conf}}, and uncomment the audio_output section for the type "pulse". The server and sink lines of it should be commented unless you know what you're doing.<br />
<br />
Then, add the mpd user (and yours if you haven't done so already) to the necessary pulse groups. The pulse-access group should be sufficient but you may want to add pulse-rt as well. The group "pulse" doesn't appear to be necessary.<br />
# gpasswd -a mpd pulse-access<br />
# gpasswd -a mpd pulse-rt<br />
<br />
Lastly, you may or may not need to copy {{Filename|~/.pulse-cookie}} from your current (pulse working) user's dir to your mpd user's home directory. It is likely to be {{Filename|/var/lib/mpd}} if you followed the first part of this wiki. This would probably only allow your current user to listen in on MPD's pulse. You may consider running pulse system-wide if that's insufficient.<br />
<br />
===Cue Files===<br />
<br />
To make cue file support actually work, you have to work around a nasty libcue bug. Libcue copied some files directly from libcdio, making it conflict with it. Steps to do to get proper cue support:<br />
<br />
* remove libcdio temporary (pacman -Rdd libcdio)<br />
* install libcue (pacman -S libcue)<br />
* install mpd with abs or from aur.<br />
* reinstall libcdio (pacman -S libcdio)<br />
<br />
At the point of writing mpd does not parse tracknumbers from cue sheets. There is a patch available (http://musicpd.org/mantis/view.php?id=3230)<br />
Once this patch is merged into mpd, i will remove this line :)<br />
<br />
==Troubleshooting==<br />
===Autodetection failed===<br />
During the start of MPD, it tries to autodetect your set-up and configure output and volume control accordingly. Though this mostly goes well, it will fail for some systems. It may help to tell MPD specifically what to use as output and mixer control. If you copied {{Filename|/etc/mpd.conf}} over from {{Filename|/etc/mpd.conf.example}} as mentioned above, you can simply uncomment:<br />
<br />
Example for alsa output type and alsa mixer:<br />
audio_output {<br />
type "alsa"<br />
name "My ALSA Device"<br />
device "hw:0,0" # optional<br />
format "44100:16:2" # optional<br />
mixer_type "hardware"<br />
mixer_device "default"<br />
mixer_control "PCM"<br />
}<br />
<br />
'''Note:''' in case of permission problems when using ESD with MPD run this as root:<br />
# chsh -s /bin/true mpd<br />
<br />
===Executable permissions===<br />
{{Warning|This is not good security practice and may be unnecessary.}}<br />
<br />
MPD needs to have +x permissions on '''ALL''' parent directories to your music collection (ie. if it's located outside of "mpd" home directory /var/lib/mpd). By default useradd sets permissions on home dir to 1700 drwx------. So if you're like me you will need to change permissions of /home/user. Example... my music collection is located /home/user/music. <br />
# chmod a+x /home/$USER<br />
# chmod -R a+X /home/$USER/music<br />
<br />
====Alternative solution====<br />
An alternative solution would be to use your group to share a selection of files, among them your music library. First remove all permissions for the group then add group permissions to read and execute home and music.<br />
# chmod -R g-rwx /home/$USER<br />
# chmod g+rx /home/$USER<br />
# chmod -R g+rX /home/$USER/music<br />
<br />
====Another alternative solution====<br />
Another alternative is to remount the music directory under a directory that mpd has access to. This does not entail the same security risks as modifying the permissions on one's home directory.<br />
# mkdir /var/lib/mpd/music<br />
# echo "/home/$USER/music /var/lib/mpd/music none bind" >> /etc/fstab<br />
# mount -a<br />
# /etc/rc.d/mpd restart<br />
And that should fix the problem. See also [https://bbs.archlinux.org/viewtopic.php?id=86449 the forum thread.]<br />
<br />
===Avoiding timeouts===<br />
To get rid of timeouts (i.e. when you paused music for long time) in gpmc and other clients uncomment and increase {{Codeline|connection_timeout}} option in {{Filename|mpd.conf}}.<br />
<br />
If files and/or titles are shown in wrong encoding, uncomment and change {{Codeline|filesystem_charset}} and {{Codeline|id3v1_encoding}} options.<br />
Note that you cannot set encoding for ID3 v2 tags. To workaround this you may use [http://mpd.wikia.com/wiki/GenericDecoder#Generic_Tagreader external tag readers].<br />
<br />
If you want to use another computer to control MPD over a network, the {{Codeline|bind_to_address}} option in {{Filename|mpd.conf}} will need to be set to either your IP address, or {{Codeline|any}} if your IP address changes frequently. <br />
<br />
'''Streaming'''<br><br />
With the latest version of MPD (0.15), built-in httpd streaming is now available.<br />
<br />
To activate this feature, you'll just need to add a new output of type httpd in {{Filename|mpd.conf}}:<br />
audio_output {<br />
type "httpd"<br />
name "What you want"<br />
encoder "lame" # vorbis or lame supported<br />
port "8000"<br />
bitrate "128"<br />
format "44100:16:2" # change 2 to 1 for mono<br />
}<br />
<br />
Restart the mpd deamon and, from another computer, simply load the stream as any other url. <br />
$ mplayer http://<server's IP>:8000<br />
<br />
{{Note | You must open the port on your router / firewall for the stream to be connectible to from another computer.}}<br />
<br />
Most players (i.e. vlc or xmms2) should also be able to load the stream via their "add url..." menu option.<br />
<br />
This is a nice clean way to replace your current icecast setup with something natively supported within MPD.<br />
<br />
===mpd hangs on first startup===<br />
This is a common error that's caused by corrupt mp3 tags.<br />
Here is an experimental way to solve this issue.<br />
Requirements:<br />
* kid3<br />
* easytag<br />
<br />
This method is very tedious, especially with a huge database. Just as a baseline it took 2.5h to fix a 16Gb DB.<br />
<br />
====Easy Tag====<br />
The purpose of easytag here is that easytag detects the error in the tags, but like MPD it hangs and dies. The trick here is that easy tags actually tells you what file is causing the problem on the status bar.<br />
Before starting easytag make sure to have a terminal close to be ready to kill easy tag to avoid a hang. Once you are ready, on the tree view select the directory where all your music is located. By default easytag starts to search all subdirectories for mp3 files. Once you notice that easytag stopped scanning for songs, make note of the culprit and kill easytag.<br />
<br />
====KID3====<br />
Here's where kid3 comes in handy. With kid3 go to the offending song and rewrite one of the tags. then save the file. This should force kid3 to rewrite the whole tag again fixing the problem with MPD and easy tag hanging.<br />
<br />
Repeat this procedure until your music library is done.<br />
<br />
===Cannot connect to mpd: host "localhost" not found: Temporary failure in name resolution===<br />
Cannot connect to MPD (with ncmpcpp), if you are disconnected from network. Solution is [[IPv6 - Disabling the Module|disable IPv6]] or add line to /etc/hosts<br />
::1 localhost.localdomain localhost<br />
<br />
===Other issues when attempting to connect to mpd with a client===<br />
Some have reported being unable to access mpd with various clients, for example seeing errors like these:<br />
$ ncmpcpp<br />
Cannot connect to mpd: Connection closed by the server<br />
$ sonata<br />
2011-02-13 18:33:05 Connection lost while reading MPD hello<br />
2011-02-13 18:33:05 Not connected<br />
2011-02-13 18:33:05 Not connected<br />
<br />
Please see posts on ncmpcpp on the Arch Forums [https://bbs.archlinux.org/viewtopic.php?id=109962 HERE] and [https://bbs.archlinux.org/viewtopic.php?id=113493 HERE]. Also see the Arch bug report on this issue [https://bugs.archlinux.org/task/22071 HERE]. <br />
<br />
====First fix====<br />
Check {{Filename|mpd.conf}} for a line like {{Codeline|mpd.error}} and remove it. The mpd error file is deprecated and has been removed.<br />
<br />
====Second fix====<br />
{{Note|I'm not so sure this is a good idea. There is a warning about changing the address to bind to in the default mpd.conf. If this does not help, you might want to comment out the changes.}}<br />
If that doesn't help, add the following to {{Filename|mpd.conf}}:<br />
<pre><br />
bind_to_address "127.0.0.1"<br />
port "6600"<br />
</pre><br />
<br />
Afterwards, instruct your client to connect via 127.0.0.1. For example, add the following to the ncmpcpp config file:<br />
<pre><br />
mpd_host "127.0.0.1"<br />
mpd_port "6600"<br />
</pre><br />
<br />
<br />
===Port 6600 already in use===<br />
MPD needs to bind to port 6600 and cannot start if it's already in use. The most common reason for this is that the user has started MPD once and then subsequently tried to start mpd again. In general, nothing should be done here.<br />
<br />
If port 6600 is tied up for some other reason, one can use the following command to find the offending process:<br />
# netstat -tulpan | grep 6600<br />
<br />
This will list IP:Port and the process name holding the connection (root privileges are required to see all processes).<br />
<br />
If you need to restart mpd for whatever reason, use:<br />
<pre><br />
$ mpd --kill<br />
$ mpd <br />
</pre><br />
A more brute-force approach:<br />
<pre><br />
$ killall mpd<br />
$ mpd <br />
</pre><br />
{{Note| If you typically run MPD as root, you will need to run the above commands as root.}}<br />
<br />
In the latest version of MPD, --create-db is completely deprecated. The database will be created automagically on first run and can subsequently be updated via your client (i.e. mpc update). You can now use inotify support to automatically update your music database. Add the following to {{File|name=mpd.conf|content=auto_update "yes"}} to enable it.<br />
<br />
===Binding to IPV6 before IPV4===<br />
If on startup, you see this message:<br />
listen: bind to '0.0.0.0:6600' failed: Address already in use (continuing anyway, because binding to '[::]:6600' succeeded)<br />
MPD is attempting to bind to the ipv6 interface before binding to ipv4. If you want to use your ipv4 interface, hardcode it in mpd.conf, like so:<br />
bind_to_address "127.0.0.1"<br />
Or, you could specify several binds, for example, to have MPD listen on localhost and the external IP of your network card:<br />
bind_to_address "127.0.0.1"<br />
bind_to_address "192.168.1.13"<br />
<br />
===Crackling sound with some audio files===<br />
This is usually a playback speed problem and can be fixed by uncommenting the audio_output_format line in:<br />
<br />
{{File|name=/etc/mpd.conf|content=<br />
audio_output_format "44100:16:2"}}<br />
<br />
This is usually a sane value for most mp3 files.<br />
<br />
===daemon: cannot setgid for user "mpd": Operation not permitted ===<br />
<br />
The error is stating that the user starting the process (you) does not have permissions to become another user (mpd) which the configuration has told that process to run as.<br />
<br />
To solve the issue, simply start mpd as root.<br />
su -c "/etc/rc.d/mpd start"<br />
or<br />
sudo /etc/rc.d/mpd start<br />
<br />
==External links==<br />
* [http://www.musicpd.org/ Official Web Site]<br />
* [http://mpd.wikia.com/wiki/Main_Page Official Wiki]<br />
* [http://mpd.wikia.com/wiki/Clients Sorted List of MPD Clients]<br />
* [http://www.musicpd.org/forum/ MPD forum]</div>Rasihttps://wiki.archlinux.org/index.php?title=Music_Player_Daemon&diff=150477Music Player Daemon2011-08-02T00:45:41Z<p>Rasi: /* Even quicker setup */</p>
<hr />
<div>[[fr:MPD]]<br />
[[Category:Audio/Video (English)]]<br />
[[Category:Daemons and system services (English)]]<br />
{{i18n|Music Player Daemon}}<br />
[[pl:Music Player Daemon]]<br />
<br />
'''MPD''' (music player daemon) is an audio player that has a server-client architecture. MPD runs in the background as a daemon, manages playlists and a music database, and uses very few resources. In order to interface with it, you need a separate client. More information can be found on their [http://www.musicpd.org/ website].<br />
<br />
''Please'' have a look at the official page for setup and troubleshooting instructions, the main developer called our wiki page in its current state ''"full of symptom killers"'', hence the official pages should contain better instructions.<br />
<br />
==Installing mpd==<br />
Install with [[pacman]]:<br />
# pacman -S mpd<br />
<br />
==Daemon Setup: Starting at Boot==<br />
General information about MPD configuration may be found at http://mpd.wikia.com/wiki/Configuration.<br />
<br />
===Sound setup===<br />
To make audio output actually work ensure that you have setup audio card and mixer correctly. See [[ALSA]], and [[PulseAudio]] if you are using Gnome 3. Do not forget to unmute the required channels in alsamixer, raise the volume and save changes with alsactl store. Run mpd with {{Filename|/usr/bin/mpd --stdout --no-daemon --verbose}} if that still doesn't work.<br />
<br />
Make sure your card can do hardware mixing (most of them can, including onboard audio). Or else this could cause problems with multiple sound playback. For example, this can prevent Mplayer from playing back sound while the mpd daemon is running, returning an audio error message stating the device is busy.<br />
<br />
===Timeline of MPD's behavior on a typical working setup when started as a daemon===<br />
# MPD is started on boot by {{Filename|/etc/rc.conf}}, by including it in the {{Codeline|DAEMONS}} array. (Or, this can be done manually each session by running {{Codeline|/etc/rc.d/mpd start}} with root privileges).<br />
# Since MPD is now started as root, it first reads the {{Filename|/etc/mpd.conf}} file.<br />
# MPD reads the user variable in the {{Filename|/etc/mpd.conf}} file, and changes from root to this user.<br />
# MPD then reads the contents of the {{Filename|/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 {{Filename|/etc/mpd.conf}} file. This way, uses of {{Codeline|~}} in the configuration file point correctly to the home user's directory, and not root's directory. It may be worthwhile to change all uses of {{Codeline|~}} to {{Codeline|/home/username}} to avoid any confusion over this aspect of MPD's behavior.<br />
<br />
===A clean configuration file===<br />
* As root, check if {{Filename|/etc/mpd.conf}} exists and delete the file if it does. This is safe.<br />
<br />
MPD comes with an example configuration file, available at {{Filename|/usr/share/mpd/mpd.conf.example}}. This file holds an abundance of information on MPD configuration, and holds default mixer values you can simply uncomment.<br />
<br />
* As root, copy this example file to {{Filename|/etc/mpd.conf}}.<br />
# cp /usr/share/mpd/mpd.conf.example /etc/mpd.conf<br />
({{Filename|/usr/share/mpd/mpd.conf.example}} is good for userspace setup)<br />
<br />
Since MPD is being set up to run as a daemon at boot, never put this file in the user's directory like some tutorials suggest, since it will not be read. Moreover, if you previously created a {{Filename|.mpdconf}} file in your home, remove it now (to set up MPD to run with user privileges alone, pleaser refer to the section [[Music_Player_Daemon#Alternative_Setup:_Starting_as_a_User | Alternative_Setup:_Starting_as_a_User]]). This is important to prevent conflicts. The presence of the configuration file in {{Filename|/etc}}, like is the case here, is what will enable MPD to run as a daemon at boot. Otherwise, a script would be needed to run MPD ''after'' the user has logged (like kdm or {{Filename|~/.fluxbox/startup}}) or it would require a manual move each time. For a single music collection, the method used here is simply better, even while the collection is shared to multiple users. Also, don't be afraid about root privileges: even while MPD runs as a daemon, it never completely runs as root since it automatically drops its root privileges after execution.<br />
<br />
===Edit {{Filename|mpd.conf}}===<br />
<br />
The default arch install keeps the setup in /var and uses "mpd" as default user, instead of cluttering up ~/.<br />
Edit {{Filename|/etc/mpd.conf}} to reflect as such.<br />
<br />
{{File|name=/etc/mpd.conf|content=<br />
music_directory "/home/user/music" # Your music dir.<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 "/var/run/mpd/mpd.pid"<br />
state_file "/var/lib/mpd/mpdstate"<br />
user "mpd"<br />
# Binding to address and port causing problems in mpd-0.14.2 best to leave<br />
# commented.<br />
# bind_to_address "127.0.0.1"<br />
# port "6600"<br />
}}<br />
<br />
* If your music collection is contained under multiple directories, you can make symbolic links under /var/lib/mpd then set 'music_directory' to the directory holding the symbolic links. Remember to set permissions accordingly on the directories being linked.<br />
<br />
* To change the volume of audio from mpd independent of other programs, uncomment or add the switch in mpd.conf:<br />
<br />
{{File|name=/etc/mpd.conf|content=<br />
mixer_type "software"<br />
}}<br />
<br />
* Lastly, if you are running pulseaudio under Gnome 3, the default setting of "alsa" for the audio output will not work. Make the modification from:<br />
{{File|name=/etc/mpd.conf|content=<br />
audio_output {<br />
type "alsa"<br />
name "Sound Card"<br />
}<br />
}}<br />
<br />
to<br />
<br />
{{File|name=/etc/mpd.conf|content=<br />
audio_output {<br />
type "pulse"<br />
name "Sound Card"<br />
}<br />
}}<br />
<br />
<br />
===Create files===<br />
<br />
* As root, create the directories and files you specified in {{Filename|/etc/mpd.conf}}.<br />
# mkdir -p /var/lib/mpd/playlists /var/run/mpd<br />
# touch /var/lib/mpd/{mpd.db,mpdstate} && touch /var/run/mpd/mpd.pid<br />
<br />
* You then need to change the file's permissions so that the daemon can modify them.<br />
# chown -R mpd /var/lib/mpd /var/run/mpd<br />
<br />
===Create database===<br />
<br />
Creating the database is now accomplished via the update feature of the client, for example 'mpc update'. The previous method, creating the MPD database as root (# mpd --create-db), is deprecated.<br />
<br />
==Alternative Setup: Starting as a User==<br />
MPD need not be started with root permissions. The only reason why MPD needs to be started as root (by being called from {{Filename|/etc/rc.conf}}) is because the default files and folders in the default configuration file points to directories owned by root (the /var directory). A less common, but perhaps more sensible, approach is to make MPD work with files and directories owned by a normal user. Running MPD as a normal user has several advantages: <br />
# You can easily have a single directory ~/.mpd (or any other directory under /home/username) for all MPD configuration files<br />
# No read/write permission errors<br />
# More flexible calls to MPD by using {{Filename|~/.xinitrc}} instead of including 'mpd' in the {{Filename|/etc/rc.conf}} DAEMONS array.<br />
<br />
The following steps shows how to run MPD as a normal user. '''Note''': this approach will not work if you want multiple users to have access to MPD.<br />
<br />
* Copy the contents of the default MPD configuration file in {{Filename|/usr/share/mpd/mpd.conf.example}} to your home directory. A good place would be {{Filename|"/home/user/.mpd/mpd.conf"}}.<br />
* Follow the 'old setup instructions' from above, ignoring the first part about copying the config to {{Filename|/etc/mpd.conf}} and do not set a user variable. <br />
* Create all of the requisite files in {{filename|"/home/user/.mpd/"}}:<br />
"~/.mpd/playlists/"<br />
"~/.mpd/db"<br />
"~/.mpd/mpd.db"<br />
"~/.mpd/mpd.log"<br />
"~/.mpd/mpd.error"<br />
"~/.mpd/mpd.pid"<br />
"~/.mpd/mpdstate"<br />
<br />
* Let MPD start on bootup by calling it from your {{Filename|~/.xinitrc}} as follows:<br />
# this starts mpd as normal user<br />
mpd ~/.mpd/mpd.conf<br />
{{Note| that you don't have to put a "&" at the end of the line here, since MPD will automatically daemonize itself.}}<br />
<br />
Lastly, delete the entry 'mpd' from your DAEMONS array in {{Filename|/etc/rc.conf}}, as you are not running it as root anymore.<br />
<br />
===Quick setup===<br />
<br />
The fastest way to do set up the structure is to do this:<br />
<br />
$ mkdir -p ~/.mpd/playlists && touch ~/.mpd/database && cp /usr/share/doc/mpd/mpdconf.example ~/.mpd/mpd.conf<br />
<br />
Then edit mpd.conf to your liking, in a manner similar to [[Music_Player_Daemon#Edit_mpd.conf]]. Beware that you must uncomment the db_file entry if you do edit mpd.conf.<br />
<br />
Then, to run it:<br />
<br />
$ mpd ~/.mpd/mpd.conf<br />
<br />
<br />
===Even quicker setup===<br />
I created a little script that will only ask for the location of your music and then creates the needed files and folders for you.<br />
You can find the script here:<br />
[http://karif.server-speed.net/~carnager/mpdsetup.tar]<br />
extract it<br />
$ tar xf mpdsetup.tar<br />
and run it<br />
$ ./mpdsetup.sh<br />
<br />
===Multi-mpd setup===<br />
'''Useful if you want to run for example an icecast server.'''<br />
If you want a second MPD daemon (e.g., with icecast output to share music over the network) to use the same music and playlist as the one above, simply copy the above configuration file and make a new file (e.g., {{Filename|/home/username/.mpd/config-icecast}}), and only change the log_file, error_file, pid_file, and state_file parameters (e.g., {{Filename|mpd-icecast.log}}, {{Filename|mpd-icecast.error}}, and so on); using the same directory paths for the music and playlist directories would ensure that this second mpd daemon would use the same music collection as your first one (e.g., creating and editing a playlist under the first daemon would affect the second daemon as well, so that you don't have to create the same playlists all over again for the second daemon). Then, call this second daemon the same way from your {{Filename|~/.xinitrc}} above. (Just be sure to have a different port number, so as to not conflict with your first mpd daemon).<br />
<br />
==Clients==<br />
Install a client program for MPD. Popular options are:<br />
<br />
===Console===<br />
* '''mpc''' &ndash; Command Line Client (you'll probably want this one no matter what)<br />
# pacman -S mpc<br />
* [http://mpd.wikia.com/wiki/Client:Ncmpc/ ncmpc] &ndash; NCurses Client (this one is very handy for running in a console)<br />
# pacman -S ncmpc<br />
* [http://unkart.ovh.org/ncmpcpp/ ncmpcpp] &ndash; Clone of ncmpc with some new features written in C++<br />
# pacman -S ncmpcpp<br />
* [http://pms.sourceforge.net/ pms] &ndash; NCurses Client (highly configurable and accessible)<br />
Install [http://aur.archlinux.org/packages.php?ID=24378 pmus] from the [[AUR]].<br />
<br />
===Graphical===<br />
* [http://ario-player.sourceforge.net ario] &ndash; GTK+ Client with a Rhythmbox like library browser<br />
# pacman -S ario<br />
* [http://gmpcwiki.sarine.nl/index.php?title=GMPC gmpc] &ndash; GNOME Client<br />
# pacman -S gmpc<br />
* [http://bitcheese.net/wiki/QMPDClient QMPDClient] &ndash; Client written with Qt 4.x.<br />
# pacman -S qmpdclient<br />
* [http://sonata.berlios.de/ sonata] &ndash; Python GTK+ Client<br />
# pacman -S sonata<br />
* [http://aur.archlinux.org/packages.php?ID=33380 dmpc] &ndash; Dmenu-based MPC client with a playlist manager and state-saving on playlist changes<br />
Install [http://aur.archlinux.org/packages.php?ID=33380 dmpc] from the [[AUR]].<br />
<br />
See a long list of clients at the [http://mpd.wikia.com/wiki/Clients mpd wiki].<br />
<br />
==Extra stuff==<br />
===Last.fm scrobbling===<br />
To scrobble your songs to [http://www.last.fm Last.fm] using MPD there are several alternatives.<br />
<br />
====mpdscribble====<br />
mpdscribble is another daemon, available in the "community" repository (if you prefer, the "git" version is available in the [http://aur.archlinux.org/packages.php?ID=22274 AUR]). This is arguably the best alternative, because it's the semi-official MPD scrobbler and uses the new "idle" feature in MPD for more accurate scrobbling. Also, you don't need root access to configure it, because it doesn't need any changes to <tt>/etc</tt> at all. Visit [http://mpd.wikia.com/wiki/Client:Mpdscribble the official website] for more information.<br />
<br />
After you have installed mpdscribble, do the following (not as root):<br />
<br />
* {{Codeline|$ mkdir ~/.mpdscribble}}<br />
* Create the file {{Filename|~/.mpdscribble/mpdscribble.conf}} and add the following:<br />
<pre><br />
[mpdscribble] <br />
host = <your mpd host> # optional, defaults to $MPD_HOST or localhost<br />
port = <your mpd port> # optional, defaults to $MPD_PORT or 6600<br />
log = /home/<YOUR_USERNAME>/.mpdscribble/mpdscribble.log<br />
verbose = 2<br />
sleep = 1<br />
musicdir = <your music directory><br />
proxy = <your proxy> # optional, e. g. http://your.proxy:8080, defaults to none<br />
<br />
[last.fm]<br />
# last.fm section, comment if you don't use last.fm<br />
url = http://post.audioscrobbler.com/<br />
username = <your last.fm username><br />
password = <your last.fm password> # md5sum also possible: echo -n 'PASSWORD' | md5sum | cut -f 1 -d " "<br />
journal = /home/<YOUR_USERNAME>/.mpdscribble/lastfm.journal<br />
<br />
[libre.fm]<br />
# libre.fm section, comment if you don't use libre.fm<br />
url = http://turtle.libre.fm/<br />
username = <your libre.fm username><br />
password = <your libre.fm password> # md5sum also possible: echo -n 'PASSWORD' | md5sum | cut -f 1 -d " "<br />
journal = /home/<YOUR_USERNAME>/.mpdscribble/librefm.journal<br />
</pre><br />
* Add {{Codeline|mpdscribble}} to your {{Filename|~/.xinitrc}}:<br />
pidof mpdscribble >& /dev/null<br />
if [ $? -ne 0 ]; then<br />
mpdscribble &<br />
fi<br />
<br />
====Sonata & Ario====<br />
The easiest way, if you don't care about having to have a program window open all the time, is using Sonata or Ario which are graphical frontends to MPD. They have built-in support for Last.fm scrobbling in their preferences. A downside of this is that Sonata doesn't cache your songs if for some reason you don't happen to have an Internet connection at the time of playing.<br />
<br />
====lastfmsubmitd====<br />
lastfmsubmitd is a daemon which is available in the "community" repository. To install it, first edit {{Filename|/etc/lastfmsubmitd.conf}} and add both {{Codeline|lastfmsubmitd}} and {{Codeline|lastmp}} to the {{Codeline|DAEMONS}} array in {{Filename|/etc/rc.conf}}.<br />
<br />
===Last.fm playback with lastfmproxy===<br />
lastfmproxy is a python script that streams a last.fm music stream to another media player. To setup, install [http://aur.archlinux.org/packages.php?ID=14214 lastfmproxy] from the [[AUR]] and then edit {{Filename|/usr/share/lastfmproxy/config.py}}. If you plan to only stream to MPD on the same host, just edit the login info.<br />
<br />
{{Note | Since it installs to a read only directory but it requires read/write access for features like saving previously listened to stations, it would be wise to copy {{Filename|/usr/share/lastfmproxy}} to your home directory.}}<br />
<br />
Start lastfmproxy with {{Codeline|lastfmproxy}} and visit http://localhost:1881/ in your web browser. To add a last.fm station navigate to http://localhost:1881/ followed by the lastfm:// url. Example: http://localhost:1881/lastfm://globaltags/punk . Navigate back to http://localhost:1881/ and download the m3u file by selecting the ''Start Listening'' link. Simply add it to your music library path.<br />
<br />
===Never play on start===<br />
<br />
This feature has recently been added to mpd git by Martin Kellerman, see commits b57330cf75bcb339e3f268f1019c63e40d305145 and 2fb40fe728ac07574808c40034fc0f3d2254d49d.<br />
<br />
====[https://aur.archlinux.org/packages.php?ID=19676 mpd-git] Method====<br />
This is the best method currently available, but is only currently (April 2011) enabled in the git version. Install [https://aur.archlinux.org/packages.php?ID=19676 mpd-git] from the [[AUR]], then add {{Codeline|restore_paused "yes"}} to your {{Filename|mpd.conf}} file.<br />
<br />
If you have issues with connecting your client to [https://aur.archlinux.org/packages.php?ID=19676 mpd-git], see [[Music Player Daemon#Other issues when attempting to connect to mpd with a client]].<br />
<br />
====Method 1====<br />
If you don't want MPD to always play on your system start, but yet you want to preserve the other state information, add the following lines to your {{Filename|/etc/rc.d/mpd}} file:<br />
'' ...''<br />
'' stat_busy "Starting Music Player Daemon"''<br />
<br />
# always start in paused state<br />
awk '/^state_file[ \t]+"[^"]+"$/ {<br />
match($0, "\".+\"")<br />
sfile = substr($0, RSTART + 1, RLENGTH - 2)<br />
} /^user[ \t]+"[^"]+"$/ {<br />
match($0, "\".+\"")<br />
user = substr($0, RSTART + 1, RLENGTH - 2)<br />
} END {<br />
if (sfile == "")<br />
exit;<br />
if (user != "")<br />
sub(/^~/, "/home/" user, sfile)<br />
system("sed -i \x27s|^\\(state:[ \\t]\\{1,\\}\\)play$|\\1pause|\x27 \x27" sfile "\x27")<br />
}' /etc/mpd.conf<br />
<br />
'' /usr/bin/mpd /etc/mpd.conf &> /dev/null''<br />
'' ...''<br />
<br />
This will change the player status to "paused", if it was stopped while playing. Next, you want this file to be preserved, so MPD updates won't erase this edit. Add (or edit) this line to your {{Filename|/etc/pacman.conf}}:<br />
NoUpgrade = etc/rc.d/mpd<br />
<br />
====Method 2====<br />
<br />
Another simpler method, would be to add mpd to your {{Filename|[[rc.conf]]}} deamons array and add {{Codeline|mpc stop}} or {{Codeline|mpc pause}} to {{Filename|/etc/rc.local.shutdown}} and to {{Filename|/etc/rc.local}}. (Remember you must have mpc installed to use this method).<br />
<br />
Adding only the order in {{Filename|/etc/rc.local}} cannot assure that mpd will play absolutely nothing, since there may be a delay before the stop command is executed. <br />
On the other hand, if you only add the order to {{Filename|/etc/rc.local.shutdown}}, that will assure that mpd won't play at all, as long as you properly shutdown your system.<br />
Even though they are redundant, adding it to {{Filename|/etc/rc.local}} would serve as a safety for those, presumably, rare occasions when you do not shutdown the system properly.<br />
<br />
====Method 3====<br />
<br />
The general idea between this method is to ask mdp to pause music when user logs out so that during next restart, mdp will stick to that "pause" state. Sending such command can be achieve using [http://www.archlinux.org/packages/extra/x86_64/mpc/ mpc], the command line interface to MPD:<br />
pacman -S mpc<br />
<br />
GDM users can then add the next line to /etc/gdm/PostSession/Default (be sure to add it before "exit 0"):<br />
/usr/bin/mpc pause<br />
<br />
Non-GDM users can use their own login manager's method to launch the line at logout.<br />
<br />
===MPD & ALSA===<br />
Sometimes, when you use other audio output, e.g: some web pages containing Flash applets, MPD cannot reproduce anything anymore (until you restart). The error looks something like: (if you search the file {{Filename|/var/log/mpd/mpd.error}})<br />
<br />
Error opening alsa device "hw:0,0": Device or resource busy<br />
<br />
And here is the solution (dmix saving our life again). Apply these lines in your {{Filename|/etc/mpd.conf}}:<br />
<br />
<pre><br />
audio_output {<br />
type "alsa"<br />
name "Sound Card"<br />
options "dev=dmixer"<br />
device "plug:dmix"<br />
}<br />
</pre><br />
<br />
And then restart with {{Codeline|/etc/rc.d/mpd restart}}.<br />
<br />
Searching on Internet I found the reason for why that happens in Gentoo's wiki:<br />
* The sound card does not support hardware mixing (uses '''dmix''' plugin)<br />
* An application does not work with ALSA with it's default settings<br />
<br />
For a detailed description, it is recommended to take a look at [http://mpd.wikia.com/wiki/Alsa this] link. There you can find an example asound.conf which worked for me right out of the box.<br />
<br />
====High CPU usage with ALSA====<br />
When using MPD with ALSA, users may experience MPD taking up lots of CPU (around 20-30%). This is caused by most sound cards supporting 48kHz and most music being 44kHz, thus forcing MPD to resample it. This operation takes lots of CPU cycles and results into high usage.<br />
<br />
For most users the problem should be solved by telling MPD not to use resampling by adding {{Codeline|auto_resample "no"}} into audio_output-part of {{Filename|/etc/mpd.conf}}. This will degrade quality slightly, however.<br />
<br />
Example from {{Filename|mpd.conf}}:<br />
<br />
audio_output {<br />
type "alsa"<br />
name "My ALSA Device"<br />
auto_resample "no"<br />
}<br />
<br />
Although it may not give as drastic a speedup, enabling mmap may speed things up:<br />
<br />
audio_output {<br />
type "alsa"<br />
name "My ALSA Device"<br />
use_mmap "yes"<br />
}<br />
<br />
Some users might also want to tell dmix to use 44kHz as well. More info about tuning performance of your MPD can be found from: [http://mpd.wikia.com/wiki/Tuning MPD wiki]<br />
<br />
====Example configuration: Output with 44.1 KHz at e. g. 16 bit depth, multiple programs at once====<br />
<br />
''Why these formats?'' Because they are standard CDA, because ALSA on its own allows more than one program "to sound" only with dmix — whose resampling algorithm is inferior — and because dmix by default resamples anything lower to 48 KHz (or whatever higher format is playing at the time). Also, some get clicking sounds if at least {{Filename|mpd.conf}} is not changed this way.<br />
<br />
''What's the downside?'' These settings cause ''everything'' (if necessary) to be resampled to this format, such as material from DVD or TV which usually is at 48 KHz. But there is no known way to have ALSA dynamically change the format, and particularly if you listen to far more CDs than anything else the occasional 48 → 44.1 isn't too great a loss.<br />
<br />
The following assumes that there are not already other settings which conflict resp. overwrite it. This applies especially to the current user's potential {{Filename|~/.asoundrc}} — which MPD as its own user ignores, therefore the following should go to {{Filename|/etc/asound.conf}}:<br />
<br />
{{File|name=/etc/asound.conf|content=<br />
defaults.pcm.dmix.rate 44100 # Force 44.1 KHz<br />
defaults.pcm.dmix.format S16_LE # Force 16 bits<br />
}}<br />
<br />
{{File|name=/etc/mpd.conf|content=<br />
audio_output {<br />
type "alsa" # Use the ALSA output plugin.<br />
name "HDA Intel" # Can be called anything or nothing tmk, but must be present.<br />
options "dev=dmixer"<br />
device "plug:dmix" # Both lines cause MPD to output to dmix.<br />
format "44100:16:2" # the actual format<br />
auto_resample "no" # This bypasses ALSA's own algorithms, which generally are inferior. See below how to choose a different one.<br />
use_mmap "yes" # Minor speed improvement, should work with all modern cards.<br />
}<br />
<br />
samplerate_converter "0" # MPD's best, most CPU intensive algorithm. See 'man mpd.conf' for others — for anything other than the poorest "internal", libsamplerate must be installed.<br />
}}<br />
<br />
{{Note|MPD gives the mp3 format a special treatment at decoding: It's always outputted as 24 bit. (The conversion as forced by the ''format'' line only comes after that.)}}<br />
<br />
If one wants to leave the bit depth decision to ALSA resp. MPD, comment out resp. omit the ''dmix.format'' line and change the one for mpd with ''format'' to "44100:*:2".<br />
<br />
{{Note|''Crossfading'' between files decoded at two different bit depths (say, one mp3 and one 16 bit flac) does not work unless conversion is active.}}<br />
<br />
===Control MPD with lirc===<br />
There are already some clients designed for communications between lircd and MPD, however, as far as the practical use, they aren't very useful since their functions are limited.<br />
<br />
It's recommended to use mpc with irexec. mpc is a command line player which only sends the command to MPD and exits immediately, which is perfect for irexec, the command runner included in lirc. What irexec does is that it runs a specified command once received a remote control button.<br />
<br />
First of all, please setup your remotes as referred to the '''[[Lirc]]''' article.<br />
<br />
Edit your favored lirc startup configuration file, default location is {{Filename|~/.lircrc}}.<br />
<br />
Fill the file with the following pattern:<br />
begin<br />
prog = irexec<br />
button = <button_name><br />
config = <command_to_run><br />
repeat = <0 or 1><br />
end<br />
<br />
An useful example:<br />
## irexec<br />
begin<br />
prog = irexec<br />
button = play_pause<br />
config = mpc toggle<br />
repeat = 0<br />
end<br />
<br />
begin<br />
prog = irexec<br />
button = stop<br />
config = mpc stop<br />
repeat = 0<br />
end<br />
begin<br />
prog = irexec<br />
button = previous<br />
config = mpc prev<br />
repeat = 0<br />
end<br />
begin<br />
prog = irexec<br />
button = next<br />
config = mpc next<br />
repeat = 0<br />
end<br />
begin<br />
prog = irexec<br />
button = volup<br />
config = mpc volume +2<br />
repeat = 1<br />
end<br />
begin<br />
prog = irexec<br />
button = voldown<br />
config = mpc volume -2<br />
repeat = 1<br />
end<br />
begin<br />
prog = irexec<br />
button = pbc<br />
config = mpc random<br />
repeat = 0<br />
end<br />
begin<br />
prog = irexec<br />
button = pdvd<br />
config = mpc update<br />
repeat = 0<br />
end<br />
begin<br />
prog = irexec<br />
button = right<br />
config = mpc seek +00:00:05<br />
repeat = 0<br />
end<br />
begin<br />
prog = irexec<br />
button = left<br />
config = mpc seek -00:00:05<br />
repeat = 0<br />
end<br />
begin<br />
prog = irexec<br />
button = up<br />
config = mpc seek +1%<br />
repeat = 0<br />
end<br />
begin<br />
prog = irexec<br />
button = down<br />
config = mpc seek -1%<br />
repeat = 0<br />
end<br />
<br />
There are more functions for mpc, run {{Codeline|man mpc}} for more info.<br />
<br />
===Control MPD with bluetooth phone===<br />
You can also control MPD (to a certain extent) using a bluetooth enabled phone. You need to do the following:<br />
<br />
* install [http://remuco.sourceforge.net/index.php/Remuco remuco] -- a wireless remote control for several Linux media players ([http://aur.archlinux.org/packages.php?ID=25072 aur])<br />
* transfer remuco client -- jar/jad files from {{Filename|/usr/share/remuco/client/}} to your phone and install it<br />
* run {{Codeline|remuco-mpd}} (as current user)<br />
* run remuco on your phone, define a new bluetooth remuco connection (pair first if you haven't done this previously) and explore its capabilities<br />
<br />
More information about remuco including troubleshooting to be found at its [http://remuco.sourceforge.net/index.php/Remuco homepage]<br />
<br />
===MPD & PulseAudio===<br />
<br />
Edit {{Filename|/etc/mpd.conf}}, and uncomment the audio_output section for the type "pulse". The server and sink lines of it should be commented unless you know what you're doing.<br />
<br />
Then, add the mpd user (and yours if you haven't done so already) to the necessary pulse groups. The pulse-access group should be sufficient but you may want to add pulse-rt as well. The group "pulse" doesn't appear to be necessary.<br />
# gpasswd -a mpd pulse-access<br />
# gpasswd -a mpd pulse-rt<br />
<br />
Lastly, you may or may not need to copy {{Filename|~/.pulse-cookie}} from your current (pulse working) user's dir to your mpd user's home directory. It is likely to be {{Filename|/var/lib/mpd}} if you followed the first part of this wiki. This would probably only allow your current user to listen in on MPD's pulse. You may consider running pulse system-wide if that's insufficient.<br />
<br />
===Cue Files===<br />
<br />
To make cue file support actually work, you have to work around a nasty libcue bug. Libcue copied some files directly from libcdio, making it conflict with it. Steps to do to get proper cue support:<br />
<br />
* remove libcdio temporary (pacman -Rdd libcdio)<br />
* install libcue (pacman -S libcue)<br />
* install mpd with abs or from aur.<br />
* reinstall libcdio (pacman -S libcdio)<br />
<br />
At the point of writing mpd does not parse tracknumbers from cue sheets. There is a patch available (http://musicpd.org/mantis/view.php?id=3230)<br />
Once this patch is merged into mpd, i will remove this line :)<br />
<br />
==Troubleshooting==<br />
===Autodetection failed===<br />
During the start of MPD, it tries to autodetect your set-up and configure output and volume control accordingly. Though this mostly goes well, it will fail for some systems. It may help to tell MPD specifically what to use as output and mixer control. If you copied {{Filename|/etc/mpd.conf}} over from {{Filename|/etc/mpd.conf.example}} as mentioned above, you can simply uncomment:<br />
<br />
Example for alsa output type and alsa mixer:<br />
audio_output {<br />
type "alsa"<br />
name "My ALSA Device"<br />
device "hw:0,0" # optional<br />
format "44100:16:2" # optional<br />
mixer_type "hardware"<br />
mixer_device "default"<br />
mixer_control "PCM"<br />
}<br />
<br />
'''Note:''' in case of permission problems when using ESD with MPD run this as root:<br />
# chsh -s /bin/true mpd<br />
<br />
===Executable permissions===<br />
{{Warning|This is not good security practice and may be unnecessary.}}<br />
<br />
MPD needs to have +x permissions on '''ALL''' parent directories to your music collection (ie. if it's located outside of "mpd" home directory /var/lib/mpd). By default useradd sets permissions on home dir to 1700 drwx------. So if you're like me you will need to change permissions of /home/user. Example... my music collection is located /home/user/music. <br />
# chmod a+x /home/$USER<br />
# chmod -R a+X /home/$USER/music<br />
<br />
====Alternative solution====<br />
An alternative solution would be to use your group to share a selection of files, among them your music library. First remove all permissions for the group then add group permissions to read and execute home and music.<br />
# chmod -R g-rwx /home/$USER<br />
# chmod g+rx /home/$USER<br />
# chmod -R g+rX /home/$USER/music<br />
<br />
====Another alternative solution====<br />
Another alternative is to remount the music directory under a directory that mpd has access to. This does not entail the same security risks as modifying the permissions on one's home directory.<br />
# mkdir /var/lib/mpd/music<br />
# echo "/home/$USER/music /var/lib/mpd/music none bind" >> /etc/fstab<br />
# mount -a<br />
# /etc/rc.d/mpd restart<br />
And that should fix the problem. See also [https://bbs.archlinux.org/viewtopic.php?id=86449 the forum thread.]<br />
<br />
===Avoiding timeouts===<br />
To get rid of timeouts (i.e. when you paused music for long time) in gpmc and other clients uncomment and increase {{Codeline|connection_timeout}} option in {{Filename|mpd.conf}}.<br />
<br />
If files and/or titles are shown in wrong encoding, uncomment and change {{Codeline|filesystem_charset}} and {{Codeline|id3v1_encoding}} options.<br />
Note that you cannot set encoding for ID3 v2 tags. To workaround this you may use [http://mpd.wikia.com/wiki/GenericDecoder#Generic_Tagreader external tag readers].<br />
<br />
If you want to use another computer to control MPD over a network, the {{Codeline|bind_to_address}} option in {{Filename|mpd.conf}} will need to be set to either your IP address, or {{Codeline|any}} if your IP address changes frequently. <br />
<br />
'''Streaming'''<br><br />
With the latest version of MPD (0.15), built-in httpd streaming is now available.<br />
<br />
To activate this feature, you'll just need to add a new output of type httpd in {{Filename|mpd.conf}}:<br />
audio_output {<br />
type "httpd"<br />
name "What you want"<br />
encoder "lame" # vorbis or lame supported<br />
port "8000"<br />
bitrate "128"<br />
format "44100:16:2" # change 2 to 1 for mono<br />
}<br />
<br />
Restart the mpd deamon and, from another computer, simply load the stream as any other url. <br />
$ mplayer http://<server's IP>:8000<br />
<br />
{{Note | You must open the port on your router / firewall for the stream to be connectible to from another computer.}}<br />
<br />
Most players (i.e. vlc or xmms2) should also be able to load the stream via their "add url..." menu option.<br />
<br />
This is a nice clean way to replace your current icecast setup with something natively supported within MPD.<br />
<br />
===mpd hangs on first startup===<br />
This is a common error that's caused by corrupt mp3 tags.<br />
Here is an experimental way to solve this issue.<br />
Requirements:<br />
* kid3<br />
* easytag<br />
<br />
This method is very tedious, especially with a huge database. Just as a baseline it took 2.5h to fix a 16Gb DB.<br />
<br />
====Easy Tag====<br />
The purpose of easytag here is that easytag detects the error in the tags, but like MPD it hangs and dies. The trick here is that easy tags actually tells you what file is causing the problem on the status bar.<br />
Before starting easytag make sure to have a terminal close to be ready to kill easy tag to avoid a hang. Once you are ready, on the tree view select the directory where all your music is located. By default easytag starts to search all subdirectories for mp3 files. Once you notice that easytag stopped scanning for songs, make note of the culprit and kill easytag.<br />
<br />
====KID3====<br />
Here's where kid3 comes in handy. With kid3 go to the offending song and rewrite one of the tags. then save the file. This should force kid3 to rewrite the whole tag again fixing the problem with MPD and easy tag hanging.<br />
<br />
Repeat this procedure until your music library is done.<br />
<br />
===Cannot connect to mpd: host "localhost" not found: Temporary failure in name resolution===<br />
Cannot connect to MPD (with ncmpcpp), if you are disconnected from network. Solution is [[IPv6 - Disabling the Module|disable IPv6]] or add line to /etc/hosts<br />
::1 localhost.localdomain localhost<br />
<br />
===Other issues when attempting to connect to mpd with a client===<br />
Some have reported being unable to access mpd with various clients, for example seeing errors like these:<br />
$ ncmpcpp<br />
Cannot connect to mpd: Connection closed by the server<br />
$ sonata<br />
2011-02-13 18:33:05 Connection lost while reading MPD hello<br />
2011-02-13 18:33:05 Not connected<br />
2011-02-13 18:33:05 Not connected<br />
<br />
Please see posts on ncmpcpp on the Arch Forums [https://bbs.archlinux.org/viewtopic.php?id=109962 HERE] and [https://bbs.archlinux.org/viewtopic.php?id=113493 HERE]. Also see the Arch bug report on this issue [https://bugs.archlinux.org/task/22071 HERE]. <br />
<br />
====First fix====<br />
Check {{Filename|mpd.conf}} for a line like {{Codeline|mpd.error}} and remove it. The mpd error file is deprecated and has been removed.<br />
<br />
====Second fix====<br />
{{Note|I'm not so sure this is a good idea. There is a warning about changing the address to bind to in the default mpd.conf. If this does not help, you might want to comment out the changes.}}<br />
If that doesn't help, add the following to {{Filename|mpd.conf}}:<br />
<pre><br />
bind_to_address "127.0.0.1"<br />
port "6600"<br />
</pre><br />
<br />
Afterwards, instruct your client to connect via 127.0.0.1. For example, add the following to the ncmpcpp config file:<br />
<pre><br />
mpd_host "127.0.0.1"<br />
mpd_port "6600"<br />
</pre><br />
<br />
<br />
===Port 6600 already in use===<br />
MPD needs to bind to port 6600 and cannot start if it's already in use. The most common reason for this is that the user has started MPD once and then subsequently tried to start mpd again. In general, nothing should be done here.<br />
<br />
If port 6600 is tied up for some other reason, one can use the following command to find the offending process:<br />
# netstat -tulpan | grep 6600<br />
<br />
This will list IP:Port and the process name holding the connection (root privileges are required to see all processes).<br />
<br />
If you need to restart mpd for whatever reason, use:<br />
<pre><br />
$ mpd --kill<br />
$ mpd <br />
</pre><br />
A more brute-force approach:<br />
<pre><br />
$ killall mpd<br />
$ mpd <br />
</pre><br />
{{Note| If you typically run MPD as root, you will need to run the above commands as root.}}<br />
<br />
In the latest version of MPD, --create-db is completely deprecated. The database will be created automagically on first run and can subsequently be updated via your client (i.e. mpc update). You can now use inotify support to automatically update your music database. Add the following to {{File|name=mpd.conf|content=auto_update "yes"}} to enable it.<br />
<br />
===Binding to IPV6 before IPV4===<br />
If on startup, you see this message:<br />
listen: bind to '0.0.0.0:6600' failed: Address already in use (continuing anyway, because binding to '[::]:6600' succeeded)<br />
MPD is attempting to bind to the ipv6 interface before binding to ipv4. If you want to use your ipv4 interface, hardcode it in mpd.conf, like so:<br />
bind_to_address "127.0.0.1"<br />
Or, you could specify several binds, for example, to have MPD listen on localhost and the external IP of your network card:<br />
bind_to_address "127.0.0.1"<br />
bind_to_address "192.168.1.13"<br />
<br />
===Crackling sound with some audio files===<br />
This is usually a playback speed problem and can be fixed by uncommenting the audio_output_format line in:<br />
<br />
{{File|name=/etc/mpd.conf|content=<br />
audio_output_format "44100:16:2"}}<br />
<br />
This is usually a sane value for most mp3 files.<br />
<br />
===daemon: cannot setgid for user "mpd": Operation not permitted ===<br />
<br />
The error is stating that the user starting the process (you) does not have permissions to become another user (mpd) which the configuration has told that process to run as.<br />
<br />
To solve the issue, simply start mpd as root.<br />
su -c "/etc/rc.d/mpd start"<br />
or<br />
sudo /etc/rc.d/mpd start<br />
<br />
==External links==<br />
* [http://www.musicpd.org/ Official Web Site]<br />
* [http://mpd.wikia.com/wiki/Main_Page Official Wiki]<br />
* [http://mpd.wikia.com/wiki/Clients Sorted List of MPD Clients]<br />
* [http://www.musicpd.org/forum/ MPD forum]</div>Rasihttps://wiki.archlinux.org/index.php?title=Music_Player_Daemon&diff=150476Music Player Daemon2011-08-02T00:44:24Z<p>Rasi: /* Quick setup */</p>
<hr />
<div>[[fr:MPD]]<br />
[[Category:Audio/Video (English)]]<br />
[[Category:Daemons and system services (English)]]<br />
{{i18n|Music Player Daemon}}<br />
[[pl:Music Player Daemon]]<br />
<br />
'''MPD''' (music player daemon) is an audio player that has a server-client architecture. MPD runs in the background as a daemon, manages playlists and a music database, and uses very few resources. In order to interface with it, you need a separate client. More information can be found on their [http://www.musicpd.org/ website].<br />
<br />
''Please'' have a look at the official page for setup and troubleshooting instructions, the main developer called our wiki page in its current state ''"full of symptom killers"'', hence the official pages should contain better instructions.<br />
<br />
==Installing mpd==<br />
Install with [[pacman]]:<br />
# pacman -S mpd<br />
<br />
==Daemon Setup: Starting at Boot==<br />
General information about MPD configuration may be found at http://mpd.wikia.com/wiki/Configuration.<br />
<br />
===Sound setup===<br />
To make audio output actually work ensure that you have setup audio card and mixer correctly. See [[ALSA]], and [[PulseAudio]] if you are using Gnome 3. Do not forget to unmute the required channels in alsamixer, raise the volume and save changes with alsactl store. Run mpd with {{Filename|/usr/bin/mpd --stdout --no-daemon --verbose}} if that still doesn't work.<br />
<br />
Make sure your card can do hardware mixing (most of them can, including onboard audio). Or else this could cause problems with multiple sound playback. For example, this can prevent Mplayer from playing back sound while the mpd daemon is running, returning an audio error message stating the device is busy.<br />
<br />
===Timeline of MPD's behavior on a typical working setup when started as a daemon===<br />
# MPD is started on boot by {{Filename|/etc/rc.conf}}, by including it in the {{Codeline|DAEMONS}} array. (Or, this can be done manually each session by running {{Codeline|/etc/rc.d/mpd start}} with root privileges).<br />
# Since MPD is now started as root, it first reads the {{Filename|/etc/mpd.conf}} file.<br />
# MPD reads the user variable in the {{Filename|/etc/mpd.conf}} file, and changes from root to this user.<br />
# MPD then reads the contents of the {{Filename|/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 {{Filename|/etc/mpd.conf}} file. This way, uses of {{Codeline|~}} in the configuration file point correctly to the home user's directory, and not root's directory. It may be worthwhile to change all uses of {{Codeline|~}} to {{Codeline|/home/username}} to avoid any confusion over this aspect of MPD's behavior.<br />
<br />
===A clean configuration file===<br />
* As root, check if {{Filename|/etc/mpd.conf}} exists and delete the file if it does. This is safe.<br />
<br />
MPD comes with an example configuration file, available at {{Filename|/usr/share/mpd/mpd.conf.example}}. This file holds an abundance of information on MPD configuration, and holds default mixer values you can simply uncomment.<br />
<br />
* As root, copy this example file to {{Filename|/etc/mpd.conf}}.<br />
# cp /usr/share/mpd/mpd.conf.example /etc/mpd.conf<br />
({{Filename|/usr/share/mpd/mpd.conf.example}} is good for userspace setup)<br />
<br />
Since MPD is being set up to run as a daemon at boot, never put this file in the user's directory like some tutorials suggest, since it will not be read. Moreover, if you previously created a {{Filename|.mpdconf}} file in your home, remove it now (to set up MPD to run with user privileges alone, pleaser refer to the section [[Music_Player_Daemon#Alternative_Setup:_Starting_as_a_User | Alternative_Setup:_Starting_as_a_User]]). This is important to prevent conflicts. The presence of the configuration file in {{Filename|/etc}}, like is the case here, is what will enable MPD to run as a daemon at boot. Otherwise, a script would be needed to run MPD ''after'' the user has logged (like kdm or {{Filename|~/.fluxbox/startup}}) or it would require a manual move each time. For a single music collection, the method used here is simply better, even while the collection is shared to multiple users. Also, don't be afraid about root privileges: even while MPD runs as a daemon, it never completely runs as root since it automatically drops its root privileges after execution.<br />
<br />
===Edit {{Filename|mpd.conf}}===<br />
<br />
The default arch install keeps the setup in /var and uses "mpd" as default user, instead of cluttering up ~/.<br />
Edit {{Filename|/etc/mpd.conf}} to reflect as such.<br />
<br />
{{File|name=/etc/mpd.conf|content=<br />
music_directory "/home/user/music" # Your music dir.<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 "/var/run/mpd/mpd.pid"<br />
state_file "/var/lib/mpd/mpdstate"<br />
user "mpd"<br />
# Binding to address and port causing problems in mpd-0.14.2 best to leave<br />
# commented.<br />
# bind_to_address "127.0.0.1"<br />
# port "6600"<br />
}}<br />
<br />
* If your music collection is contained under multiple directories, you can make symbolic links under /var/lib/mpd then set 'music_directory' to the directory holding the symbolic links. Remember to set permissions accordingly on the directories being linked.<br />
<br />
* To change the volume of audio from mpd independent of other programs, uncomment or add the switch in mpd.conf:<br />
<br />
{{File|name=/etc/mpd.conf|content=<br />
mixer_type "software"<br />
}}<br />
<br />
* Lastly, if you are running pulseaudio under Gnome 3, the default setting of "alsa" for the audio output will not work. Make the modification from:<br />
{{File|name=/etc/mpd.conf|content=<br />
audio_output {<br />
type "alsa"<br />
name "Sound Card"<br />
}<br />
}}<br />
<br />
to<br />
<br />
{{File|name=/etc/mpd.conf|content=<br />
audio_output {<br />
type "pulse"<br />
name "Sound Card"<br />
}<br />
}}<br />
<br />
<br />
===Create files===<br />
<br />
* As root, create the directories and files you specified in {{Filename|/etc/mpd.conf}}.<br />
# mkdir -p /var/lib/mpd/playlists /var/run/mpd<br />
# touch /var/lib/mpd/{mpd.db,mpdstate} && touch /var/run/mpd/mpd.pid<br />
<br />
* You then need to change the file's permissions so that the daemon can modify them.<br />
# chown -R mpd /var/lib/mpd /var/run/mpd<br />
<br />
===Create database===<br />
<br />
Creating the database is now accomplished via the update feature of the client, for example 'mpc update'. The previous method, creating the MPD database as root (# mpd --create-db), is deprecated.<br />
<br />
==Alternative Setup: Starting as a User==<br />
MPD need not be started with root permissions. The only reason why MPD needs to be started as root (by being called from {{Filename|/etc/rc.conf}}) is because the default files and folders in the default configuration file points to directories owned by root (the /var directory). A less common, but perhaps more sensible, approach is to make MPD work with files and directories owned by a normal user. Running MPD as a normal user has several advantages: <br />
# You can easily have a single directory ~/.mpd (or any other directory under /home/username) for all MPD configuration files<br />
# No read/write permission errors<br />
# More flexible calls to MPD by using {{Filename|~/.xinitrc}} instead of including 'mpd' in the {{Filename|/etc/rc.conf}} DAEMONS array.<br />
<br />
The following steps shows how to run MPD as a normal user. '''Note''': this approach will not work if you want multiple users to have access to MPD.<br />
<br />
* Copy the contents of the default MPD configuration file in {{Filename|/usr/share/mpd/mpd.conf.example}} to your home directory. A good place would be {{Filename|"/home/user/.mpd/mpd.conf"}}.<br />
* Follow the 'old setup instructions' from above, ignoring the first part about copying the config to {{Filename|/etc/mpd.conf}} and do not set a user variable. <br />
* Create all of the requisite files in {{filename|"/home/user/.mpd/"}}:<br />
"~/.mpd/playlists/"<br />
"~/.mpd/db"<br />
"~/.mpd/mpd.db"<br />
"~/.mpd/mpd.log"<br />
"~/.mpd/mpd.error"<br />
"~/.mpd/mpd.pid"<br />
"~/.mpd/mpdstate"<br />
<br />
* Let MPD start on bootup by calling it from your {{Filename|~/.xinitrc}} as follows:<br />
# this starts mpd as normal user<br />
mpd ~/.mpd/mpd.conf<br />
{{Note| that you don't have to put a "&" at the end of the line here, since MPD will automatically daemonize itself.}}<br />
<br />
Lastly, delete the entry 'mpd' from your DAEMONS array in {{Filename|/etc/rc.conf}}, as you are not running it as root anymore.<br />
<br />
===Quick setup===<br />
<br />
The fastest way to do set up the structure is to do this:<br />
<br />
$ mkdir -p ~/.mpd/playlists && touch ~/.mpd/database && cp /usr/share/doc/mpd/mpdconf.example ~/.mpd/mpd.conf<br />
<br />
Then edit mpd.conf to your liking, in a manner similar to [[Music_Player_Daemon#Edit_mpd.conf]]. Beware that you must uncomment the db_file entry if you do edit mpd.conf.<br />
<br />
Then, to run it:<br />
<br />
$ mpd ~/.mpd/mpd.conf<br />
<br />
<br />
===Even quicker setup===<br />
I created a little script that will only ask for the location of your music and then creates the needed files and folders for you.<br />
You can find the script here:<br />
http://karif.server-speed.net/~carnager/mpdsetup.tar<br />
extract it, and run ./mpdsetup.sh<br />
<br />
===Multi-mpd setup===<br />
'''Useful if you want to run for example an icecast server.'''<br />
If you want a second MPD daemon (e.g., with icecast output to share music over the network) to use the same music and playlist as the one above, simply copy the above configuration file and make a new file (e.g., {{Filename|/home/username/.mpd/config-icecast}}), and only change the log_file, error_file, pid_file, and state_file parameters (e.g., {{Filename|mpd-icecast.log}}, {{Filename|mpd-icecast.error}}, and so on); using the same directory paths for the music and playlist directories would ensure that this second mpd daemon would use the same music collection as your first one (e.g., creating and editing a playlist under the first daemon would affect the second daemon as well, so that you don't have to create the same playlists all over again for the second daemon). Then, call this second daemon the same way from your {{Filename|~/.xinitrc}} above. (Just be sure to have a different port number, so as to not conflict with your first mpd daemon).<br />
<br />
==Clients==<br />
Install a client program for MPD. Popular options are:<br />
<br />
===Console===<br />
* '''mpc''' &ndash; Command Line Client (you'll probably want this one no matter what)<br />
# pacman -S mpc<br />
* [http://mpd.wikia.com/wiki/Client:Ncmpc/ ncmpc] &ndash; NCurses Client (this one is very handy for running in a console)<br />
# pacman -S ncmpc<br />
* [http://unkart.ovh.org/ncmpcpp/ ncmpcpp] &ndash; Clone of ncmpc with some new features written in C++<br />
# pacman -S ncmpcpp<br />
* [http://pms.sourceforge.net/ pms] &ndash; NCurses Client (highly configurable and accessible)<br />
Install [http://aur.archlinux.org/packages.php?ID=24378 pmus] from the [[AUR]].<br />
<br />
===Graphical===<br />
* [http://ario-player.sourceforge.net ario] &ndash; GTK+ Client with a Rhythmbox like library browser<br />
# pacman -S ario<br />
* [http://gmpcwiki.sarine.nl/index.php?title=GMPC gmpc] &ndash; GNOME Client<br />
# pacman -S gmpc<br />
* [http://bitcheese.net/wiki/QMPDClient QMPDClient] &ndash; Client written with Qt 4.x.<br />
# pacman -S qmpdclient<br />
* [http://sonata.berlios.de/ sonata] &ndash; Python GTK+ Client<br />
# pacman -S sonata<br />
* [http://aur.archlinux.org/packages.php?ID=33380 dmpc] &ndash; Dmenu-based MPC client with a playlist manager and state-saving on playlist changes<br />
Install [http://aur.archlinux.org/packages.php?ID=33380 dmpc] from the [[AUR]].<br />
<br />
See a long list of clients at the [http://mpd.wikia.com/wiki/Clients mpd wiki].<br />
<br />
==Extra stuff==<br />
===Last.fm scrobbling===<br />
To scrobble your songs to [http://www.last.fm Last.fm] using MPD there are several alternatives.<br />
<br />
====mpdscribble====<br />
mpdscribble is another daemon, available in the "community" repository (if you prefer, the "git" version is available in the [http://aur.archlinux.org/packages.php?ID=22274 AUR]). This is arguably the best alternative, because it's the semi-official MPD scrobbler and uses the new "idle" feature in MPD for more accurate scrobbling. Also, you don't need root access to configure it, because it doesn't need any changes to <tt>/etc</tt> at all. Visit [http://mpd.wikia.com/wiki/Client:Mpdscribble the official website] for more information.<br />
<br />
After you have installed mpdscribble, do the following (not as root):<br />
<br />
* {{Codeline|$ mkdir ~/.mpdscribble}}<br />
* Create the file {{Filename|~/.mpdscribble/mpdscribble.conf}} and add the following:<br />
<pre><br />
[mpdscribble] <br />
host = <your mpd host> # optional, defaults to $MPD_HOST or localhost<br />
port = <your mpd port> # optional, defaults to $MPD_PORT or 6600<br />
log = /home/<YOUR_USERNAME>/.mpdscribble/mpdscribble.log<br />
verbose = 2<br />
sleep = 1<br />
musicdir = <your music directory><br />
proxy = <your proxy> # optional, e. g. http://your.proxy:8080, defaults to none<br />
<br />
[last.fm]<br />
# last.fm section, comment if you don't use last.fm<br />
url = http://post.audioscrobbler.com/<br />
username = <your last.fm username><br />
password = <your last.fm password> # md5sum also possible: echo -n 'PASSWORD' | md5sum | cut -f 1 -d " "<br />
journal = /home/<YOUR_USERNAME>/.mpdscribble/lastfm.journal<br />
<br />
[libre.fm]<br />
# libre.fm section, comment if you don't use libre.fm<br />
url = http://turtle.libre.fm/<br />
username = <your libre.fm username><br />
password = <your libre.fm password> # md5sum also possible: echo -n 'PASSWORD' | md5sum | cut -f 1 -d " "<br />
journal = /home/<YOUR_USERNAME>/.mpdscribble/librefm.journal<br />
</pre><br />
* Add {{Codeline|mpdscribble}} to your {{Filename|~/.xinitrc}}:<br />
pidof mpdscribble >& /dev/null<br />
if [ $? -ne 0 ]; then<br />
mpdscribble &<br />
fi<br />
<br />
====Sonata & Ario====<br />
The easiest way, if you don't care about having to have a program window open all the time, is using Sonata or Ario which are graphical frontends to MPD. They have built-in support for Last.fm scrobbling in their preferences. A downside of this is that Sonata doesn't cache your songs if for some reason you don't happen to have an Internet connection at the time of playing.<br />
<br />
====lastfmsubmitd====<br />
lastfmsubmitd is a daemon which is available in the "community" repository. To install it, first edit {{Filename|/etc/lastfmsubmitd.conf}} and add both {{Codeline|lastfmsubmitd}} and {{Codeline|lastmp}} to the {{Codeline|DAEMONS}} array in {{Filename|/etc/rc.conf}}.<br />
<br />
===Last.fm playback with lastfmproxy===<br />
lastfmproxy is a python script that streams a last.fm music stream to another media player. To setup, install [http://aur.archlinux.org/packages.php?ID=14214 lastfmproxy] from the [[AUR]] and then edit {{Filename|/usr/share/lastfmproxy/config.py}}. If you plan to only stream to MPD on the same host, just edit the login info.<br />
<br />
{{Note | Since it installs to a read only directory but it requires read/write access for features like saving previously listened to stations, it would be wise to copy {{Filename|/usr/share/lastfmproxy}} to your home directory.}}<br />
<br />
Start lastfmproxy with {{Codeline|lastfmproxy}} and visit http://localhost:1881/ in your web browser. To add a last.fm station navigate to http://localhost:1881/ followed by the lastfm:// url. Example: http://localhost:1881/lastfm://globaltags/punk . Navigate back to http://localhost:1881/ and download the m3u file by selecting the ''Start Listening'' link. Simply add it to your music library path.<br />
<br />
===Never play on start===<br />
<br />
This feature has recently been added to mpd git by Martin Kellerman, see commits b57330cf75bcb339e3f268f1019c63e40d305145 and 2fb40fe728ac07574808c40034fc0f3d2254d49d.<br />
<br />
====[https://aur.archlinux.org/packages.php?ID=19676 mpd-git] Method====<br />
This is the best method currently available, but is only currently (April 2011) enabled in the git version. Install [https://aur.archlinux.org/packages.php?ID=19676 mpd-git] from the [[AUR]], then add {{Codeline|restore_paused "yes"}} to your {{Filename|mpd.conf}} file.<br />
<br />
If you have issues with connecting your client to [https://aur.archlinux.org/packages.php?ID=19676 mpd-git], see [[Music Player Daemon#Other issues when attempting to connect to mpd with a client]].<br />
<br />
====Method 1====<br />
If you don't want MPD to always play on your system start, but yet you want to preserve the other state information, add the following lines to your {{Filename|/etc/rc.d/mpd}} file:<br />
'' ...''<br />
'' stat_busy "Starting Music Player Daemon"''<br />
<br />
# always start in paused state<br />
awk '/^state_file[ \t]+"[^"]+"$/ {<br />
match($0, "\".+\"")<br />
sfile = substr($0, RSTART + 1, RLENGTH - 2)<br />
} /^user[ \t]+"[^"]+"$/ {<br />
match($0, "\".+\"")<br />
user = substr($0, RSTART + 1, RLENGTH - 2)<br />
} END {<br />
if (sfile == "")<br />
exit;<br />
if (user != "")<br />
sub(/^~/, "/home/" user, sfile)<br />
system("sed -i \x27s|^\\(state:[ \\t]\\{1,\\}\\)play$|\\1pause|\x27 \x27" sfile "\x27")<br />
}' /etc/mpd.conf<br />
<br />
'' /usr/bin/mpd /etc/mpd.conf &> /dev/null''<br />
'' ...''<br />
<br />
This will change the player status to "paused", if it was stopped while playing. Next, you want this file to be preserved, so MPD updates won't erase this edit. Add (or edit) this line to your {{Filename|/etc/pacman.conf}}:<br />
NoUpgrade = etc/rc.d/mpd<br />
<br />
====Method 2====<br />
<br />
Another simpler method, would be to add mpd to your {{Filename|[[rc.conf]]}} deamons array and add {{Codeline|mpc stop}} or {{Codeline|mpc pause}} to {{Filename|/etc/rc.local.shutdown}} and to {{Filename|/etc/rc.local}}. (Remember you must have mpc installed to use this method).<br />
<br />
Adding only the order in {{Filename|/etc/rc.local}} cannot assure that mpd will play absolutely nothing, since there may be a delay before the stop command is executed. <br />
On the other hand, if you only add the order to {{Filename|/etc/rc.local.shutdown}}, that will assure that mpd won't play at all, as long as you properly shutdown your system.<br />
Even though they are redundant, adding it to {{Filename|/etc/rc.local}} would serve as a safety for those, presumably, rare occasions when you do not shutdown the system properly.<br />
<br />
====Method 3====<br />
<br />
The general idea between this method is to ask mdp to pause music when user logs out so that during next restart, mdp will stick to that "pause" state. Sending such command can be achieve using [http://www.archlinux.org/packages/extra/x86_64/mpc/ mpc], the command line interface to MPD:<br />
pacman -S mpc<br />
<br />
GDM users can then add the next line to /etc/gdm/PostSession/Default (be sure to add it before "exit 0"):<br />
/usr/bin/mpc pause<br />
<br />
Non-GDM users can use their own login manager's method to launch the line at logout.<br />
<br />
===MPD & ALSA===<br />
Sometimes, when you use other audio output, e.g: some web pages containing Flash applets, MPD cannot reproduce anything anymore (until you restart). The error looks something like: (if you search the file {{Filename|/var/log/mpd/mpd.error}})<br />
<br />
Error opening alsa device "hw:0,0": Device or resource busy<br />
<br />
And here is the solution (dmix saving our life again). Apply these lines in your {{Filename|/etc/mpd.conf}}:<br />
<br />
<pre><br />
audio_output {<br />
type "alsa"<br />
name "Sound Card"<br />
options "dev=dmixer"<br />
device "plug:dmix"<br />
}<br />
</pre><br />
<br />
And then restart with {{Codeline|/etc/rc.d/mpd restart}}.<br />
<br />
Searching on Internet I found the reason for why that happens in Gentoo's wiki:<br />
* The sound card does not support hardware mixing (uses '''dmix''' plugin)<br />
* An application does not work with ALSA with it's default settings<br />
<br />
For a detailed description, it is recommended to take a look at [http://mpd.wikia.com/wiki/Alsa this] link. There you can find an example asound.conf which worked for me right out of the box.<br />
<br />
====High CPU usage with ALSA====<br />
When using MPD with ALSA, users may experience MPD taking up lots of CPU (around 20-30%). This is caused by most sound cards supporting 48kHz and most music being 44kHz, thus forcing MPD to resample it. This operation takes lots of CPU cycles and results into high usage.<br />
<br />
For most users the problem should be solved by telling MPD not to use resampling by adding {{Codeline|auto_resample "no"}} into audio_output-part of {{Filename|/etc/mpd.conf}}. This will degrade quality slightly, however.<br />
<br />
Example from {{Filename|mpd.conf}}:<br />
<br />
audio_output {<br />
type "alsa"<br />
name "My ALSA Device"<br />
auto_resample "no"<br />
}<br />
<br />
Although it may not give as drastic a speedup, enabling mmap may speed things up:<br />
<br />
audio_output {<br />
type "alsa"<br />
name "My ALSA Device"<br />
use_mmap "yes"<br />
}<br />
<br />
Some users might also want to tell dmix to use 44kHz as well. More info about tuning performance of your MPD can be found from: [http://mpd.wikia.com/wiki/Tuning MPD wiki]<br />
<br />
====Example configuration: Output with 44.1 KHz at e. g. 16 bit depth, multiple programs at once====<br />
<br />
''Why these formats?'' Because they are standard CDA, because ALSA on its own allows more than one program "to sound" only with dmix — whose resampling algorithm is inferior — and because dmix by default resamples anything lower to 48 KHz (or whatever higher format is playing at the time). Also, some get clicking sounds if at least {{Filename|mpd.conf}} is not changed this way.<br />
<br />
''What's the downside?'' These settings cause ''everything'' (if necessary) to be resampled to this format, such as material from DVD or TV which usually is at 48 KHz. But there is no known way to have ALSA dynamically change the format, and particularly if you listen to far more CDs than anything else the occasional 48 → 44.1 isn't too great a loss.<br />
<br />
The following assumes that there are not already other settings which conflict resp. overwrite it. This applies especially to the current user's potential {{Filename|~/.asoundrc}} — which MPD as its own user ignores, therefore the following should go to {{Filename|/etc/asound.conf}}:<br />
<br />
{{File|name=/etc/asound.conf|content=<br />
defaults.pcm.dmix.rate 44100 # Force 44.1 KHz<br />
defaults.pcm.dmix.format S16_LE # Force 16 bits<br />
}}<br />
<br />
{{File|name=/etc/mpd.conf|content=<br />
audio_output {<br />
type "alsa" # Use the ALSA output plugin.<br />
name "HDA Intel" # Can be called anything or nothing tmk, but must be present.<br />
options "dev=dmixer"<br />
device "plug:dmix" # Both lines cause MPD to output to dmix.<br />
format "44100:16:2" # the actual format<br />
auto_resample "no" # This bypasses ALSA's own algorithms, which generally are inferior. See below how to choose a different one.<br />
use_mmap "yes" # Minor speed improvement, should work with all modern cards.<br />
}<br />
<br />
samplerate_converter "0" # MPD's best, most CPU intensive algorithm. See 'man mpd.conf' for others — for anything other than the poorest "internal", libsamplerate must be installed.<br />
}}<br />
<br />
{{Note|MPD gives the mp3 format a special treatment at decoding: It's always outputted as 24 bit. (The conversion as forced by the ''format'' line only comes after that.)}}<br />
<br />
If one wants to leave the bit depth decision to ALSA resp. MPD, comment out resp. omit the ''dmix.format'' line and change the one for mpd with ''format'' to "44100:*:2".<br />
<br />
{{Note|''Crossfading'' between files decoded at two different bit depths (say, one mp3 and one 16 bit flac) does not work unless conversion is active.}}<br />
<br />
===Control MPD with lirc===<br />
There are already some clients designed for communications between lircd and MPD, however, as far as the practical use, they aren't very useful since their functions are limited.<br />
<br />
It's recommended to use mpc with irexec. mpc is a command line player which only sends the command to MPD and exits immediately, which is perfect for irexec, the command runner included in lirc. What irexec does is that it runs a specified command once received a remote control button.<br />
<br />
First of all, please setup your remotes as referred to the '''[[Lirc]]''' article.<br />
<br />
Edit your favored lirc startup configuration file, default location is {{Filename|~/.lircrc}}.<br />
<br />
Fill the file with the following pattern:<br />
begin<br />
prog = irexec<br />
button = <button_name><br />
config = <command_to_run><br />
repeat = <0 or 1><br />
end<br />
<br />
An useful example:<br />
## irexec<br />
begin<br />
prog = irexec<br />
button = play_pause<br />
config = mpc toggle<br />
repeat = 0<br />
end<br />
<br />
begin<br />
prog = irexec<br />
button = stop<br />
config = mpc stop<br />
repeat = 0<br />
end<br />
begin<br />
prog = irexec<br />
button = previous<br />
config = mpc prev<br />
repeat = 0<br />
end<br />
begin<br />
prog = irexec<br />
button = next<br />
config = mpc next<br />
repeat = 0<br />
end<br />
begin<br />
prog = irexec<br />
button = volup<br />
config = mpc volume +2<br />
repeat = 1<br />
end<br />
begin<br />
prog = irexec<br />
button = voldown<br />
config = mpc volume -2<br />
repeat = 1<br />
end<br />
begin<br />
prog = irexec<br />
button = pbc<br />
config = mpc random<br />
repeat = 0<br />
end<br />
begin<br />
prog = irexec<br />
button = pdvd<br />
config = mpc update<br />
repeat = 0<br />
end<br />
begin<br />
prog = irexec<br />
button = right<br />
config = mpc seek +00:00:05<br />
repeat = 0<br />
end<br />
begin<br />
prog = irexec<br />
button = left<br />
config = mpc seek -00:00:05<br />
repeat = 0<br />
end<br />
begin<br />
prog = irexec<br />
button = up<br />
config = mpc seek +1%<br />
repeat = 0<br />
end<br />
begin<br />
prog = irexec<br />
button = down<br />
config = mpc seek -1%<br />
repeat = 0<br />
end<br />
<br />
There are more functions for mpc, run {{Codeline|man mpc}} for more info.<br />
<br />
===Control MPD with bluetooth phone===<br />
You can also control MPD (to a certain extent) using a bluetooth enabled phone. You need to do the following:<br />
<br />
* install [http://remuco.sourceforge.net/index.php/Remuco remuco] -- a wireless remote control for several Linux media players ([http://aur.archlinux.org/packages.php?ID=25072 aur])<br />
* transfer remuco client -- jar/jad files from {{Filename|/usr/share/remuco/client/}} to your phone and install it<br />
* run {{Codeline|remuco-mpd}} (as current user)<br />
* run remuco on your phone, define a new bluetooth remuco connection (pair first if you haven't done this previously) and explore its capabilities<br />
<br />
More information about remuco including troubleshooting to be found at its [http://remuco.sourceforge.net/index.php/Remuco homepage]<br />
<br />
===MPD & PulseAudio===<br />
<br />
Edit {{Filename|/etc/mpd.conf}}, and uncomment the audio_output section for the type "pulse". The server and sink lines of it should be commented unless you know what you're doing.<br />
<br />
Then, add the mpd user (and yours if you haven't done so already) to the necessary pulse groups. The pulse-access group should be sufficient but you may want to add pulse-rt as well. The group "pulse" doesn't appear to be necessary.<br />
# gpasswd -a mpd pulse-access<br />
# gpasswd -a mpd pulse-rt<br />
<br />
Lastly, you may or may not need to copy {{Filename|~/.pulse-cookie}} from your current (pulse working) user's dir to your mpd user's home directory. It is likely to be {{Filename|/var/lib/mpd}} if you followed the first part of this wiki. This would probably only allow your current user to listen in on MPD's pulse. You may consider running pulse system-wide if that's insufficient.<br />
<br />
===Cue Files===<br />
<br />
To make cue file support actually work, you have to work around a nasty libcue bug. Libcue copied some files directly from libcdio, making it conflict with it. Steps to do to get proper cue support:<br />
<br />
* remove libcdio temporary (pacman -Rdd libcdio)<br />
* install libcue (pacman -S libcue)<br />
* install mpd with abs or from aur.<br />
* reinstall libcdio (pacman -S libcdio)<br />
<br />
At the point of writing mpd does not parse tracknumbers from cue sheets. There is a patch available (http://musicpd.org/mantis/view.php?id=3230)<br />
Once this patch is merged into mpd, i will remove this line :)<br />
<br />
==Troubleshooting==<br />
===Autodetection failed===<br />
During the start of MPD, it tries to autodetect your set-up and configure output and volume control accordingly. Though this mostly goes well, it will fail for some systems. It may help to tell MPD specifically what to use as output and mixer control. If you copied {{Filename|/etc/mpd.conf}} over from {{Filename|/etc/mpd.conf.example}} as mentioned above, you can simply uncomment:<br />
<br />
Example for alsa output type and alsa mixer:<br />
audio_output {<br />
type "alsa"<br />
name "My ALSA Device"<br />
device "hw:0,0" # optional<br />
format "44100:16:2" # optional<br />
mixer_type "hardware"<br />
mixer_device "default"<br />
mixer_control "PCM"<br />
}<br />
<br />
'''Note:''' in case of permission problems when using ESD with MPD run this as root:<br />
# chsh -s /bin/true mpd<br />
<br />
===Executable permissions===<br />
{{Warning|This is not good security practice and may be unnecessary.}}<br />
<br />
MPD needs to have +x permissions on '''ALL''' parent directories to your music collection (ie. if it's located outside of "mpd" home directory /var/lib/mpd). By default useradd sets permissions on home dir to 1700 drwx------. So if you're like me you will need to change permissions of /home/user. Example... my music collection is located /home/user/music. <br />
# chmod a+x /home/$USER<br />
# chmod -R a+X /home/$USER/music<br />
<br />
====Alternative solution====<br />
An alternative solution would be to use your group to share a selection of files, among them your music library. First remove all permissions for the group then add group permissions to read and execute home and music.<br />
# chmod -R g-rwx /home/$USER<br />
# chmod g+rx /home/$USER<br />
# chmod -R g+rX /home/$USER/music<br />
<br />
====Another alternative solution====<br />
Another alternative is to remount the music directory under a directory that mpd has access to. This does not entail the same security risks as modifying the permissions on one's home directory.<br />
# mkdir /var/lib/mpd/music<br />
# echo "/home/$USER/music /var/lib/mpd/music none bind" >> /etc/fstab<br />
# mount -a<br />
# /etc/rc.d/mpd restart<br />
And that should fix the problem. See also [https://bbs.archlinux.org/viewtopic.php?id=86449 the forum thread.]<br />
<br />
===Avoiding timeouts===<br />
To get rid of timeouts (i.e. when you paused music for long time) in gpmc and other clients uncomment and increase {{Codeline|connection_timeout}} option in {{Filename|mpd.conf}}.<br />
<br />
If files and/or titles are shown in wrong encoding, uncomment and change {{Codeline|filesystem_charset}} and {{Codeline|id3v1_encoding}} options.<br />
Note that you cannot set encoding for ID3 v2 tags. To workaround this you may use [http://mpd.wikia.com/wiki/GenericDecoder#Generic_Tagreader external tag readers].<br />
<br />
If you want to use another computer to control MPD over a network, the {{Codeline|bind_to_address}} option in {{Filename|mpd.conf}} will need to be set to either your IP address, or {{Codeline|any}} if your IP address changes frequently. <br />
<br />
'''Streaming'''<br><br />
With the latest version of MPD (0.15), built-in httpd streaming is now available.<br />
<br />
To activate this feature, you'll just need to add a new output of type httpd in {{Filename|mpd.conf}}:<br />
audio_output {<br />
type "httpd"<br />
name "What you want"<br />
encoder "lame" # vorbis or lame supported<br />
port "8000"<br />
bitrate "128"<br />
format "44100:16:2" # change 2 to 1 for mono<br />
}<br />
<br />
Restart the mpd deamon and, from another computer, simply load the stream as any other url. <br />
$ mplayer http://<server's IP>:8000<br />
<br />
{{Note | You must open the port on your router / firewall for the stream to be connectible to from another computer.}}<br />
<br />
Most players (i.e. vlc or xmms2) should also be able to load the stream via their "add url..." menu option.<br />
<br />
This is a nice clean way to replace your current icecast setup with something natively supported within MPD.<br />
<br />
===mpd hangs on first startup===<br />
This is a common error that's caused by corrupt mp3 tags.<br />
Here is an experimental way to solve this issue.<br />
Requirements:<br />
* kid3<br />
* easytag<br />
<br />
This method is very tedious, especially with a huge database. Just as a baseline it took 2.5h to fix a 16Gb DB.<br />
<br />
====Easy Tag====<br />
The purpose of easytag here is that easytag detects the error in the tags, but like MPD it hangs and dies. The trick here is that easy tags actually tells you what file is causing the problem on the status bar.<br />
Before starting easytag make sure to have a terminal close to be ready to kill easy tag to avoid a hang. Once you are ready, on the tree view select the directory where all your music is located. By default easytag starts to search all subdirectories for mp3 files. Once you notice that easytag stopped scanning for songs, make note of the culprit and kill easytag.<br />
<br />
====KID3====<br />
Here's where kid3 comes in handy. With kid3 go to the offending song and rewrite one of the tags. then save the file. This should force kid3 to rewrite the whole tag again fixing the problem with MPD and easy tag hanging.<br />
<br />
Repeat this procedure until your music library is done.<br />
<br />
===Cannot connect to mpd: host "localhost" not found: Temporary failure in name resolution===<br />
Cannot connect to MPD (with ncmpcpp), if you are disconnected from network. Solution is [[IPv6 - Disabling the Module|disable IPv6]] or add line to /etc/hosts<br />
::1 localhost.localdomain localhost<br />
<br />
===Other issues when attempting to connect to mpd with a client===<br />
Some have reported being unable to access mpd with various clients, for example seeing errors like these:<br />
$ ncmpcpp<br />
Cannot connect to mpd: Connection closed by the server<br />
$ sonata<br />
2011-02-13 18:33:05 Connection lost while reading MPD hello<br />
2011-02-13 18:33:05 Not connected<br />
2011-02-13 18:33:05 Not connected<br />
<br />
Please see posts on ncmpcpp on the Arch Forums [https://bbs.archlinux.org/viewtopic.php?id=109962 HERE] and [https://bbs.archlinux.org/viewtopic.php?id=113493 HERE]. Also see the Arch bug report on this issue [https://bugs.archlinux.org/task/22071 HERE]. <br />
<br />
====First fix====<br />
Check {{Filename|mpd.conf}} for a line like {{Codeline|mpd.error}} and remove it. The mpd error file is deprecated and has been removed.<br />
<br />
====Second fix====<br />
{{Note|I'm not so sure this is a good idea. There is a warning about changing the address to bind to in the default mpd.conf. If this does not help, you might want to comment out the changes.}}<br />
If that doesn't help, add the following to {{Filename|mpd.conf}}:<br />
<pre><br />
bind_to_address "127.0.0.1"<br />
port "6600"<br />
</pre><br />
<br />
Afterwards, instruct your client to connect via 127.0.0.1. For example, add the following to the ncmpcpp config file:<br />
<pre><br />
mpd_host "127.0.0.1"<br />
mpd_port "6600"<br />
</pre><br />
<br />
<br />
===Port 6600 already in use===<br />
MPD needs to bind to port 6600 and cannot start if it's already in use. The most common reason for this is that the user has started MPD once and then subsequently tried to start mpd again. In general, nothing should be done here.<br />
<br />
If port 6600 is tied up for some other reason, one can use the following command to find the offending process:<br />
# netstat -tulpan | grep 6600<br />
<br />
This will list IP:Port and the process name holding the connection (root privileges are required to see all processes).<br />
<br />
If you need to restart mpd for whatever reason, use:<br />
<pre><br />
$ mpd --kill<br />
$ mpd <br />
</pre><br />
A more brute-force approach:<br />
<pre><br />
$ killall mpd<br />
$ mpd <br />
</pre><br />
{{Note| If you typically run MPD as root, you will need to run the above commands as root.}}<br />
<br />
In the latest version of MPD, --create-db is completely deprecated. The database will be created automagically on first run and can subsequently be updated via your client (i.e. mpc update). You can now use inotify support to automatically update your music database. Add the following to {{File|name=mpd.conf|content=auto_update "yes"}} to enable it.<br />
<br />
===Binding to IPV6 before IPV4===<br />
If on startup, you see this message:<br />
listen: bind to '0.0.0.0:6600' failed: Address already in use (continuing anyway, because binding to '[::]:6600' succeeded)<br />
MPD is attempting to bind to the ipv6 interface before binding to ipv4. If you want to use your ipv4 interface, hardcode it in mpd.conf, like so:<br />
bind_to_address "127.0.0.1"<br />
Or, you could specify several binds, for example, to have MPD listen on localhost and the external IP of your network card:<br />
bind_to_address "127.0.0.1"<br />
bind_to_address "192.168.1.13"<br />
<br />
===Crackling sound with some audio files===<br />
This is usually a playback speed problem and can be fixed by uncommenting the audio_output_format line in:<br />
<br />
{{File|name=/etc/mpd.conf|content=<br />
audio_output_format "44100:16:2"}}<br />
<br />
This is usually a sane value for most mp3 files.<br />
<br />
===daemon: cannot setgid for user "mpd": Operation not permitted ===<br />
<br />
The error is stating that the user starting the process (you) does not have permissions to become another user (mpd) which the configuration has told that process to run as.<br />
<br />
To solve the issue, simply start mpd as root.<br />
su -c "/etc/rc.d/mpd start"<br />
or<br />
sudo /etc/rc.d/mpd start<br />
<br />
==External links==<br />
* [http://www.musicpd.org/ Official Web Site]<br />
* [http://mpd.wikia.com/wiki/Main_Page Official Wiki]<br />
* [http://mpd.wikia.com/wiki/Clients Sorted List of MPD Clients]<br />
* [http://www.musicpd.org/forum/ MPD forum]</div>Rasihttps://wiki.archlinux.org/index.php?title=Music_Player_Daemon&diff=139077Music Player Daemon2011-05-01T10:17:15Z<p>Rasi: /* Extra stuff */</p>
<hr />
<div>[[Category:Audio/Video (English)]]<br />
[[Category:Daemons and system services (English)]]<br />
[[Category:HOWTOs (English)]]<br />
{{i18n|Music Player Daemon}}<br />
[[pl:Music Player Daemon]]<br />
<br />
'''MPD''' (music player daemon) is an audio player that has a server-client architecture. MPD runs in the background as a daemon, manages playlists and a music database, and uses very few resources. In order to interface with it, you need a separate client. More information can be found on their [http://www.musicpd.org/ website].<br />
<br />
''Please'' have a look at the official page for setup and troubleshooting instructions, the main developer called our wiki page in its current state ''"full of symptom killers"'', hence the official pages should contain better instructions.<br />
<br />
==Daemon install procedure==<br />
Install with [[pacman]]:<br />
# pacman -S mpd<br />
<br />
==Setup instructions==<br />
For more information about MPD configuration visit http://mpd.wikia.com/wiki/Configuration.<br />
<br />
===Sound setup===<br />
To make audio output actually work ensure that you have setup audio card and mixer correctly. See [[ALSA]]. Do not forget to unmute the required channels in alsamixer, raise the volume and save changes with alsactl store. Run mpd with {{Filename|/usr/bin/mpd --stdout --no-daemon --verbose}} if that still doesn't work.<br />
<br />
Make sure your card can do hardware mixing (most of them can, including onboard audio). Or else this could cause problems with multiple sound playback. For example, this can prevent Mplayer from playing back sound while the mpd daemon is running, returning an audio error message stating the device is busy.<br />
<br />
===Timeline of MPD's behavior on a typical working setup===<br />
# MPD is started on boot by {{Filename|/etc/rc.conf}}, by including it in the {{Codeline|DAEMONS}} array. (Or, this can be done manually each session by running {{Codeline|/etc/rc.d/mpd start}} with root privileges).<br />
# Since MPD is now started as root, it first reads the {{Filename|/etc/mpd.conf}} file.<br />
# MPD reads the user variable in the {{Filename|/etc/mpd.conf}} file, and changes from root to this user.<br />
# MPD then reads the contents of the {{Filename|/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 {{Filename|/etc/mpd.conf}} file. This way, uses of {{Codeline|~}} in the configuration file point correctly to the home user's directory, and not root's directory. It may be worthwhile to change all uses of {{Codeline|~}} to {{Codeline|/home/username}} to avoid any confusion over this aspect of MPD's behavior.<br />
<br />
===A clean configuration file===<br />
* As root, check if {{Filename|/etc/mpd.conf}} exists and delete the file if it does. This is safe.<br />
<br />
Mpd comes with an example configuration file, available at {{Filename|/usr/share/mpd/mpd.conf.example}}. This file holds an abundance of information on MPD configuration, and holds default mixer values you can simply uncomment.<br />
<br />
* As root, copy this example file to {{Filename|/etc/mpd.conf}}.<br />
# cp /usr/share/mpd/mpd.conf.example /etc/mpd.conf<br />
(/usr/share/mpd/mpd.conf.example is good for userspace setup)<br />
<br />
Never put this file in the user's directory like some tutorials suggest. This would complicate things and most of the time doing this is useless (notice you're reading a quick installation howto). If you previously created a {{Filename|.mpdconf}} file in your home, remove it now. This is important to prevent conflicts. When placing it in {{Filename|/etc}}, like we do here, MPD will be able to run as a daemon at boot. Otherwise, a script would be needed to run MPD ''after'' the user has logged (like kdm or {{Filename|~/.fluxbox/startup}}) or it would require a manual move each time. For a single music collection, the method used here is simply better, even while the collection is shared to multiple users. Also, don't be afraid about root privileges: even while MPD runs as a daemon, it never completely runs as root since it automatically drops its root privileges after execution.<br />
<br />
===Edit {{Filename|mpd.conf}}===<br />
<br />
The default arch install keeps the setup in /var and uses "mpd" as default user, instead of cluttering up ~/.<br />
Edit {{Filename|/etc/mpd.conf}} to reflect as such.<br />
<br />
{{File|name=/etc/mpd.conf|content=<br />
music_directory "/home/user/music" # Your music dir.<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 "/var/run/mpd/mpd.pid"<br />
state_file "/var/lib/mpd/mpdstate"<br />
user "mpd"<br />
# Binding to address and port causing problems in mpd-0.14.2 best to leave<br />
# commented.<br />
# bind_to_address "127.0.0.1"<br />
# port "6600"<br />
}}<br />
<br />
* If your music collection is contained under multiple directories, you can make symbolic links under /var/lib/mpd then set 'music_directory' to the directory holding the symbolic links. Remember to set permissions accordingly on the directories being linked.<br />
<br />
* To change the volume of audio from mpd independent of other programs, uncomment or add the switch in mpd.conf:<br />
<br />
{{File|name=/etc/mpd.conf|content=<br />
mixer_type "software"<br />
}}<br />
<br />
===Create files===<br />
<br />
* As root, create the directories and files you specified in {{Filename|/etc/mpd.conf}}.<br />
# mkdir -p /var/lib/mpd/playlists /var/run/mpd<br />
# touch /var/lib/mpd/{mpd.db,mpdstate} && touch /var/run/mpd/mpd.pid<br />
<br />
* You then need to change the file's permissions so that the daemon can modify them.<br />
# chown -R mpd /var/lib/mpd /var/run/mpd<br />
<br />
===Create database===<br />
<br />
Creating the database is now accomplished via the update feature of the client, for example 'mpc update'. The previous method, creating the MPD database as root (# mpd --create-db), is deprecated.<br />
<br />
==Alternative setup==<br />
MPD need not be started with root permissions. The only reason why MPD needs to be started as root (by being called from {{Filename|/etc/rc.conf}}) is because the default files and folders in the default configuration file points to directories owned by root (the /var directory). A less common, but perhaps more sensible, approach is to make MPD work with files and directories owned by a normal user. Running MPD as a normal user has several advantages: <br />
# You can easily have a single directory ~/.mpd (or any other directory under /home/username) for all MPD configuration files<br />
# No read/write permission errors<br />
# More flexible calls to MPD by using {{Filename|~/.xinitrc}} instead of including 'mpd' in the {{Filename|/etc/rc.conf}} DAEMONS array.<br />
<br />
The following steps shows how to run MPD as a normal user. '''Note''': this approach will not work if you want multiple users to have access to MPD.<br />
<br />
* Copy the contents of the default MPD configuration file in {{Filename|/usr/share/mpd/mpd.conf.example}} to your home directory. A good place would be {{Filename|"/home/user/.mpd/mpd.conf"}}.<br />
* Follow the 'old setup instructions' from above, ignoring the first part about copying the config to {{Filename|/etc/mpd.conf}}. <br />
* Create all of the requisite files in {{filename|"/home/user/.mpd/"}}:<br />
"~/.mpd/playlists"<br />
"~/.mpd/db"<br />
"~/.mpd/mpd.log"<br />
"~/.mpd/mpd.error"<br />
"~/.mpd/mpd.pid"<br />
"~/.mpd/mpdstate"<br />
<br />
* Let MPD start on bootup by calling it from your {{Filename|~/.xinitrc}} as follows:<br />
# this starts mpd as normal user<br />
mpd ~/.mpd/mpd.conf<br />
{{Note| that you don't have to put a "&" at the end of the line here, since MPD will automatically daemonize itself.}}<br />
<br />
Lastly, delete the entry 'mpd' from your DAEMONS array in {{Filename|/etc/rc.conf}}, as you are not running it as root anymore.<br />
<br />
===Quick setup===<br />
<br />
The fastest way to do set up the structure is to do this:<br />
<br />
$ mkdir -p ~/.mpd/playlists && touch ~/.mpd/database && cp /usr/share/doc/mpd/mpdconf.example ~/.mpd/mpd.conf<br />
<br />
Then edit mpd.conf to your liking. Beware that you must uncomment the db_file entry if you do edit mpd.conf.<br />
<br />
Then, to run it:<br />
<br />
$ mpd ~/.mpd/mpd.conf<br />
<br />
===Multi-mpd setup===<br />
'''Useful if you want to run for example an icecast server.'''<br />
If you want a second MPD daemon (e.g., with icecast output to share music over the network) to use the same music and playlist as the one above, simply copy the above configuration file and make a new file (e.g., {{Filename|/home/username/.mpd/config-icecast}}), and only change the log_file, error_file, pid_file, and state_file parameters (e.g., {{Filename|mpd-icecast.log}}, {{Filename|mpd-icecast.error}}, and so on); using the same directory paths for the music and playlist directories would ensure that this second mpd daemon would use the same music collection as your first one (e.g., creating and editing a playlist under the first daemon would affect the second daemon as well, so that you don't have to create the same playlists all over again for the second daemon). Then, call this second daemon the same way from your {{Filename|~/.xinitrc}} above. (Just be sure to have a different port number, so as to not conflict with your first mpd daemon).<br />
<br />
==Clients==<br />
Install a client program for MPD. Popular options are:<br />
<br />
===Console===<br />
* '''mpc''' &ndash; Command Line Client (you'll probably want this one no matter what)<br />
# pacman -S mpc<br />
* [http://hem.bredband.net/kaw/ncmpc/ ncmpc] &ndash; NCurses Client (this one is very handy for running in a console)<br />
# pacman -S ncmpc<br />
* [http://unkart.ovh.org/ncmpcpp/ ncmpcpp] &ndash; Clone of ncmpc with some new features written in C++<br />
# pacman -S ncmpcpp<br />
* [http://pms.sourceforge.net/ pms] &ndash; NCurses Client (highly configurable and accessible)<br />
Install [http://aur.archlinux.org/packages.php?ID=24378 pmus] from the [[AUR]].<br />
<br />
===Graphical===<br />
* [http://ario-player.sourceforge.net ario] &ndash; GTK+ Client with a Rhythmbox like library browser<br />
# pacman -S ario<br />
* [http://gmpcwiki.sarine.nl/index.php?title=GMPC gmpc] &ndash; GNOME Client<br />
# pacman -S gmpc<br />
* [http://bitcheese.net/wiki/QMPDClient QMPDClient] &ndash; Client written with Qt 4.x.<br />
# pacman -S qmpdclient<br />
* [http://sonata.berlios.de/ sonata] &ndash; Python GTK+ Client<br />
# pacman -S sonata<br />
* [http://aur.archlinux.org/packages.php?ID=33380 dmpc] &ndash; Dmenu-based MPC client with a playlist manager and state-saving on playlist changes<br />
Install [http://aur.archlinux.org/packages.php?ID=33380 dmpc] from the [[AUR]].<br />
<br />
See a long list of clients at the [http://mpd.wikia.com/wiki/Clients mpd wiki].<br />
<br />
==Extra stuff==<br />
===Last.fm scrobbling===<br />
To scrobble your songs to [http://www.last.fm Last.fm] using MPD there are several alternatives.<br />
<br />
====mpdscribble====<br />
mpdscribble is another daemon, available in the "community" repository (if you prefer, the "git" version is available in the [http://aur.archlinux.org/packages.php?ID=22274 AUR]). This is arguably the best alternative, because it's the semi-official MPD scrobbler and uses the new "idle" feature in MPD for more accurate scrobbling. Also, you don't need root access to configure it, because it doesn't need any changes to <tt>/etc</tt> at all. Visit [http://mpd.wikia.com/wiki/Client:Mpdscribble the official website] for more information.<br />
<br />
After you have installed mpdscribble, do the following (not as root):<br />
<br />
* {{Codeline|$ mkdir ~/.mpdscribble}}<br />
* Create the file {{Filename|~/.mpdscribble/mpdscribble.conf}} and add the following:<br />
<pre><br />
[mpdscribble] <br />
host = <your mpd host> # optional, defaults to $MPD_HOST or localhost<br />
port = <your mpd port> # optional, defaults to $MPD_PORT or 6600<br />
log = /home/<YOUR_USERNAME>/.mpdscribble/mpdscribble.log<br />
verbose = 2<br />
sleep = 1<br />
musicdir = <your music directory><br />
proxy = <your proxy> # optional, e. g. http://your.proxy:8080, defaults to none<br />
<br />
[last.fm]<br />
# last.fm section, comment if you don't use last.fm<br />
url = http://post.audioscrobbler.com/<br />
username = <your last.fm username><br />
password = <your last.fm password> # md5sum also possible: echo -n PASSWORD | md5sum | cut -f 1 -d " "<br />
journal = /home/<YOUR_USERNAME>/.mpdscribble/lastfm.journal<br />
<br />
[libre.fm]<br />
# libre.fm section, comment if you don't use libre.fm<br />
url = http://turtle.libre.fm/<br />
username = <your libre.fm username><br />
password = <your libre.fm password> # md5sum also possible: echo -n PASSWORD | md5sum | cut -f 1 -d " "<br />
journal = /home/<YOUR_USERNAME>/.mpdscribble/librefm.journal<br />
</pre><br />
* Add {{Codeline|mpdscribble}} to your {{Filename|~/.xinitrc}}:<br />
pidof mpdscribble >& /dev/null<br />
if [ $? -ne 0 ]; then<br />
mpdscribble &<br />
fi<br />
<br />
====Sonata & Ario====<br />
The easiest way, if you don't care about having to have a program window open all the time, is using Sonata or Ario which are graphical frontends to MPD. They have built-in support for Last.fm scrobbling in their preferences. A downside of this is that Sonata doesn't cache your songs if for some reason you don't happen to have an Internet connection at the time of playing.<br />
<br />
====lastfmsubmitd====<br />
lastfmsubmitd is a daemon which is available in the "community" repository. To install it, first edit {{Filename|/etc/lastfmsubmitd.conf}} and add both {{Codeline|lastfmsubmitd}} and {{Codeline|lastmp}} to the {{Codeline|DAEMONS}} array in {{Filename|/etc/rc.conf}}.<br />
<br />
===Last.fm playback with lastfmproxy===<br />
lastfmproxy is a python script that streams a last.fm music stream to another media player. To setup, install [http://aur.archlinux.org/packages.php?ID=14214 lastfmproxy] from the [[AUR]] and then edit {{Filename|/usr/share/lastfmproxy/config.py}}. If you plan to only stream to MPD on the same host, just edit the login info.<br />
<br />
{{Note | Since it installs to a read only directory but it requires read/write access for features like saving previously listened to stations, it would be wise to copy {{Filename|/usr/share/lastfmproxy}} to your home directory.}}<br />
<br />
Start lastfmproxy with {{Codeline|lastfmproxy}} and visit http://localhost:1881/ in your web browser. To add a last.fm station navigate to http://localhost:1881/ followed by the lastfm:// url. Example: http://localhost:1881/lastfm://globaltags/punk . Navigate back to http://localhost:1881/ and download the m3u file by selecting the ''Start Listening'' link. Simply add it to your music library path.<br />
<br />
===Never play on start===<br />
<br />
This feature has recently been added to mpd git by Martin Kellerman, see commits b57330cf75bcb339e3f268f1019c63e40d305145 and 2fb40fe728ac07574808c40034fc0f3d2254d49d.<br />
<br />
====[https://aur.archlinux.org/packages.php?ID=19676 mpd-git] Method====<br />
This is the best method currently available, but is only currently (April 2011) enabled in the git version. Install [https://aur.archlinux.org/packages.php?ID=19676 mpd-git] from the [[AUR]], then add {{Codeline|restore_paused "yes"}} to your {{Filename|mpd.conf}} file.<br />
<br />
If you have issues with connecting your client to [https://aur.archlinux.org/packages.php?ID=19676 mpd-git], see [[Music Player Daemon#Other issues when attempting to connect to mpd with a client]].<br />
<br />
====Method 1====<br />
If you don't want MPD to always play on your system start, but yet you want to preserve the other state information, add the following lines to your {{Filename|/etc/rc.d/mpd}} file:<br />
'' ...''<br />
'' stat_busy "Starting Music Player Daemon"''<br />
<br />
# always start in paused state<br />
awk '/^state_file[ \t]+"[^"]+"$/ {<br />
match($0, "\".+\"")<br />
sfile = substr($0, RSTART + 1, RLENGTH - 2)<br />
} /^user[ \t]+"[^"]+"$/ {<br />
match($0, "\".+\"")<br />
user = substr($0, RSTART + 1, RLENGTH - 2)<br />
} END {<br />
if (sfile == "")<br />
exit;<br />
if (user != "")<br />
sub(/^~/, "/home/" user, sfile)<br />
system("sed -i \x27s|^\\(state:[ \\t]\\{1,\\}\\)play$|\\1pause|\x27 \x27" sfile "\x27")<br />
}' /etc/mpd.conf<br />
<br />
'' /usr/bin/mpd /etc/mpd.conf &> /dev/null''<br />
'' ...''<br />
<br />
This will change the player status to "paused", if it was stopped while playing. Next, you want this file to be preserved, so MPD updates won't erase this edit. Add (or edit) this line to your {{Filename|/etc/pacman.conf}}:<br />
NoUpgrade = etc/rc.d/mpd<br />
<br />
====Method 2====<br />
<br />
Another simpler method, would be to add mpd to your {{Filename|[[rc.conf]]}} deamons array and add {{Codeline|mpc stop}} or {{Codeline|mpc pause}} to {{Filename|/etc/rc.local.shutdown}} and to {{Filename|/etc/rc.local}}. (Remember you must have mpc installed to use this method).<br />
<br />
Adding only the order in {{Filename|/etc/rc.local}} cannot assure that mpd will play absolutely nothing, since there may be a delay before the stop command is executed. <br />
On the other hand, if you only add the order to {{Filename|/etc/rc.local.shutdown}}, that will assure that mpd won't play at all, as long as you properly shutdown your system.<br />
Even though they are redundant, adding it to {{Filename|/etc/rc.local}} would serve as a safety for those, presumably, rare occasions when you do not shutdown the system properly.<br />
<br />
====Method 3====<br />
<br />
The general idea between this method is to ask mdp to pause music when user logs out so that during next restart, mdp will stick to that "pause" state. Sending such command can be achieve using [http://www.archlinux.org/packages/extra/x86_64/mpc/ mpc], the command line interface to MPD:<br />
pacman -S mpc<br />
<br />
GDM users can then add the next line to /etc/gdm/PostSession/Default (be sure to add it before "exit 0"):<br />
/usr/bin/mpc pause<br />
<br />
Non-GDM users can use their own login manager's method to launch the line at logout.<br />
<br />
===MPD & ALSA===<br />
Sometimes, when you use other audio output, e.g: some web pages containing Flash applets, MPD cannot reproduce anything anymore (until you restart). The error looks something like: (if you search the file {{Filename|/var/log/mpd/mpd.error}})<br />
<br />
Error opening alsa device "hw:0,0": Device or resource busy<br />
<br />
And here is the solution (dmix saving our life again). Apply these lines in your {{Filename|/etc/mpd.conf}}:<br />
<br />
<pre><br />
audio_output {<br />
type "alsa"<br />
name "Sound Card"<br />
options "dev=dmixer"<br />
device "plug:dmix"<br />
}<br />
</pre><br />
<br />
And then restart with {{Codeline|/etc/rc.d/mpd restart}}.<br />
<br />
Searching on Internet I found the reason for why that happens in Gentoo's wiki:<br />
* The sound card does not support hardware mixing (uses '''dmix''' plugin)<br />
* An application does not work with ALSA with it's default settings<br />
<br />
For a detailed description, it is recommended to take a look at [http://mpd.wikia.com/wiki/Alsa this] link. There you can find an example asound.conf which worked for me right out of the box.<br />
<br />
====High CPU usage with ALSA====<br />
When using MPD with ALSA, users may experience MPD taking up lots of CPU (around 20-30%). This is caused by most sound cards supporting 48kHz and most music being 44kHz, thus forcing MPD to resample it. This operation takes lots of CPU cycles and results into high usage.<br />
<br />
For most users the problem should be solved by telling MPD not to use resampling by adding {{Codeline|auto_resample "no"}} into audio_output-part of {{Filename|/etc/mpd.conf}}. This will degrade quality slightly, however.<br />
<br />
Example from {{Filename|mpd.conf}}:<br />
<br />
audio_output {<br />
type "alsa"<br />
name "My ALSA Device"<br />
auto_resample "no"<br />
}<br />
<br />
Although it may not give as drastic a speedup, enabling mmap may speed things up:<br />
<br />
audio_output {<br />
type "alsa"<br />
name "My ALSA Device"<br />
use_mmap "yes"<br />
}<br />
<br />
Some users might also want to tell dmix to use 44kHz as well. More info about tuning performance of your MPD can be found from: [http://mpd.wikia.com/wiki/Tuning MPD wiki]<br />
<br />
====Example configuration: Output with 44.1 KHz at e. g. 16 bit depth, multiple programs at once====<br />
<br />
''Why these formats?'' Because they are standard CDA, because ALSA on its own allows more than one program "to sound" only with dmix — whose resampling algorithm is inferior — and because dmix by default resamples anything lower to 48 KHz (or whatever higher format is playing at the time). Also, some get clicking sounds if at least {{Filename|mpd.conf}} is not changed this way.<br />
<br />
''What's the downside?'' These settings cause ''everything'' (if necessary) to be resampled to this format, such as material from DVD or TV which usually is at 48 KHz. But there is no known way to have ALSA dynamically change the format, and particularly if you listen to far more CDs than anything else the occasional 48 → 44.1 isn't too great a loss.<br />
<br />
The following assumes that there are not already other settings which conflict resp. overwrite it. This applies especially to the current user's potential {{Filename|~/.asoundrc}} — which MPD as its own user ignores, therefore the following should go to {{Filename|/etc/asound.conf}}:<br />
<br />
{{File|name=/etc/asound.conf|content=<br />
defaults.pcm.dmix.rate 44100 # Force 44.1 KHz<br />
defaults.pcm.dmix.format S16_LE # Force 16 bits<br />
}}<br />
<br />
{{File|name=/etc/mpd.conf|content=<br />
audio_output {<br />
type "alsa" # Use the ALSA output plugin.<br />
name "HDA Intel" # Can be called anything or nothing tmk, but must be present.<br />
options "dev=dmixer"<br />
device "plug:dmix" # Both lines cause MPD to output to dmix.<br />
format "44100:16:2" # the actual format<br />
auto_resample "no" # This bypasses ALSA's own algorithms, which generally are inferior. See below how to choose a different one.<br />
use_mmap "yes" # Minor speed improvement, should work with all modern cards.<br />
}<br />
<br />
samplerate_converter "0" # MPD's best, most CPU intensive algorithm. See 'man mpd.conf' for others — for anything other than the poorest "internal", libsamplerate must be installed.<br />
}}<br />
<br />
{{Note|MPD gives the mp3 format a special treatment at decoding: It's always outputted as 24 bit. (The conversion as forced by the ''format'' line only comes after that.)}}<br />
<br />
If one wants to leave the bit depth decision to ALSA resp. MPD, comment out resp. omit the ''dmix.format'' line and change the one for mpd with ''format'' to "44100:*:2".<br />
<br />
{{Note|''Crossfading'' between files decoded at two different bit depths (say, one mp3 and one 16 bit flac) does not work unless conversion is active.}}<br />
<br />
===Control MPD with lirc===<br />
There are already some clients designed for communications between lircd and MPD, however, as far as the practical use, they aren't very useful since their functions are limited.<br />
<br />
It's recommended to use mpc with irexec. mpc is a command line player which only sends the command to MPD and exits immediately, which is perfect for irexec, the command runner included in lirc. What irexec does is that it runs a specified command once received a remote control button.<br />
<br />
First of all, please setup your remotes as referred to the '''[[Lirc]]''' article.<br />
<br />
Edit your favored lirc startup configuration file, default location is {{Filename|~/.lircrc}}.<br />
<br />
Fill the file with the following pattern:<br />
begin<br />
prog = irexec<br />
button = <button_name><br />
config = <command_to_run><br />
repeat = <0 or 1><br />
end<br />
<br />
An useful example:<br />
## irexec<br />
begin<br />
prog = irexec<br />
button = play_pause<br />
config = mpc toggle<br />
repeat = 0<br />
end<br />
<br />
begin<br />
prog = irexec<br />
button = stop<br />
config = mpc stop<br />
repeat = 0<br />
end<br />
begin<br />
prog = irexec<br />
button = previous<br />
config = mpc prev<br />
repeat = 0<br />
end<br />
begin<br />
prog = irexec<br />
button = next<br />
config = mpc next<br />
repeat = 0<br />
end<br />
begin<br />
prog = irexec<br />
button = volup<br />
config = mpc volume +2<br />
repeat = 1<br />
end<br />
begin<br />
prog = irexec<br />
button = voldown<br />
config = mpc volume -2<br />
repeat = 1<br />
end<br />
begin<br />
prog = irexec<br />
button = pbc<br />
config = mpc random<br />
repeat = 0<br />
end<br />
begin<br />
prog = irexec<br />
button = pdvd<br />
config = mpc update<br />
repeat = 0<br />
end<br />
begin<br />
prog = irexec<br />
button = right<br />
config = mpc seek +00:00:05<br />
repeat = 0<br />
end<br />
begin<br />
prog = irexec<br />
button = left<br />
config = mpc seek -00:00:05<br />
repeat = 0<br />
end<br />
begin<br />
prog = irexec<br />
button = up<br />
config = mpc seek +1%<br />
repeat = 0<br />
end<br />
begin<br />
prog = irexec<br />
button = down<br />
config = mpc seek -1%<br />
repeat = 0<br />
end<br />
<br />
There are more functions for mpc, run {{Codeline|man mpc}} for more info.<br />
<br />
===Control MPD with bluetooth phone===<br />
You can also control MPD (to a certain extent) using a bluetooth enabled phone. You need to do the following:<br />
<br />
* install [http://remuco.sourceforge.net/index.php/Remuco remuco] -- a wireless remote control for several Linux media players ([http://aur.archlinux.org/packages.php?ID=25072 aur])<br />
* transfer remuco client -- jar/jad files from {{Filename|/usr/share/remuco/client/}} to your phone and install it<br />
* run {{Codeline|remuco-mpd}} (as current user)<br />
* run remuco on your phone, define a new bluetooth remuco connection (pair first if you haven't done this previously) and explore its capabilities<br />
<br />
More information about remuco including troubleshooting to be found at its [http://remuco.sourceforge.net/index.php/Remuco homepage]<br />
<br />
===MPD & PulseAudio===<br />
<br />
Edit {{Filename|/etc/mpd.conf}}, and uncomment the audio_output section for the type "pulse". The server and sink lines of it should be commented unless you know what you're doing.<br />
<br />
Then, add the mpd user (and yours if you haven't done so already) to the necessary pulse groups. The pulse-access group should be sufficient but you may want to add pulse-rt as well. The group "pulse" doesn't appear to be necessary.<br />
# gpasswd -a mpd pulse-access<br />
# gpasswd -a mpd pulse-rt<br />
<br />
Lastly, you may or may not need to copy {{Filename|~/.pulse-cookie}} from your current (pulse working) user's dir to your mpd user's home directory. It is likely to be {{Filename|/var/lib/mpd}} if you followed the first part of this wiki. This would probably only allow your current user to listen in on MPD's pulse. You may consider running pulse system-wide if that's insufficient.<br />
<br />
===Cue Files===<br />
<br />
To make cue file support actually work, you have to work around a nasty libcue bug. Libcue copied some files directly from libcdio, making it conflict with it. Steps to do to get proper cue support:<br />
<br />
* remove libcdio temporary (pacman -Rdd libcdio)<br />
* install libcue (pacman -S libcue)<br />
* install mpd with abs or from aur.<br />
* reinstall libcdio (pacman -S libcdio)<br />
<br />
At the point of writing mpd does not parse tracknumbers from cue sheets. There is a patch available (http://musicpd.org/mantis/view.php?id=3230)<br />
Once this patch is merged into mpd, i will remove this line :)<br />
<br />
==Troubleshooting==<br />
===Autodetection failed===<br />
During the start of MPD, it tries to autodetect your set-up and configure output and volume control accordingly. Though this mostly goes well, it will fail for some systems. It may help to tell MPD specifically what to use as output and mixer control. If you copied {{Filename|/etc/mpd.conf}} over from {{Filename|/etc/mpd.conf.example}} as mentioned above, you can simply uncomment:<br />
<br />
Example for alsa output type:<br />
audio_output {<br />
type "alsa"<br />
name "My ALSA Device"<br />
device "hw:0,0" # optional<br />
format "44100:16:2" # optional<br />
}<br />
<br />
Example for alsa mixer:<br />
mixer_type "alsa"<br />
mixer_device "default"<br />
mixer_control "PCM"<br />
<br />
'''Note:''' in case of permission problems when using ESD with MPD run this as root:<br />
# chsh -s /bin/true mpd<br />
<br />
===Executable permissions===<br />
{{Warning|This is not good security practice and may be unnecessary.}}<br />
<br />
MPD needs to have +x permissions on '''ALL''' parent directories to your music collection (ie. if it's located outside of "mpd" home directory /var/lib/mpd). By default useradd sets permissions on home dir to 1700 drwx------. So if you're like me you will need to change permissions of /home/user. Example... my music collection is located /home/user/music. <br />
# chmod a+x /home/$USER<br />
# chmod -R a+X /home/$USER/music<br />
<br />
====Alternative solution====<br />
An alternative solution would be to use your group to share a selection of files, among them your music library. First remove all permissions for the group then add group permissions to read and execute home and music.<br />
# chmod -R g-rwx /home/$USER<br />
# chmod g+rx /home/$USER<br />
# chmod -R g+rX /home/$USER/music<br />
<br />
====Another alternative solution====<br />
Another alternative is to remount the music directory under a directory that mpd has access to. This does not entail the same security risks as modifying the permissions on one's home directory.<br />
# mkdir /var/lib/mpd/music<br />
# echo "/home/$USER/music /var/lib/mpd/music none bind" >> /etc/fstab<br />
# mount -a<br />
# /etc/rc.d/mpd restart<br />
And that should fix the problem. See also [https://bbs.archlinux.org/viewtopic.php?id=86449 the forum thread.]<br />
<br />
===Avoiding timeouts===<br />
To get rid of timeouts (i.e. when you paused music for long time) in gpmc and other clients uncomment and increase {{Codeline|connection_timeout}} option in {{Filename|mpd.conf}}.<br />
<br />
If files and/or titles are shown in wrong encoding, uncomment and change {{Codeline|filesystem_charset}} and {{Codeline|id3v1_encoding}} options.<br />
Note that you cannot set encoding for ID3 v2 tags. To workaround this you may use [http://mpd.wikia.com/wiki/GenericDecoder#Generic_Tagreader external tag readers].<br />
<br />
If you want to use another computer to control MPD over a network, the {{Codeline|bind_to_address}} option in {{Filename|mpd.conf}} will need to be set to either your IP address, or {{Codeline|any}} if your IP address changes frequently. Remember to add mpd to the {{Filename|/etc/hosts.allow}} file to enable external access.<br />
<br />
'''Streaming'''<br><br />
With the latest version of MPD (0.15), built-in httpd streaming is now available.<br />
<br />
To activate this feature, you'll just need to add a new output of type httpd in {{Filename|mpd.conf}}:<br />
audio_output {<br />
type "httpd"<br />
name "What you want"<br />
encoder "lame" # vorbis or lame supported<br />
port "8000"<br />
bitrate "128"<br />
format "44100:16:2" # change 2 to 1 for mono<br />
}<br />
<br />
Restart the mpd deamon and, from another computer, simply load the stream as any other url. <br />
$ mplayer http://<server's IP>:8000<br />
<br />
{{Note | You must open the port on your router / firewall for the stream to be connectible to from another computer.}}<br />
<br />
Most players (i.e. vlc or xmms2) should also be able to load the stream via their "add url..." menu option.<br />
<br />
This is a nice clean way to replace your current icecast setup with something natively supported within MPD.<br />
<br />
===mpd hangs on first startup===<br />
This is a common error that's caused by corrupt mp3 tags.<br />
Here is an experimental way to solve this issue.<br />
Requirements:<br />
* kid3<br />
* easytag<br />
<br />
This method is very tedious, especially with a huge database. Just as a baseline it took 2.5h to fix a 16Gb DB.<br />
<br />
====Easy Tag====<br />
The purpose of easytag here is that easytag detects the error in the tags, but like MPD it hangs and dies. The trick here is that easy tags actually tells you what file is causing the problem on the status bar.<br />
Before starting easytag make sure to have a terminal close to be ready to kill easy tag to avoid a hang. Once you are ready, on the tree view select the directory where all your music is located. By default easytag starts to search all subdirectories for mp3 files. Once you notice that easytag stopped scanning for songs, make note of the culprit and kill easytag.<br />
<br />
====KID3====<br />
Here's where kid3 comes in handy. With kid3 go to the offending song and rewrite one of the tags. then save the file. This should force kid3 to rewrite the whole tag again fixing the problem with MPD and easy tag hanging.<br />
<br />
Repeat this procedure until your music library is done.<br />
<br />
===Cannot connect to mpd: host "localhost" not found: Temporary failure in name resolution===<br />
Cannot connect to MPD (with ncmpcpp), if you are disconnected from network. Solution is [[IPv6 - Disabling the Module|disable IPv6]] or add line to /etc/hosts<br />
::1 localhost.localdomain localhost<br />
<br />
===Other issues when attempting to connect to mpd with a client===<br />
Some have reported being unable to access mpd with various clients, for example seeing errors like these:<br />
$ ncmpcpp<br />
Cannot connect to mpd: Connection closed by the server<br />
$ sonata<br />
2011-02-13 18:33:05 Connection lost while reading MPD hello<br />
2011-02-13 18:33:05 Not connected<br />
2011-02-13 18:33:05 Not connected<br />
<br />
Please see posts on ncmpcpp on the Arch Forums [https://bbs.archlinux.org/viewtopic.php?id=109962 HERE] and [https://bbs.archlinux.org/viewtopic.php?id=113493 HERE]. Also see the Arch bug report on this issue [https://bugs.archlinux.org/task/22071 HERE]. <br />
<br />
====First fix====<br />
Your first resort should be adding the following to /etc/hosts.allow.<br />
<br />
{{File|name=/etc/hosts.allow|content=mod: ALL}}.<br />
<br />
====Second fix====<br />
Check {{Filename|mpd.conf}} for a line like {{Codeline|mpd.error}} and remove it. The mpd error file is deprecated and has been removed.<br />
<br />
====Third fix====<br />
{{Note|I'm not so sure this is a good idea. There is a warning about changing the address to bind to in the default mpd.conf. If this does not help, you might want to comment out the changes.}}<br />
If that doesn't help, add the following to {{Filename|mpd.conf}}:<br />
<pre><br />
bind_to_address "127.0.0.1"<br />
port "6600"<br />
</pre><br />
<br />
Afterwards, instruct your client to connect via 127.0.0.1. For example, add the following to the ncmpcpp config file:<br />
<pre><br />
mpd_host "127.0.0.1"<br />
mpd_port "6600"<br />
</pre><br />
<br />
<br />
<br />
====Forth fix====<br />
{{Note|This fix only applies to users of manually compiled mpd or the AUR package mpd-git}}<br />
The final possible solution is simply compiling mpd without libwrap support. Install mpd-git as usual, but edit the PKGBUILD and search for <br />
<pre><br />
--with-zeroconf=no <br />
</pre><br />
<br />
and replace it with <br />
<pre><br />
--with-zeroconf=no \<br />
--disable-libwrap<br />
</pre><br />
<br />
===Port 6600 already in use===<br />
MPD needs to bind to port 6600 and cannot start if it's already in use. The most common reason for this is that the user has started MPD once and then subsequently tried to start mpd again. In general, nothing should be done here.<br />
<br />
If port 6600 is tied up for some other reason, one can use the following command to find the offending process:<br />
# netstat -tulpan | grep 6600<br />
<br />
This will list IP:Port and the process name holding the connection (root privileges are required to see all processes).<br />
<br />
If you need to restart mpd for whatever reason, use:<br />
<pre><br />
$ mpd --kill<br />
$ mpd <br />
</pre><br />
A more brute-force approach:<br />
<pre><br />
$ killall mpd<br />
$ mpd <br />
</pre><br />
{{Note| If you typically run MPD as root, you will need to run the above commands as root.}}<br />
<br />
In the latest version of MPD, --create-db is completely deprecated. The database will be created automagically on first run and can subsequently be updated via your client (i.e. mpc update). You can now use inotify support to automatically update your music database. Add the following to {{File|name=mpd.conf|content=auto_update "yes"}} to enable it.<br />
<br />
<br />
===Crackling sound with some audio files===<br />
This is usually a playback speed problem and can be fixed by uncommenting the audio_output_format line in:<br />
<br />
{{File|name=/etc/mpd.conf|content=<br />
audio_output_format "44100:16:2"}}<br />
<br />
This is usually a sane value for most mp3 files.<br />
<br />
===daemon: cannot setgid for user "mpd": Operation not permitted ===<br />
<br />
The error is stating that the user starting the process (you) does not have permissions to become another user (mpd) which the configuration has told that process to run as.<br />
<br />
To solve the issue, simply start mpd as root.<br />
su -c "/etc/rc.d/mpd start"<br />
or<br />
sudo /etc/rc.d/mpd start<br />
<br />
==External links==<br />
* [http://www.musicpd.org/ Official Web Site]<br />
* [http://mpd.wikia.com/wiki/Main_Page Official Wiki]<br />
* [http://mpd.wikia.com/wiki/Clients Sorted List of MPD Clients]<br />
* [http://www.musicpd.org/forum/ MPD forum]</div>Rasihttps://wiki.archlinux.org/index.php?title=Kernel_Panics&diff=77514Kernel Panics2009-10-11T09:08:48Z<p>Rasi: /* Definition */</p>
<hr />
<div>[[Category: System recovery (English)]]<br />
[[Category:HOWTOs (English)]]<br />
[[Category:Kernel (English)]]<br />
<br />
{{i18n_links_start}}<br />
{{i18n_entry|Česky|:Kernel Panics (Česky)}}<br />
{{i18n_entry|English|:Kernel Panics}}<br />
{{i18n_entry|Español|:Kernel Panics (Español)}}<br />
{{i18n_entry|Italiano|:Kernel Panics (Italiano)}}<br />
{{i18n_entry|Français|:Kernel Panics (francais)}}<br />
{{i18n_entry|简体中文|:Kernel Panics (简体中文)}}<br />
{{i18n_entry|Ελληνικά|:Kernel Panics (Ελληνικά)}}<br />
{{i18n_entry|Türkçe|:Çekirdek Hataları}}<br />
{{i18n_entry|日本語|:Kernel Panics (日本語)}}<br />
{{i18n_links_end}}<br />
<br />
This page describes how to repair a computer whose kernel panics at boot. This has to do with the very basic OS kernel and the first part of the boot routine. (For issues regarding graphical interface problems or program freeze-ups, etc., save yourself some wasted effort and time, and please look elsewhere.)<br />
<br />
==Definition==<br />
A decent definition of Kernel Panic comes to us from Wikipedia, which states in part; "A kernel panic is an action taken by an operating system upon detecting an internal fatal error from which it cannot safely recover; the term is largely specific to Unix and Unix-like systems. The equivalent in Microsoft Windows operating systems is the Blue Screen of Death." Read more by following this link: [http://en.wikipedia.org/wiki/Kernel_panic Kernel Panic]<br />
<br />
==What To Do==<br />
Basically, the problem is that the operating system doesn't start correctly. Various behavior may be expressed, such as that one may get the computer to freeze, or the operating system may give an error message of some sort or one may not go to the place they were expecting (Command prompt, Desktop or whathaveyou). This will require some basic troubleshooting from the command line, if you can boot to it, or from a boot disk if it will get you a command prompt or your favorite interface.<br />
<br />
==Troubleshooting==<br />
To make troubleshooting easier, ensure that the kernel is not in quiet mode. Remove 'quiet' from the kernel line in GRUB, if it is found there. Upon boot, check the output immediately before the panic, and decide whether there is any useful information. There are probably too many causes for a kernel panic to keep well-documented in this wiki. Make sure that your system's configuration in /boot is correct, and that none of the computer's hardware is faulty - it is good idea to run memtest from the Arch install/rescue CD or another utility (red entries are bad). If you believe the configuration in /boot may be erroneous, try Option 1 to repair your bootloader setup. If you believe the kernel panic is the fault of the kernel itself, follow Option 2 in order to reinstall the existing version or an earlier kernel.<br />
<br />
==Option 1: Check bootloader configuration==<br />
Another possibility is an error in the bootloader's configuration (e.g. <tt>/boot/grub/menu.lst</tt>). For example, repartitioning hard drives can change partitions' order. GRUB users may recall whether repartitioning has occurred recently and make sure the ''root'' and ''kernel'' lines match up with the new partitioning scheme. And examine the file for typos and extraneous characters. An extra space, or a character in the wrong place will cause a kernel panic.<br />
<br />
==Option 2: Reinstall kernel==<br />
Reinstalling the kernel is probably the best bet when no other major system modifications have taken place recently.<br />
<br />
===Start from the installation CD===<br />
The first step is booting the installation CD. When started, type arch, like you would when installing arch.<br />
# arch<br />
<br />
===Chroot to your normal root===<br />
When booted, you are in a minimal but functional live GNU/Linux environment with some basic tools.<br />
Now, you have to mount your normal root disk to /mnt.<br />
# mount /dev/sdXY /mnt<br />
If you use a boot partition, don't forget to mount it<br />
# mount /dev/sdXZ /mnt/boot<br />
<br />
Newer kernels use an initial ramdisk to set up the kernel environment. When you reinstall a kernel, that initial ramdisk will be regenerated with mkinitcpio. One of mkinitcpio's features is that it does autodetection to find out what kernel modules are required for starting up your computer. For this autodetection to work, /dev, /sys and /proc need to mounted in your chroot:<br />
<br />
# mount -t proc none /mnt/proc<br />
# mount -t sysfs none /mnt/sys<br />
# mount --bind /dev /mnt/dev<br />
<br />
Now, we will chroot to this disk:<br />
# chroot /mnt<br />
<br />
===Roll back to previous kernel version===<br />
If you keep your downloaded pacman packages, you now can easily roll back. If you didn't keep them, you have to find a way to get a previous kernel version on your system now.<br />
<br />
Let's suppose you keep the previous versions. We will now install the last working one.<br />
# pacman -U /var/cache/pacman/pkg/kernel26-2.6.23.''xx-x''.pkg.tar.gz<br />
Of course, make sure that you adapt this line to your own kernel version.<br />
<br />
Otherwise, check the install CD for a package. For example, the version 2008.06 i686 CD contains addons/core-pkgs/kernel26-2.6.25.6-1-i686.pkg.tar.gz.<br />
<br />
==Reboot==<br />
Now is the time to reboot and see if the system modifications have stopped the panic.<br />
If reverting to an older kernel works, don't forget to check the arch-newspage to check what went wrong with the kernel build.</div>Rasihttps://wiki.archlinux.org/index.php?title=Subtle&diff=71386Subtle2009-06-29T14:31:15Z<p>Rasi: /* Introduction */</p>
<hr />
<div>[[Category:Desktop environments (English)]]<br />
[[Category:HOWTOs (English)]]<br />
<br />
== Introduction ==<br />
<br />
[http://unexist.scrapping.cc/projects/show/subtle Subtle] is another tiling window manager with a very flexible and <br />
dynamical layout, client and view tagging, mouse and keyboard control <br />
as well as an extendable statusbar.<br />
<br />
== Installation ==<br />
<br />
* Install subtle from [http://aur.archlinux.org/packages.php?ID=13016 AUR].<br />
* If you prefer bleeding edge you can check out the latest version from the [http://unexist.scrapping.cc/wiki/subtle/Install mercurial repository].<br />
<br />
== Configuration ==<br />
<br />
On start subtle will check if a config file is available in the typical XDG paths and use it. A local config is preferred over a system wide. (See {{Codeline|$XDG_CONFIG_HOME}}) <br />
<br />
Then it will have a look for sublets in the XDG paths too and load them accordingly. (See {{Codeline|$XDG_DATA_HOME}})<br />
<br />
No system wide [http://unexist.scrapping.cc/wiki/subtle/Sublets sublets] will be loaded per default.<br />
* To create a user config just create ''$XDG_CONFIG_HOME/subtle'' and copy the latest config from the dist folder into it.<br />
* To enable sublets create ''$XDG_DATA_HOME/subtle/sublets'' and create symlinks to the sublets. (Load order is '''alphabetically''')<br />
<br />
Always compare your existing config with the one of the repository/tarball to get the latest options.<br />
<br />
This and more info can be found on the [http://unexist.scrapping.cc/projects/show/subtle subtle website].<br />
<br />
== Contact ==<br />
<br />
If you have problems, suggestions or just want to talk about [http://unexist.scrapping.cc/projects/show/subtle subtle] feel free to join '''#subtle''' on '''irc.freenode.org''' or drop a mail to _unexist_ at _dorfelite_ dot _net_.</div>Rasihttps://wiki.archlinux.org/index.php?title=Open_Sound_System&diff=66926Open Sound System2009-04-16T08:39:50Z<p>Rasi: /* OSS and KDE4 */</p>
<hr />
<div>[[Category:Sound (English)]]<br />
[[Category:Audio/Video (English)]]<br />
[[Category:HOWTOs (English)]]<br />
{{i18n_links_start}}<br />
{{i18n_entry|English|OSS}}<br />
{{i18n_entry|简体中文|OSS (简体中文)}}<br />
{{i18n_entry|Türkçe|OSS (Türkçe)}}<br />
{{i18n_links_end}}<br />
<br />
= Introduction =<br />
The [http://developer.opensound.com Open Sound System] is a [http://4front-tech.com commercially-supported] sound architecture that works on several UNIX-like and POSIX-compatible systems, including Linux, FreeBSD, Solaris and BeOS/Haiku.<br />
<br />
Please note that this article is not about the old OSS, which is included in the Linux kernel sources and is more than 10 years old by now.<br />
<br />
This article is about the new OSS versions (often called OSSv4). These versions were previously proprietary - OSS became open source again in July 2007, and is currently available under GPL, BSD or CDDL licenses.<br />
<br />
= Advantages and disadvantages vs. ALSA =<br />
<br />
== Advantages over ALSA (for users) ==<br />
* Includes a transparent software mixer (vmix) in kernel space. This means multiple applications can access the sound device at the same time without problems.<br />
* The vmix mixer controls allow you to adjust the volume of each application individually.<br />
* Better support for some sound card models, for example for the Creative X-Fi.<br />
* Sound quality is usually better.<br />
* Better support for applications written for the OSS API, of course. The OSS API is widely spread and a lot of applications support it. The ALSA's OSS API emulation, however, is often buggy.<br />
<br />
== Advantages over ALSA (for developers) ==<br />
* Cleaner and easier to use API.<br />
* API is much better [http://manuals.opensound.com/developer documented].<br />
* Support for sound drivers in the userspace (oss_userdev).<br />
* Portability across all supported platforms. If the application works using OSS under Linux, it will work under FreeBSD and Solaris too, for example.<br />
* Portability across operating systems. It's [http://revolf.free.fr/Alchimie-7/Alchimie7_OSS_Haiku.en.pdf easier] to port OSS to a new operating system.<br />
<br />
== Disadvantages vs. ALSA ==<br />
* USB audio devices support is currently experimental under Linux.<br />
* Bluetooth audio devices are currently not supported.<br />
* AC'97 and HDAudio dial-up soft-modems (for example Si3055) are currently not supported.<br />
* MIDI support is currently not finished. However, you can still use MIDI with a software synthesizer like timidity or fluidsynth.<br />
* Suspend is currently not supported. You need to unload OSS (by using <tt>soundoff</tt>) before suspending, and to reload OSS (by using <tt>soundon</tt>) after resuming.<br />
* Automatic jack sensing currently doesn't work properly with '''some''' HDAudio-powered motherboards. This means that, depending on your motherboard model, you may have to manually switch off your speakers when plugging your earphone.<br />
<br />
= Installing =<br />
<br />
* Disable ALSA by blocking the <tt>soundcore</tt> module in <tt>/etc/rc.conf</tt>:<br />
<br />
MODULES=(!soundcore ..............<br />
<br />
And by rebooting.<br />
<br />
If you didn't want to reboot, you could also quit your desktop environment (if any) to free the soundcard, and go to pure console for doing the next steps.<br />
<br />
* Install OSS by running:<br />
<br />
# pacman -S oss<br />
<br />
* Start OSS by running:<br />
<br />
# /etc/rc.d/oss start<br />
<br />
* Add <tt>oss</tt> to your <tt>DAEMONS</tt> variable at <tt>/etc/rc.conf</tt>, so OSS is loaded automatically at each boot.<br />
<br />
* In the case OSS is not able to detect your card when starting it, run :<br />
<br />
# ossdetect -v<br />
<br />
Then <tt>soundoff && soundon</tt> to reactivate it.<br />
<br />
<br />
Note: The above instructions will currently install OSS 4.1. If you want OSS 4.0, you can still find it at [http://aur.archlinux.org/packages.php?ID=23383 AUR].<br />
<br />
= Testing =<br />
<br />
You can test OSS by running:<br />
<br />
$ osstest<br />
<br />
{{Box Note| Beware the default volume is very loud. Avoid using earphones or lower the volume by using <tt>ossxmix</tt>. }}<br />
<br />
You should be able to hear music during the test process. If there is no audio, try to adjust the mixer as explained in the following sections and/or read the Troubleshooting sections.<br />
<br />
= The mixer =<br />
<br />
The command line mixer is called <tt>ossmix</tt>. It's very like the BSD audio mixer (<tt>mixerctl</tt>).<br />
<br />
A more friendly, graphical mixer, is available too. It's called <tt>ossxmix</tt>. It needs the optional depend <tt>gtk2</tt> to work.<br />
<br />
The <tt>ossxmix</tt> controls are explained in the following example:<br />
<br />
______________________________<br />
/ High Definition Audio ALC262 \ ----------------------------------> One tab for each sound card<br />
/________________________________\_______________________________<br />
|<br />
| [x] vmix0-enable [vmix0-rate: 48.000kHz] vmix0-channels \ The vmix (virtual mixer) special configurations<br />
| [ Stereo [v] ] |--> appear at the top. These include sampling rate<br />
| / and mixer priority. They are provided by OSS.<br />
| __codec1______________________________________________________ <br />
| | _jack_______________________________________________________ \ <br />
| | | _int-speaker____________________ __green_________________ |<br />
| | | | | | | These are your sound card configurations.<br />
| | | | _mode______ | | | | _mode______ | | | Every mixer control that is shown here is<br />
| | | | [ mix [v] ] o o [x] [ ]mute | | [ mix [v] ] o o [x] |--> provided by your sound card. Every sound card<br />
| | | | | | | | | | | specific control is shown here.<br />
| | | |________________________________| |_______________________ |<br />
| | |____________________________________________________________ |<br />
| |______________________________________________________________ /<br />
|<br />
| ___vmix0_______________________________________________________ \<br />
| | __mocp___ O O _firefox_ O O __pcm7___ O O | Here are the vmix mixer controls. These are<br />
| | | | O O | | x x | | O O | virtual mixer controls provided by OSS. Each<br />
| | | | | | x O | | | | x x | | | | O O | slider is the volume control of a different<br />
| | | o o [x] | x x | o o [x] | x x | o o [x] | O O |--> application. When one application uses the<br />
| | | | | | x x | | | | x x | | | | O O | sound card, its name is shown in the place of<br />
| | |_________| x x |_________| x x |_________| O O | the 'pcm#' labels. There are also sound level<br />
| |______________________________________________________________ | meter levels for each application.<br />
|________________________________________________________________ /<br />
<br />
=== Saving and restoring mixer settings ===<br />
<br />
If you wish to save your mixer settings manually, run <tt>savemixer</tt>. You will require to be a user with write permissions to <tt>/usr/lib/oss/etc/save.mixer</tt> or you'll need to use the <tt>-f</tt> switch to select another file. <tt>savemixer -L</tt> restores mixer settings.<br />
<br />
Please note that the init scripts run these commands before shutdown/after starting to keep mixer settings across boot, so most users don't need to worry about it.<br />
<br />
= Configuring Applications for OSS =<br />
<br />
== Skype ==<br />
<br />
The <tt>skype</tt> package only includes support for ALSA. To get an OSS-capable Skype, install the <tt>skype-oss</tt> package:<br />
<br />
pacman -S skype-oss<br />
<br />
If you are using x86_64, you can get the [http://aur.archlinux.org/packages.php?ID=18312 bin32-skype-oss] package from AUR.<br />
<br />
== Wine ==<br />
<br />
* Run <tt>winecfg</tt>.<br />
<br />
winecfg<br />
<br />
* Go to the <tt>Audio</tt> tab.<br />
<br />
* Select <tt>OSS Driver</tt>.<br />
<br />
== Other applications ==<br />
<br />
* If you can't get sound from an application not listed here, try looking at the [http://www.4front-tech.com/wiki/index.php/Configuring_Applications_for_OSSv4 Configuring Applications for OSSv4] page.<br />
* Search OSS specific packages by using <tt>pacman -Ss -- '-oss'</tt> and [http://aur.archlinux.org/packages.php?K=-oss&start=0&PP=100| in AUR].<br />
<br />
= Troubleshooting =<br />
<br />
== Troubleshooting HDAudio devices ==<br />
<br />
=== Understanding why problems arise ===<br />
<br />
If you have a HDAudio sound device, it's very likely that you will have to adjust some mixer settings before your sound works.<br />
<br />
HDAudio devices are very powerful in the sense that they can contain a lot of small circuits (called ''widgets'') that can be adjusted by software at any time. These controls are exposed to the mixer, and they can be used, for example, to turn the earphone jack into a sound input jack instead of a sound output jack.<br />
<br />
However, there is a side effect, mainly because the HDAudio standard is more flexible than it perhaps should be, and because the vendors often only care to get their ''official drivers'' working.<br />
<br />
Then, when using HDAudio devices, you often find disorganized mixer controls, that doesn't work at all by default, and you are forced to try every mixer control combination, until it works.<br />
<br />
=== How to solve ===<br />
<br />
Open <tt>ossxmix</tt> and try to change every mixer control in the ''middle area'', that contains the sound card specific controls, as explained in the previous "[[OSS#The_mixer|The mixer]]" section.<br />
<br />
You'll probably want to setup a program to record/play continously in the background (e.g. <tt>ossrecord - | ossplay -</tt> for recording or <tt>osstest -lV</tt> for playing), while changing mixer settings in ossxmix in the foreground.<br />
<br />
* Raise every volume control slider.<br />
* In each option box, try to change the selected option, trying all the possible combinations.<br />
* If you get noise, try to lower and/or mute some volume controls, until you find the source of the noise.<br />
<br />
Please note again that you do '''not''' need to change any controls in the ''top area'' nor in the ''bottom area'', as they are virtual <tt>vmix</tt>-related mixer controls.<br />
<br />
== Troubleshooting other issues ==<br />
<br />
* If you get distorted sound, try lowering some volume control sliders.<br />
<br />
* If you need to change the default sound card, look at [http://www.opensound.com/wiki/index.php/Tips_And_Tricks#Changing_the_default_sound_output here].<br />
<br />
* If you have another issues, try searching or asking for help at the [http://www.4front-tech.com/forum 4front forums].<br />
<br />
= Tips and Tricks =<br />
<br />
== Using multimedia keys with OSS ==<br />
An easy way to mute/unmute and increase/decrease the volume is to use the [http://www.opensound.com/wiki/index.php/Tips_And_Tricks#ossvol {{Codeline|ossvol}} script]. It is available in [[AUR]].<br />
<br />
Once you installed it try to toggle the sound:<br />
ossvol -t<br />
<br />
Type {{Codeline|ossvol -h}} for the other commands.<br />
<br />
If you don't know how to assign commands to your multimedia keys, see [[Extra Keyboard Keys]].<br />
<br />
==={{Codeline|ossvol}} troubleshooting===<br />
If you get an error like:<br />
Bad mixer control name(987) 'vol'<br />
you need to edit the script ({{Filename|/usr/bin/ossvol}}) and change the value of the {{Codeline|CHANNEL}} variable which is at the beginning of the script. For example mine is {{Codeline|CHANNEL<nowiki>=</nowiki>"vmix0-outvol"}}.<br />
<br />
== Other tips ==<br />
<br />
* [http://www.opensound.com/wiki/index.php/Tips_And_Tricks#Starting_ossxmix_minimized_to_tray_on_desktop_startup Starting ossxmix minimized to tray on desktop startup].<br />
* [http://www.opensound.com/wiki/index.php/Tips_And_Tricks#Recording_sound_output_of_a_program Recording sound output of a program].<br />
<br />
== Laptop suspend and hibernation ==<br />
<br />
OSS does not automatically support suspend meaning that OSS must be manually stopped prior to suspending or hibernating a laptop.<br />
<br />
OSS provides <tt>soundon</tt> and <tt>soundoff</tt> to enable and disable OSS, although any processes that use sound must be terminated first.<br />
<br />
The following script is a rather basic method of automatically unloading OSS prior to suspending and reloading afterwards. This has been tested with KDE 4.2 but has not tried in other desktop environments.<br />
<br />
* Save the contents of this script (as root) into <tt>/usr/lib/pm-utils/sleep.d/50ossound</tt>:<br />
<br />
#!/bin/sh<br />
. "${PM_FUNCTIONS}"<br />
<br />
suspend_osssound()<br />
{<br />
/usr/lib/oss/scripts/killprocs.sh<br />
/usr/sbin/soundoff<br />
}<br />
<br />
resume_osssound()<br />
{<br />
/usr/sbin/soundon<br />
}<br />
<br />
case "$1" in<br />
hibernate|suspend)<br />
suspend_osssound<br />
;;<br />
thaw|resume)<br />
resume_osssound<br />
;;<br />
*) exit $NA<br />
;;<br />
esac<br />
<br />
The KDE notify daemon (which provides the system sounds) will automatically reload itself after being terminated by OSS. <br />
<br />
{{Box Note|This script is rather basic and will terminate any application directly accessing OSS, this means save your work prior to suspending your laptop.}}<br />
<br />
== ALSA emulation ==<br />
<br />
=== Introduction ===<br />
<br />
You can instruct <tt>alsa-lib</tt> to use OSS as its audio output system. This works as a sort of ALSA emulation.<br />
<br />
Note, however, that this method may introduce additional latency in your sound output, and that the emulation is not complete and doesn't work with all applications. It doesn't work, for example, with programs that try to detect devices using ALSA.<br />
<br />
So, as most applications support OSS directly, use this method only as a last resort.<br />
<br />
In the future, more complete methods may be available for emulating ALSA, such as <tt>libsalsa</tt> and <tt>cuckoo</tt>.<br />
<br />
=== HOW-TO ===<br />
<br />
* Install the <tt>alsa-plugins</tt> package.<br />
<br />
pacman -S alsa-plugins<br />
<br />
* Edit <tt>/etc/asound.conf</tt> as follows.<br />
<br />
pcm.oss {<br />
type oss<br />
device /dev/dsp<br />
}<br />
<br />
pcm.!default {<br />
type oss<br />
device /dev/dsp<br />
}<br />
<br />
ctl.oss {<br />
type oss<br />
device /dev/mixer<br />
}<br />
<br />
ctl.!default {<br />
type oss<br />
device /dev/mixer<br />
}<br />
<br />
{{Box Note| If you don't want to use OSS anymore, don't forget to revert changes that you do here in ''/etc/asound.conf'' .}}<br />
<br />
= Experimental packages =<br />
<br />
== Mercurial repository version ==<br />
<br />
There is a [http://aur.archlinux.org/packages.php?ID=21126 oss-mercurial package] in AUR. This package compiles and installs the latest OSS development version direcly from the Mercurial repository.<br />
<br />
You can try this package if you want to contribute code to OSS or if only a very recent change in OSS code introduced support to your sound device.<br />
<br />
= OSS and KDE4 =<br />
<br />
KDE4 in arch does not ship with the gstreamer backend, which is needed for OSS4 to work in this DE.<br />
To enable gstreamer support in phonon get the PKGBUILD with ABS. Install abs and run it as root.<br />
Then cp the phonon PKGBUILD.<br />
<br />
cp -a /var/abs/extra/phonon ~/abs/phonon<br />
<br />
cd into the new directory and open the PKGBUILD in your favorite editor.<br />
change<br />
<br />
-DWITH_GStreamer=OFF<br />
to<br />
-DWITH_GStreamer=ON<br />
<br />
now simply run makepkg and after a while you can install the resulting package with<br />
<br />
pacman -U phonon*.pkg.tar.gz<br />
<br />
Last but not least install the needed gstreamer packages with<br />
<br />
pacman -S gstreamer0.10-plugins<br />
<br />
In Systemsettings -> Multimedia select the Gstreamer backened which should enable your sound in KDE.<br />
<br />
<br />
Keep in mind that kmix does have sliders for applications-volume, so you have to use ossxmix to change those.</div>Rasihttps://wiki.archlinux.org/index.php?title=Open_Sound_System&diff=66925Open Sound System2009-04-16T08:36:46Z<p>Rasi: </p>
<hr />
<div>[[Category:Sound (English)]]<br />
[[Category:Audio/Video (English)]]<br />
[[Category:HOWTOs (English)]]<br />
{{i18n_links_start}}<br />
{{i18n_entry|English|OSS}}<br />
{{i18n_entry|简体中文|OSS (简体中文)}}<br />
{{i18n_entry|Türkçe|OSS (Türkçe)}}<br />
{{i18n_links_end}}<br />
<br />
= Introduction =<br />
The [http://developer.opensound.com Open Sound System] is a [http://4front-tech.com commercially-supported] sound architecture that works on several UNIX-like and POSIX-compatible systems, including Linux, FreeBSD, Solaris and BeOS/Haiku.<br />
<br />
Please note that this article is not about the old OSS, which is included in the Linux kernel sources and is more than 10 years old by now.<br />
<br />
This article is about the new OSS versions (often called OSSv4). These versions were previously proprietary - OSS became open source again in July 2007, and is currently available under GPL, BSD or CDDL licenses.<br />
<br />
= Advantages and disadvantages vs. ALSA =<br />
<br />
== Advantages over ALSA (for users) ==<br />
* Includes a transparent software mixer (vmix) in kernel space. This means multiple applications can access the sound device at the same time without problems.<br />
* The vmix mixer controls allow you to adjust the volume of each application individually.<br />
* Better support for some sound card models, for example for the Creative X-Fi.<br />
* Sound quality is usually better.<br />
* Better support for applications written for the OSS API, of course. The OSS API is widely spread and a lot of applications support it. The ALSA's OSS API emulation, however, is often buggy.<br />
<br />
== Advantages over ALSA (for developers) ==<br />
* Cleaner and easier to use API.<br />
* API is much better [http://manuals.opensound.com/developer documented].<br />
* Support for sound drivers in the userspace (oss_userdev).<br />
* Portability across all supported platforms. If the application works using OSS under Linux, it will work under FreeBSD and Solaris too, for example.<br />
* Portability across operating systems. It's [http://revolf.free.fr/Alchimie-7/Alchimie7_OSS_Haiku.en.pdf easier] to port OSS to a new operating system.<br />
<br />
== Disadvantages vs. ALSA ==<br />
* USB audio devices support is currently experimental under Linux.<br />
* Bluetooth audio devices are currently not supported.<br />
* AC'97 and HDAudio dial-up soft-modems (for example Si3055) are currently not supported.<br />
* MIDI support is currently not finished. However, you can still use MIDI with a software synthesizer like timidity or fluidsynth.<br />
* Suspend is currently not supported. You need to unload OSS (by using <tt>soundoff</tt>) before suspending, and to reload OSS (by using <tt>soundon</tt>) after resuming.<br />
* Automatic jack sensing currently doesn't work properly with '''some''' HDAudio-powered motherboards. This means that, depending on your motherboard model, you may have to manually switch off your speakers when plugging your earphone.<br />
<br />
= Installing =<br />
<br />
* Disable ALSA by blocking the <tt>soundcore</tt> module in <tt>/etc/rc.conf</tt>:<br />
<br />
MODULES=(!soundcore ..............<br />
<br />
And by rebooting.<br />
<br />
If you didn't want to reboot, you could also quit your desktop environment (if any) to free the soundcard, and go to pure console for doing the next steps.<br />
<br />
* Install OSS by running:<br />
<br />
# pacman -S oss<br />
<br />
* Start OSS by running:<br />
<br />
# /etc/rc.d/oss start<br />
<br />
* Add <tt>oss</tt> to your <tt>DAEMONS</tt> variable at <tt>/etc/rc.conf</tt>, so OSS is loaded automatically at each boot.<br />
<br />
* In the case OSS is not able to detect your card when starting it, run :<br />
<br />
# ossdetect -v<br />
<br />
Then <tt>soundoff && soundon</tt> to reactivate it.<br />
<br />
<br />
Note: The above instructions will currently install OSS 4.1. If you want OSS 4.0, you can still find it at [http://aur.archlinux.org/packages.php?ID=23383 AUR].<br />
<br />
= Testing =<br />
<br />
You can test OSS by running:<br />
<br />
$ osstest<br />
<br />
{{Box Note| Beware the default volume is very loud. Avoid using earphones or lower the volume by using <tt>ossxmix</tt>. }}<br />
<br />
You should be able to hear music during the test process. If there is no audio, try to adjust the mixer as explained in the following sections and/or read the Troubleshooting sections.<br />
<br />
= The mixer =<br />
<br />
The command line mixer is called <tt>ossmix</tt>. It's very like the BSD audio mixer (<tt>mixerctl</tt>).<br />
<br />
A more friendly, graphical mixer, is available too. It's called <tt>ossxmix</tt>. It needs the optional depend <tt>gtk2</tt> to work.<br />
<br />
The <tt>ossxmix</tt> controls are explained in the following example:<br />
<br />
______________________________<br />
/ High Definition Audio ALC262 \ ----------------------------------> One tab for each sound card<br />
/________________________________\_______________________________<br />
|<br />
| [x] vmix0-enable [vmix0-rate: 48.000kHz] vmix0-channels \ The vmix (virtual mixer) special configurations<br />
| [ Stereo [v] ] |--> appear at the top. These include sampling rate<br />
| / and mixer priority. They are provided by OSS.<br />
| __codec1______________________________________________________ <br />
| | _jack_______________________________________________________ \ <br />
| | | _int-speaker____________________ __green_________________ |<br />
| | | | | | | These are your sound card configurations.<br />
| | | | _mode______ | | | | _mode______ | | | Every mixer control that is shown here is<br />
| | | | [ mix [v] ] o o [x] [ ]mute | | [ mix [v] ] o o [x] |--> provided by your sound card. Every sound card<br />
| | | | | | | | | | | specific control is shown here.<br />
| | | |________________________________| |_______________________ |<br />
| | |____________________________________________________________ |<br />
| |______________________________________________________________ /<br />
|<br />
| ___vmix0_______________________________________________________ \<br />
| | __mocp___ O O _firefox_ O O __pcm7___ O O | Here are the vmix mixer controls. These are<br />
| | | | O O | | x x | | O O | virtual mixer controls provided by OSS. Each<br />
| | | | | | x O | | | | x x | | | | O O | slider is the volume control of a different<br />
| | | o o [x] | x x | o o [x] | x x | o o [x] | O O |--> application. When one application uses the<br />
| | | | | | x x | | | | x x | | | | O O | sound card, its name is shown in the place of<br />
| | |_________| x x |_________| x x |_________| O O | the 'pcm#' labels. There are also sound level<br />
| |______________________________________________________________ | meter levels for each application.<br />
|________________________________________________________________ /<br />
<br />
=== Saving and restoring mixer settings ===<br />
<br />
If you wish to save your mixer settings manually, run <tt>savemixer</tt>. You will require to be a user with write permissions to <tt>/usr/lib/oss/etc/save.mixer</tt> or you'll need to use the <tt>-f</tt> switch to select another file. <tt>savemixer -L</tt> restores mixer settings.<br />
<br />
Please note that the init scripts run these commands before shutdown/after starting to keep mixer settings across boot, so most users don't need to worry about it.<br />
<br />
= Configuring Applications for OSS =<br />
<br />
== Skype ==<br />
<br />
The <tt>skype</tt> package only includes support for ALSA. To get an OSS-capable Skype, install the <tt>skype-oss</tt> package:<br />
<br />
pacman -S skype-oss<br />
<br />
If you are using x86_64, you can get the [http://aur.archlinux.org/packages.php?ID=18312 bin32-skype-oss] package from AUR.<br />
<br />
== Wine ==<br />
<br />
* Run <tt>winecfg</tt>.<br />
<br />
winecfg<br />
<br />
* Go to the <tt>Audio</tt> tab.<br />
<br />
* Select <tt>OSS Driver</tt>.<br />
<br />
== Other applications ==<br />
<br />
* If you can't get sound from an application not listed here, try looking at the [http://www.4front-tech.com/wiki/index.php/Configuring_Applications_for_OSSv4 Configuring Applications for OSSv4] page.<br />
* Search OSS specific packages by using <tt>pacman -Ss -- '-oss'</tt> and [http://aur.archlinux.org/packages.php?K=-oss&start=0&PP=100| in AUR].<br />
<br />
= Troubleshooting =<br />
<br />
== Troubleshooting HDAudio devices ==<br />
<br />
=== Understanding why problems arise ===<br />
<br />
If you have a HDAudio sound device, it's very likely that you will have to adjust some mixer settings before your sound works.<br />
<br />
HDAudio devices are very powerful in the sense that they can contain a lot of small circuits (called ''widgets'') that can be adjusted by software at any time. These controls are exposed to the mixer, and they can be used, for example, to turn the earphone jack into a sound input jack instead of a sound output jack.<br />
<br />
However, there is a side effect, mainly because the HDAudio standard is more flexible than it perhaps should be, and because the vendors often only care to get their ''official drivers'' working.<br />
<br />
Then, when using HDAudio devices, you often find disorganized mixer controls, that doesn't work at all by default, and you are forced to try every mixer control combination, until it works.<br />
<br />
=== How to solve ===<br />
<br />
Open <tt>ossxmix</tt> and try to change every mixer control in the ''middle area'', that contains the sound card specific controls, as explained in the previous "[[OSS#The_mixer|The mixer]]" section.<br />
<br />
You'll probably want to setup a program to record/play continously in the background (e.g. <tt>ossrecord - | ossplay -</tt> for recording or <tt>osstest -lV</tt> for playing), while changing mixer settings in ossxmix in the foreground.<br />
<br />
* Raise every volume control slider.<br />
* In each option box, try to change the selected option, trying all the possible combinations.<br />
* If you get noise, try to lower and/or mute some volume controls, until you find the source of the noise.<br />
<br />
Please note again that you do '''not''' need to change any controls in the ''top area'' nor in the ''bottom area'', as they are virtual <tt>vmix</tt>-related mixer controls.<br />
<br />
== Troubleshooting other issues ==<br />
<br />
* If you get distorted sound, try lowering some volume control sliders.<br />
<br />
* If you need to change the default sound card, look at [http://www.opensound.com/wiki/index.php/Tips_And_Tricks#Changing_the_default_sound_output here].<br />
<br />
* If you have another issues, try searching or asking for help at the [http://www.4front-tech.com/forum 4front forums].<br />
<br />
= Tips and Tricks =<br />
<br />
== Using multimedia keys with OSS ==<br />
An easy way to mute/unmute and increase/decrease the volume is to use the [http://www.opensound.com/wiki/index.php/Tips_And_Tricks#ossvol {{Codeline|ossvol}} script]. It is available in [[AUR]].<br />
<br />
Once you installed it try to toggle the sound:<br />
ossvol -t<br />
<br />
Type {{Codeline|ossvol -h}} for the other commands.<br />
<br />
If you don't know how to assign commands to your multimedia keys, see [[Extra Keyboard Keys]].<br />
<br />
==={{Codeline|ossvol}} troubleshooting===<br />
If you get an error like:<br />
Bad mixer control name(987) 'vol'<br />
you need to edit the script ({{Filename|/usr/bin/ossvol}}) and change the value of the {{Codeline|CHANNEL}} variable which is at the beginning of the script. For example mine is {{Codeline|CHANNEL<nowiki>=</nowiki>"vmix0-outvol"}}.<br />
<br />
== Other tips ==<br />
<br />
* [http://www.opensound.com/wiki/index.php/Tips_And_Tricks#Starting_ossxmix_minimized_to_tray_on_desktop_startup Starting ossxmix minimized to tray on desktop startup].<br />
* [http://www.opensound.com/wiki/index.php/Tips_And_Tricks#Recording_sound_output_of_a_program Recording sound output of a program].<br />
<br />
== Laptop suspend and hibernation ==<br />
<br />
OSS does not automatically support suspend meaning that OSS must be manually stopped prior to suspending or hibernating a laptop.<br />
<br />
OSS provides <tt>soundon</tt> and <tt>soundoff</tt> to enable and disable OSS, although any processes that use sound must be terminated first.<br />
<br />
The following script is a rather basic method of automatically unloading OSS prior to suspending and reloading afterwards. This has been tested with KDE 4.2 but has not tried in other desktop environments.<br />
<br />
* Save the contents of this script (as root) into <tt>/usr/lib/pm-utils/sleep.d/50ossound</tt>:<br />
<br />
#!/bin/sh<br />
. "${PM_FUNCTIONS}"<br />
<br />
suspend_osssound()<br />
{<br />
/usr/lib/oss/scripts/killprocs.sh<br />
/usr/sbin/soundoff<br />
}<br />
<br />
resume_osssound()<br />
{<br />
/usr/sbin/soundon<br />
}<br />
<br />
case "$1" in<br />
hibernate|suspend)<br />
suspend_osssound<br />
;;<br />
thaw|resume)<br />
resume_osssound<br />
;;<br />
*) exit $NA<br />
;;<br />
esac<br />
<br />
The KDE notify daemon (which provides the system sounds) will automatically reload itself after being terminated by OSS. <br />
<br />
{{Box Note|This script is rather basic and will terminate any application directly accessing OSS, this means save your work prior to suspending your laptop.}}<br />
<br />
== ALSA emulation ==<br />
<br />
=== Introduction ===<br />
<br />
You can instruct <tt>alsa-lib</tt> to use OSS as its audio output system. This works as a sort of ALSA emulation.<br />
<br />
Note, however, that this method may introduce additional latency in your sound output, and that the emulation is not complete and doesn't work with all applications. It doesn't work, for example, with programs that try to detect devices using ALSA.<br />
<br />
So, as most applications support OSS directly, use this method only as a last resort.<br />
<br />
In the future, more complete methods may be available for emulating ALSA, such as <tt>libsalsa</tt> and <tt>cuckoo</tt>.<br />
<br />
=== HOW-TO ===<br />
<br />
* Install the <tt>alsa-plugins</tt> package.<br />
<br />
pacman -S alsa-plugins<br />
<br />
* Edit <tt>/etc/asound.conf</tt> as follows.<br />
<br />
pcm.oss {<br />
type oss<br />
device /dev/dsp<br />
}<br />
<br />
pcm.!default {<br />
type oss<br />
device /dev/dsp<br />
}<br />
<br />
ctl.oss {<br />
type oss<br />
device /dev/mixer<br />
}<br />
<br />
ctl.!default {<br />
type oss<br />
device /dev/mixer<br />
}<br />
<br />
{{Box Note| If you don't want to use OSS anymore, don't forget to revert changes that you do here in ''/etc/asound.conf'' .}}<br />
<br />
= Experimental packages =<br />
<br />
== Mercurial repository version ==<br />
<br />
There is a [http://aur.archlinux.org/packages.php?ID=21126 oss-mercurial package] in AUR. This package compiles and installs the latest OSS development version direcly from the Mercurial repository.<br />
<br />
You can try this package if you want to contribute code to OSS or if only a very recent change in OSS code introduced support to your sound device.<br />
<br />
= OSS and KDE4 =<br />
<br />
KDE4 in arch does not ship with the gstreamer backend, which is needed for OSS4 to work in this DE.<br />
To enable gstramer support in phonon get the PKGBUILD with ABS. Install abs and run it as root.<br />
Then cp the phonon PKGBUILD.<br />
<br />
cp -a /var/abs/extra/phonon ~/abs/phonon<br />
<br />
cd into the new directory and open the PKGBUILD in your favorite editor.<br />
change<br />
<br />
-DWITH_GStreamer=OFF<br />
to<br />
-DWITH_GStreamer=ON<br />
<br />
now simply run makepkg and after a while you can install the resulting package with<br />
<br />
pacman -U phonon*.pkg.tar.gz<br />
<br />
Last but not least install the needed gstreamer packages with<br />
<br />
pacman -S gstreamer0.10-plugins<br />
<br />
In Systemsettings -> Multimedia select the Gstreamer backened which should enable your sound in KDE.<br />
<br />
<br />
Keep in mind that kmix does have sliders for applications-volume, so you have to use ossxmix to change those.</div>Rasihttps://wiki.archlinux.org/index.php?title=Open_Sound_System&diff=66924Open Sound System2009-04-16T08:36:06Z<p>Rasi: </p>
<hr />
<div>[[Category:Sound (English)]]<br />
[[Category:Audio/Video (English)]]<br />
[[Category:HOWTOs (English)]]<br />
{{i18n_links_start}}<br />
{{i18n_entry|English|OSS}}<br />
{{i18n_entry|简体中文|OSS (简体中文)}}<br />
{{i18n_entry|Türkçe|OSS (Türkçe)}}<br />
{{i18n_links_end}}<br />
<br />
= Introduction =<br />
The [http://developer.opensound.com Open Sound System] is a [http://4front-tech.com commercially-supported] sound architecture that works on several UNIX-like and POSIX-compatible systems, including Linux, FreeBSD, Solaris and BeOS/Haiku.<br />
<br />
Please note that this article is not about the old OSS, which is included in the Linux kernel sources and is more than 10 years old by now.<br />
<br />
This article is about the new OSS versions (often called OSSv4). These versions were previously proprietary - OSS became open source again in July 2007, and is currently available under GPL, BSD or CDDL licenses.<br />
<br />
= Advantages and disadvantages vs. ALSA =<br />
<br />
== Advantages over ALSA (for users) ==<br />
* Includes a transparent software mixer (vmix) in kernel space. This means multiple applications can access the sound device at the same time without problems.<br />
* The vmix mixer controls allow you to adjust the volume of each application individually.<br />
* Better support for some sound card models, for example for the Creative X-Fi.<br />
* Sound quality is usually better.<br />
* Better support for applications written for the OSS API, of course. The OSS API is widely spread and a lot of applications support it. The ALSA's OSS API emulation, however, is often buggy.<br />
<br />
== Advantages over ALSA (for developers) ==<br />
* Cleaner and easier to use API.<br />
* API is much better [http://manuals.opensound.com/developer documented].<br />
* Support for sound drivers in the userspace (oss_userdev).<br />
* Portability across all supported platforms. If the application works using OSS under Linux, it will work under FreeBSD and Solaris too, for example.<br />
* Portability across operating systems. It's [http://revolf.free.fr/Alchimie-7/Alchimie7_OSS_Haiku.en.pdf easier] to port OSS to a new operating system.<br />
<br />
== Disadvantages vs. ALSA ==<br />
* USB audio devices support is currently experimental under Linux.<br />
* Bluetooth audio devices are currently not supported.<br />
* AC'97 and HDAudio dial-up soft-modems (for example Si3055) are currently not supported.<br />
* MIDI support is currently not finished. However, you can still use MIDI with a software synthesizer like timidity or fluidsynth.<br />
* Suspend is currently not supported. You need to unload OSS (by using <tt>soundoff</tt>) before suspending, and to reload OSS (by using <tt>soundon</tt>) after resuming.<br />
* Automatic jack sensing currently doesn't work properly with '''some''' HDAudio-powered motherboards. This means that, depending on your motherboard model, you may have to manually switch off your speakers when plugging your earphone.<br />
<br />
= Installing =<br />
<br />
* Disable ALSA by blocking the <tt>soundcore</tt> module in <tt>/etc/rc.conf</tt>:<br />
<br />
MODULES=(!soundcore ..............<br />
<br />
And by rebooting.<br />
<br />
If you didn't want to reboot, you could also quit your desktop environment (if any) to free the soundcard, and go to pure console for doing the next steps.<br />
<br />
* Install OSS by running:<br />
<br />
# pacman -S oss<br />
<br />
* Start OSS by running:<br />
<br />
# /etc/rc.d/oss start<br />
<br />
* Add <tt>oss</tt> to your <tt>DAEMONS</tt> variable at <tt>/etc/rc.conf</tt>, so OSS is loaded automatically at each boot.<br />
<br />
* In the case OSS is not able to detect your card when starting it, run :<br />
<br />
# ossdetect -v<br />
<br />
Then <tt>soundoff && soundon</tt> to reactivate it.<br />
<br />
<br />
Note: The above instructions will currently install OSS 4.1. If you want OSS 4.0, you can still find it at [http://aur.archlinux.org/packages.php?ID=23383 AUR].<br />
<br />
= Testing =<br />
<br />
You can test OSS by running:<br />
<br />
$ osstest<br />
<br />
{{Box Note| Beware the default volume is very loud. Avoid using earphones or lower the volume by using <tt>ossxmix</tt>. }}<br />
<br />
You should be able to hear music during the test process. If there is no audio, try to adjust the mixer as explained in the following sections and/or read the Troubleshooting sections.<br />
<br />
= The mixer =<br />
<br />
The command line mixer is called <tt>ossmix</tt>. It's very like the BSD audio mixer (<tt>mixerctl</tt>).<br />
<br />
A more friendly, graphical mixer, is available too. It's called <tt>ossxmix</tt>. It needs the optional depend <tt>gtk2</tt> to work.<br />
<br />
The <tt>ossxmix</tt> controls are explained in the following example:<br />
<br />
______________________________<br />
/ High Definition Audio ALC262 \ ----------------------------------> One tab for each sound card<br />
/________________________________\_______________________________<br />
|<br />
| [x] vmix0-enable [vmix0-rate: 48.000kHz] vmix0-channels \ The vmix (virtual mixer) special configurations<br />
| [ Stereo [v] ] |--> appear at the top. These include sampling rate<br />
| / and mixer priority. They are provided by OSS.<br />
| __codec1______________________________________________________ <br />
| | _jack_______________________________________________________ \ <br />
| | | _int-speaker____________________ __green_________________ |<br />
| | | | | | | These are your sound card configurations.<br />
| | | | _mode______ | | | | _mode______ | | | Every mixer control that is shown here is<br />
| | | | [ mix [v] ] o o [x] [ ]mute | | [ mix [v] ] o o [x] |--> provided by your sound card. Every sound card<br />
| | | | | | | | | | | specific control is shown here.<br />
| | | |________________________________| |_______________________ |<br />
| | |____________________________________________________________ |<br />
| |______________________________________________________________ /<br />
|<br />
| ___vmix0_______________________________________________________ \<br />
| | __mocp___ O O _firefox_ O O __pcm7___ O O | Here are the vmix mixer controls. These are<br />
| | | | O O | | x x | | O O | virtual mixer controls provided by OSS. Each<br />
| | | | | | x O | | | | x x | | | | O O | slider is the volume control of a different<br />
| | | o o [x] | x x | o o [x] | x x | o o [x] | O O |--> application. When one application uses the<br />
| | | | | | x x | | | | x x | | | | O O | sound card, its name is shown in the place of<br />
| | |_________| x x |_________| x x |_________| O O | the 'pcm#' labels. There are also sound level<br />
| |______________________________________________________________ | meter levels for each application.<br />
|________________________________________________________________ /<br />
<br />
=== Saving and restoring mixer settings ===<br />
<br />
If you wish to save your mixer settings manually, run <tt>savemixer</tt>. You will require to be a user with write permissions to <tt>/usr/lib/oss/etc/save.mixer</tt> or you'll need to use the <tt>-f</tt> switch to select another file. <tt>savemixer -L</tt> restores mixer settings.<br />
<br />
Please note that the init scripts run these commands before shutdown/after starting to keep mixer settings across boot, so most users don't need to worry about it.<br />
<br />
= Configuring Applications for OSS =<br />
<br />
== Skype ==<br />
<br />
The <tt>skype</tt> package only includes support for ALSA. To get an OSS-capable Skype, install the <tt>skype-oss</tt> package:<br />
<br />
pacman -S skype-oss<br />
<br />
If you are using x86_64, you can get the [http://aur.archlinux.org/packages.php?ID=18312 bin32-skype-oss] package from AUR.<br />
<br />
== Wine ==<br />
<br />
* Run <tt>winecfg</tt>.<br />
<br />
winecfg<br />
<br />
* Go to the <tt>Audio</tt> tab.<br />
<br />
* Select <tt>OSS Driver</tt>.<br />
<br />
== Other applications ==<br />
<br />
* If you can't get sound from an application not listed here, try looking at the [http://www.4front-tech.com/wiki/index.php/Configuring_Applications_for_OSSv4 Configuring Applications for OSSv4] page.<br />
* Search OSS specific packages by using <tt>pacman -Ss -- '-oss'</tt> and [http://aur.archlinux.org/packages.php?K=-oss&start=0&PP=100| in AUR].<br />
<br />
= Troubleshooting =<br />
<br />
== Troubleshooting HDAudio devices ==<br />
<br />
=== Understanding why problems arise ===<br />
<br />
If you have a HDAudio sound device, it's very likely that you will have to adjust some mixer settings before your sound works.<br />
<br />
HDAudio devices are very powerful in the sense that they can contain a lot of small circuits (called ''widgets'') that can be adjusted by software at any time. These controls are exposed to the mixer, and they can be used, for example, to turn the earphone jack into a sound input jack instead of a sound output jack.<br />
<br />
However, there is a side effect, mainly because the HDAudio standard is more flexible than it perhaps should be, and because the vendors often only care to get their ''official drivers'' working.<br />
<br />
Then, when using HDAudio devices, you often find disorganized mixer controls, that doesn't work at all by default, and you are forced to try every mixer control combination, until it works.<br />
<br />
=== How to solve ===<br />
<br />
Open <tt>ossxmix</tt> and try to change every mixer control in the ''middle area'', that contains the sound card specific controls, as explained in the previous "[[OSS#The_mixer|The mixer]]" section.<br />
<br />
You'll probably want to setup a program to record/play continously in the background (e.g. <tt>ossrecord - | ossplay -</tt> for recording or <tt>osstest -lV</tt> for playing), while changing mixer settings in ossxmix in the foreground.<br />
<br />
* Raise every volume control slider.<br />
* In each option box, try to change the selected option, trying all the possible combinations.<br />
* If you get noise, try to lower and/or mute some volume controls, until you find the source of the noise.<br />
<br />
Please note again that you do '''not''' need to change any controls in the ''top area'' nor in the ''bottom area'', as they are virtual <tt>vmix</tt>-related mixer controls.<br />
<br />
== Troubleshooting other issues ==<br />
<br />
* If you get distorted sound, try lowering some volume control sliders.<br />
<br />
* If you need to change the default sound card, look at [http://www.opensound.com/wiki/index.php/Tips_And_Tricks#Changing_the_default_sound_output here].<br />
<br />
* If you have another issues, try searching or asking for help at the [http://www.4front-tech.com/forum 4front forums].<br />
<br />
= Tips and Tricks =<br />
<br />
== Using multimedia keys with OSS ==<br />
An easy way to mute/unmute and increase/decrease the volume is to use the [http://www.opensound.com/wiki/index.php/Tips_And_Tricks#ossvol {{Codeline|ossvol}} script]. It is available in [[AUR]].<br />
<br />
Once you installed it try to toggle the sound:<br />
ossvol -t<br />
<br />
Type {{Codeline|ossvol -h}} for the other commands.<br />
<br />
If you don't know how to assign commands to your multimedia keys, see [[Extra Keyboard Keys]].<br />
<br />
==={{Codeline|ossvol}} troubleshooting===<br />
If you get an error like:<br />
Bad mixer control name(987) 'vol'<br />
you need to edit the script ({{Filename|/usr/bin/ossvol}}) and change the value of the {{Codeline|CHANNEL}} variable which is at the beginning of the script. For example mine is {{Codeline|CHANNEL<nowiki>=</nowiki>"vmix0-outvol"}}.<br />
<br />
== Other tips ==<br />
<br />
* [http://www.opensound.com/wiki/index.php/Tips_And_Tricks#Starting_ossxmix_minimized_to_tray_on_desktop_startup Starting ossxmix minimized to tray on desktop startup].<br />
* [http://www.opensound.com/wiki/index.php/Tips_And_Tricks#Recording_sound_output_of_a_program Recording sound output of a program].<br />
<br />
== Laptop suspend and hibernation ==<br />
<br />
OSS does not automatically support suspend meaning that OSS must be manually stopped prior to suspending or hibernating a laptop.<br />
<br />
OSS provides <tt>soundon</tt> and <tt>soundoff</tt> to enable and disable OSS, although any processes that use sound must be terminated first.<br />
<br />
The following script is a rather basic method of automatically unloading OSS prior to suspending and reloading afterwards. This has been tested with KDE 4.2 but has not tried in other desktop environments.<br />
<br />
* Save the contents of this script (as root) into <tt>/usr/lib/pm-utils/sleep.d/50ossound</tt>:<br />
<br />
#!/bin/sh<br />
. "${PM_FUNCTIONS}"<br />
<br />
suspend_osssound()<br />
{<br />
/usr/lib/oss/scripts/killprocs.sh<br />
/usr/sbin/soundoff<br />
}<br />
<br />
resume_osssound()<br />
{<br />
/usr/sbin/soundon<br />
}<br />
<br />
case "$1" in<br />
hibernate|suspend)<br />
suspend_osssound<br />
;;<br />
thaw|resume)<br />
resume_osssound<br />
;;<br />
*) exit $NA<br />
;;<br />
esac<br />
<br />
The KDE notify daemon (which provides the system sounds) will automatically reload itself after being terminated by OSS. <br />
<br />
{{Box Note|This script is rather basic and will terminate any application directly accessing OSS, this means save your work prior to suspending your laptop.}}<br />
<br />
== ALSA emulation ==<br />
<br />
=== Introduction ===<br />
<br />
You can instruct <tt>alsa-lib</tt> to use OSS as its audio output system. This works as a sort of ALSA emulation.<br />
<br />
Note, however, that this method may introduce additional latency in your sound output, and that the emulation is not complete and doesn't work with all applications. It doesn't work, for example, with programs that try to detect devices using ALSA.<br />
<br />
So, as most applications support OSS directly, use this method only as a last resort.<br />
<br />
In the future, more complete methods may be available for emulating ALSA, such as <tt>libsalsa</tt> and <tt>cuckoo</tt>.<br />
<br />
=== HOW-TO ===<br />
<br />
* Install the <tt>alsa-plugins</tt> package.<br />
<br />
pacman -S alsa-plugins<br />
<br />
* Edit <tt>/etc/asound.conf</tt> as follows.<br />
<br />
pcm.oss {<br />
type oss<br />
device /dev/dsp<br />
}<br />
<br />
pcm.!default {<br />
type oss<br />
device /dev/dsp<br />
}<br />
<br />
ctl.oss {<br />
type oss<br />
device /dev/mixer<br />
}<br />
<br />
ctl.!default {<br />
type oss<br />
device /dev/mixer<br />
}<br />
<br />
{{Box Note| If you don't want to use OSS anymore, don't forget to revert changes that you do here in ''/etc/asound.conf'' .}}<br />
<br />
= Experimental packages =<br />
<br />
== Mercurial repository version ==<br />
<br />
There is a [http://aur.archlinux.org/packages.php?ID=21126 oss-mercurial package] in AUR. This package compiles and installs the latest OSS development version direcly from the Mercurial repository.<br />
<br />
You can try this package if you want to contribute code to OSS or if only a very recent change in OSS code introduced support to your sound device.<br />
<br />
= OSS and KDE4<br />
<br />
KDE4 in arch does not ship with the gstreamer backend, which is needed for OSS4 to work in this DE.<br />
To enable gstramer support in phonon get the PKGBUILD with ABS. Install abs and run it as root.<br />
Then cp the phonon PKGBUILD.<br />
<br />
cp -a /var/abs/extra/phonon ~/abs/phonon<br />
<br />
cd into the new directory and open the PKGBUILD in your favorite editor.<br />
change<br />
<br />
-DWITH_GStreamer=OFF<br />
to<br />
-DWITH_GStreamer=ON<br />
<br />
now simply run makepkg and after a while you can install the resulting package with<br />
<br />
pacman -U phonon*.pkg.tar.gz<br />
<br />
Last but not least install the needed gstreamer packages with<br />
<br />
pacman -S gstreamer0.10-plugins<br />
<br />
In Systemsettings -> Multimedia select the Gstreamer backened which should enable your sound in KDE.<br />
<br />
<br />
Keep in mind that kmix does have sliders for applications-volume, so you have to use ossxmix to change those.</div>Rasihttps://wiki.archlinux.org/index.php?title=Xmonad&diff=48190Xmonad2008-08-25T12:59:17Z<p>Rasi: /* Development Version (xmonad-darcs) */</p>
<hr />
<div>{{i18n_links_start}}<br />
{{i18n_entry|English|Xmonad}}<br />
{{i18n_entry|Türkçe|Xmonad (Türkçe)}}<br />
{{i18n_links_end}}<br />
= Introduction =<br />
<br />
[http://xmonad.org/ xmonad] is a tiling window manager for X. Windows are arranged automatically to tile the screen without gaps or overlap, maximizing screen use. Window manager features are accessible from the keyboard: a mouse is optional. <br />
<br />
xmonad is written, configured and extensible in [http://haskell.org/ Haskell]. Custom layout algorithms, key bindings and other extensions may be written by the user in config files. <br />
<br />
Layouts are applied dynamically, and different layouts may be used on each workspace. Xinerama is fully supported, allowing windows to be tiled on several physical screens.<br />
<br />
For more information, please visit the xmonad website: http://xmonad.org/<br />
<br />
= Installation =<br />
<br />
xmonad is currently available in the community repo. A build for the current development snapshot (darcs) is in the [http://aur.archlinux.org/ aur]. The following instructions are for xmonad-darcs, the development snapshot.<br />
<br />
== Development Version (xmonad-darcs) ==<br />
<br />
The xmonad-darcs development release requires 3 separate packages available from AUR (install them in the following order):<br />
<br />
* [http://aur.archlinux.org/packages.php?do_Details=1&ID=13750&O=0&L=0&C=0&K=xmonad&SB=n&SO=a&PP=25&do_MyPackages=0&do_Orphans=0&SeB=nd haskell-x11-darcs] - haskell bindings to the X11 graphics library<br />
* [http://aur.archlinux.org/packages.php?ID=12483 xmonad-darcs] - the core window manager<br />
* [http://aur.archlinux.org/packages.php?do_Details=1&ID=13652&O=0&L=0&C=0&K=xmonad&SB=n&SO=a&PP=25&do_MyPackages=0&do_Orphans=0&SeB=nd xmonad-contrib-darcs] - contributed extensions providing custom layouts, configurations, etc.<br />
<br />
= Configuration =<br />
<br />
== Starting xmonad ==<br />
To start xmonad automatically, simply add the command '''xmonad''' to your startup script (e.g. ~/.xinitrc). GDM and KDM users can create a new session file and then select xmonad from the appropriate Session menu.<br />
<br />
== Configuring xmonad ==<br />
<br />
Xmonad users can modify, override or extend the default settings with the ~/.xmonad/xmonad.hs configuration file. Recompiling is done on the fly, with the Mod+q shortcut.<br />
<br />
Because the xmonad configuration file is written in Haskell, non-programmers may have a difficult time adjusting settings. For detailed HOWTO's and example configs, we refer you to the following resources:<br />
<br />
* [http://haskell.org/haskellwiki/Xmonad xmonad wiki]<br />
* [http://haskell.org/haskellwiki/Xmonad/Config_archive xmonad config archive]<br />
* [http://haskell.org/haskellwiki/Xmonad/Frequently_asked_questions xmonad FAQ]<br />
<br />
== Exiting xmonad ==<br />
To end the current xmonad session, press Mod+SHIFT+q (Mod being ALT by default).<br />
<br />
= Tips & Tricks =<br />
== Complementary Applications ==<br />
There are number of complementary utilities that work well with Xmonad. The most common of these include:<br />
<br />
* [http://www.suckless.org/wiki/tools/xlib dmenu]<br />
* [[Xmobar]]<br />
* [[Dzen]] <br />
* [[Conky]] and [http://aur.archlinux.org/packages.php?ID=11884 conky-cli]<br />
<br />
== Making room for conky or tray apps ==<br />
:''Note that 'defaultGaps' will be removed from XMonad in version 0.8, and replaced by something like 'avoidStruts' or an extension from XMonadContrib like XMonad.Hooks.ManageDocks.''<br />
<br />
xmonad can be configured to leave space at the top or bottom of your screen for background applications like Conky or trayer. To do so, open the Config.hs file in your favourite editor and change the ''defaultGaps'' value:<br />
defaultGaps = [(0,0,0,0)]<br />
The fields are: top, bottom, left, right. So, to leave a 15 pixel gap at the top and a 24 pixel gap along the bottom would look like this:<br />
defaultGaps = [(15,24,0,0)]<br />
<br />
Or, wrap your layouts with avoidStruts from XMonad.Hooks.ManageDocks for the fitting to happen automatically:<br />
layoutHook = avoidStruts (tiled Tall ||| ...<br />
manageHook = manageHook defaultConfig <+> manageDocks<br />
<br />
If you ever want to toggle the gaps the action is<br />
,((modMask x, xK_b ), sendMessage ToggleStruts)<br />
<br />
== Using [[xmobar]] with xmonad ==<br />
[[Xmobar]] is a light and minimalistic text based bar, designed to work with xmonad.<br><br />
To use xmobar with xmonad, you will need two packages in addition to the xmonad package, these are xmonad-contrib from [community] and xmobar or xmobar-darcs from [http://aur.archlinux.org aur]. You must also make room for the bar on screen, see [[Xmonad#Making room for conky or tray apps]]<br />
<br />
There are two ways of getting the output of xmonad into xmobar. You can either use a standard unix pipe when you start xmonad, or you can set up a pipe from within xmonad.hs. The later is generaly prefered since it's independent of the way you start xmonad. The following setup will use the later, starting xmobar and setting up the pipe from within xmonad.<br />
<br />
Open up <tt>~/.xmonad/xmonad.hs</tt> in your favorite editor.<br><br />
First, we need to import three modules, IO, the DynamicLog and the Run utility. The logger is used to format and print various information about xmonad, like the workspaces, the title of the current window, the current layout and more. The two others are neede to run xmobar with a pipe, and to print the output of the logger to it.<br />
import IO<br />
import XMonad.Hooks.DynamicLog<br />
import XMonad.Util.Run<br />
<br />
Now, on to the main function. There are several loggers you can use and you can also create your own. In this example, we will use xmobarPP, for details read the documentation on [http://xmonad.org/xmonad-docs/xmonad-contrib/XMonad-Hooks-DynamicLog.html XMonad.Hooks.DynamicLog].<br><br />
The important thing here, is that we have to overide the ppOutput, else it will just print to stdout.<br />
main = do<br />
xmobar <- spawnPipe "xmobar" -- spawns xmobar and returns a handle<br />
xmonad $ defaultConfig <br />
{ ...<br />
, logHook = dynamicLogWithPP $ xmobarPP { ppOutput = hPutStrLn xmobar } -- print the output of xmobarPP to the handle<br />
, ...<br />
}<br />
<br />
At last, open up <tt>~/.xmobarrc</tt> and make sure you got StdinReader in the template. E.g.<br />
Config { ...<br />
, template = " %StdinReader% ... "<br />
}<br />
Now, all you should have to do is either to start, or restart xmonad.<br />
<br />
== Example Configurations ==<br />
Below are some example configurations from fellow Xmonad users. Feel free to add links to your own.<br />
* MrElendig :: Simple configuration, with xmobar :: [http://arch.har-ikkje.net/configs/home/dot.xmonad/xmonad.hs xmonad.hs], [http://arch.har-ikkje.net/configs/home/dot.xmobarrc .xmobarrc], [http://arch.har-ikkje.net/gfx/ss/2008-07-27-180602_1680x1050_scrot.png screenshot].<br />
* hsa2 :: Simple configuration, with xmobar :: [http://www.difuzyon.net/linked/configs/xmonad.hs xmonad.hs], [http://www.difuzyon.net/linked/configs/dot.xmobarrc .xmobarrc].<br />
<br />
= Other Resources =<br />
[http://xmonad.org/ xmonad] -- The official xmonad website<br />
<br />
[http://xmonad.org/tour.html xmonad: a guided tour]<br />
<br />
[[dzen]] -- A general purpose messaging and notification program<br />
<br />
[[dmenu]] -- A dynamic X menu for the quick launching of programs</div>Rasihttps://wiki.archlinux.org/index.php?title=Xmonad&diff=48189Xmonad2008-08-25T12:57:43Z<p>Rasi: /* Development Version (xmonad-darcs) */</p>
<hr />
<div>{{i18n_links_start}}<br />
{{i18n_entry|English|Xmonad}}<br />
{{i18n_entry|Türkçe|Xmonad (Türkçe)}}<br />
{{i18n_links_end}}<br />
= Introduction =<br />
<br />
[http://xmonad.org/ xmonad] is a tiling window manager for X. Windows are arranged automatically to tile the screen without gaps or overlap, maximizing screen use. Window manager features are accessible from the keyboard: a mouse is optional. <br />
<br />
xmonad is written, configured and extensible in [http://haskell.org/ Haskell]. Custom layout algorithms, key bindings and other extensions may be written by the user in config files. <br />
<br />
Layouts are applied dynamically, and different layouts may be used on each workspace. Xinerama is fully supported, allowing windows to be tiled on several physical screens.<br />
<br />
For more information, please visit the xmonad website: http://xmonad.org/<br />
<br />
= Installation =<br />
<br />
xmonad is currently available in the community repo. A build for the current development snapshot (darcs) is in the [http://aur.archlinux.org/ aur]. The following instructions are for xmonad-darcs, the development snapshot.<br />
<br />
== Development Version (xmonad-darcs) ==<br />
<br />
The xmonad-darcs development release requires 3 separate packages available from AUR (install them in the following order):<br />
<br />
* [http://aur.archlinux.org/packages.php?do_Details=1&ID=13750&O=0&L=0&C=0&K=xmonad&SB=n&SO=a&PP=25&do_MyPackages=0&do_Orphans=0&SeB=nd haskell-x11-darcs] - haskell bindings to the X11 graphics library<br />
* [http://aur.archlinux.org/packages.php?ID=12483] - the core window manager<br />
* [http://aur.archlinux.org/packages.php?do_Details=1&ID=13652&O=0&L=0&C=0&K=xmonad&SB=n&SO=a&PP=25&do_MyPackages=0&do_Orphans=0&SeB=nd xmonad-contrib-darcs] - contributed extensions providing custom layouts, configurations, etc.<br />
<br />
= Configuration =<br />
<br />
== Starting xmonad ==<br />
To start xmonad automatically, simply add the command '''xmonad''' to your startup script (e.g. ~/.xinitrc). GDM and KDM users can create a new session file and then select xmonad from the appropriate Session menu.<br />
<br />
== Configuring xmonad ==<br />
<br />
Xmonad users can modify, override or extend the default settings with the ~/.xmonad/xmonad.hs configuration file. Recompiling is done on the fly, with the Mod+q shortcut.<br />
<br />
Because the xmonad configuration file is written in Haskell, non-programmers may have a difficult time adjusting settings. For detailed HOWTO's and example configs, we refer you to the following resources:<br />
<br />
* [http://haskell.org/haskellwiki/Xmonad xmonad wiki]<br />
* [http://haskell.org/haskellwiki/Xmonad/Config_archive xmonad config archive]<br />
* [http://haskell.org/haskellwiki/Xmonad/Frequently_asked_questions xmonad FAQ]<br />
<br />
== Exiting xmonad ==<br />
To end the current xmonad session, press Mod+SHIFT+q (Mod being ALT by default).<br />
<br />
= Tips & Tricks =<br />
== Complementary Applications ==<br />
There are number of complementary utilities that work well with Xmonad. The most common of these include:<br />
<br />
* [http://www.suckless.org/wiki/tools/xlib dmenu]<br />
* [[Xmobar]]<br />
* [[Dzen]] <br />
* [[Conky]] and [http://aur.archlinux.org/packages.php?ID=11884 conky-cli]<br />
<br />
== Making room for conky or tray apps ==<br />
:''Note that 'defaultGaps' will be removed from XMonad in version 0.8, and replaced by something like 'avoidStruts' or an extension from XMonadContrib like XMonad.Hooks.ManageDocks.''<br />
<br />
xmonad can be configured to leave space at the top or bottom of your screen for background applications like Conky or trayer. To do so, open the Config.hs file in your favourite editor and change the ''defaultGaps'' value:<br />
defaultGaps = [(0,0,0,0)]<br />
The fields are: top, bottom, left, right. So, to leave a 15 pixel gap at the top and a 24 pixel gap along the bottom would look like this:<br />
defaultGaps = [(15,24,0,0)]<br />
<br />
Or, wrap your layouts with avoidStruts from XMonad.Hooks.ManageDocks for the fitting to happen automatically:<br />
layoutHook = avoidStruts (tiled Tall ||| ...<br />
manageHook = manageHook defaultConfig <+> manageDocks<br />
<br />
If you ever want to toggle the gaps the action is<br />
,((modMask x, xK_b ), sendMessage ToggleStruts)<br />
<br />
== Using [[xmobar]] with xmonad ==<br />
[[Xmobar]] is a light and minimalistic text based bar, designed to work with xmonad.<br><br />
To use xmobar with xmonad, you will need two packages in addition to the xmonad package, these are xmonad-contrib from [community] and xmobar or xmobar-darcs from [http://aur.archlinux.org aur]. You must also make room for the bar on screen, see [[Xmonad#Making room for conky or tray apps]]<br />
<br />
There are two ways of getting the output of xmonad into xmobar. You can either use a standard unix pipe when you start xmonad, or you can set up a pipe from within xmonad.hs. The later is generaly prefered since it's independent of the way you start xmonad. The following setup will use the later, starting xmobar and setting up the pipe from within xmonad.<br />
<br />
Open up <tt>~/.xmonad/xmonad.hs</tt> in your favorite editor.<br><br />
First, we need to import three modules, IO, the DynamicLog and the Run utility. The logger is used to format and print various information about xmonad, like the workspaces, the title of the current window, the current layout and more. The two others are neede to run xmobar with a pipe, and to print the output of the logger to it.<br />
import IO<br />
import XMonad.Hooks.DynamicLog<br />
import XMonad.Util.Run<br />
<br />
Now, on to the main function. There are several loggers you can use and you can also create your own. In this example, we will use xmobarPP, for details read the documentation on [http://xmonad.org/xmonad-docs/xmonad-contrib/XMonad-Hooks-DynamicLog.html XMonad.Hooks.DynamicLog].<br><br />
The important thing here, is that we have to overide the ppOutput, else it will just print to stdout.<br />
main = do<br />
xmobar <- spawnPipe "xmobar" -- spawns xmobar and returns a handle<br />
xmonad $ defaultConfig <br />
{ ...<br />
, logHook = dynamicLogWithPP $ xmobarPP { ppOutput = hPutStrLn xmobar } -- print the output of xmobarPP to the handle<br />
, ...<br />
}<br />
<br />
At last, open up <tt>~/.xmobarrc</tt> and make sure you got StdinReader in the template. E.g.<br />
Config { ...<br />
, template = " %StdinReader% ... "<br />
}<br />
Now, all you should have to do is either to start, or restart xmonad.<br />
<br />
== Example Configurations ==<br />
Below are some example configurations from fellow Xmonad users. Feel free to add links to your own.<br />
* MrElendig :: Simple configuration, with xmobar :: [http://arch.har-ikkje.net/configs/home/dot.xmonad/xmonad.hs xmonad.hs], [http://arch.har-ikkje.net/configs/home/dot.xmobarrc .xmobarrc], [http://arch.har-ikkje.net/gfx/ss/2008-07-27-180602_1680x1050_scrot.png screenshot].<br />
* hsa2 :: Simple configuration, with xmobar :: [http://www.difuzyon.net/linked/configs/xmonad.hs xmonad.hs], [http://www.difuzyon.net/linked/configs/dot.xmobarrc .xmobarrc].<br />
<br />
= Other Resources =<br />
[http://xmonad.org/ xmonad] -- The official xmonad website<br />
<br />
[http://xmonad.org/tour.html xmonad: a guided tour]<br />
<br />
[[dzen]] -- A general purpose messaging and notification program<br />
<br />
[[dmenu]] -- A dynamic X menu for the quick launching of programs</div>Rasi