Difference between revisions of "Music Player Daemon/Tips and tricks"

From ArchWiki
Jump to: navigation, search
(Local (with separate mpd user): update)
(Organize HTTP streaming section, and add info on what formats are supported)
 
(118 intermediate revisions by 39 users not shown)
Line 1: Line 1:
[[Category:Player]]
+
[[Category:Multimedia players]]
[[Category:Daemons and system services]]
+
[[ja:Music Player Daemon/Tips and tricks]]
 
Go back to [[Music Player Daemon]].
 
Go back to [[Music Player Daemon]].
  
==Tips and Tricks==
+
== Organizing library ==
===Organizing===
+
MPD doesn't provide a tool to preserve the file structure of your audio files. Check out [http://beets.radbox.org/ beets].
+
  
===Last.fm scrobbling===
+
MPD does not manage your library. Check out {{Pkg|beets}} or {{Pkg|picard}} in the [[official repositories]].
To scrobble your songs to [http://www.last.fm Last.fm] when using MPD, there are several possibilities.
+
  
====mpdscribble====
+
== Last.fm/Libre.fm scrobbling ==
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.
+
  
After you have installed mpdscribble, do the following (not as root):
+
{{Note|mpd release 0.18 removed Last.fm [http://git.musicpd.org/cgit/master/mpd.git/tree/NEWS support]. However, some clients offer scrobbling independent of mpd.}}
 +
To scrobble your songs to [http://www.last.fm Last.fm] or [http://libre.fm Libre.fm] when using MPD, there are several possibilities.
  
{{bc|$ mkdir ~/.mpdscribble}}
+
=== mpdas ===
* Create the file {{ic|~/.mpdscribble/mpdscribble.conf}} and add the following:
+
{{hc|~/.mpdscribble/mpdscribble.conf|2=
+
[mpdscribble]
+
host = <your mpd host> # optional, defaults to $MPD_HOST or localhost
+
port = <your mpd port> # optional, defaults to $MPD_PORT or 6600
+
log = /home/<YOUR_USERNAME>/.mpdscribble/mpdscribble.log
+
verbose = 2
+
sleep = 1
+
musicdir = <your music directory>
+
proxy = <your proxy> # optional, e. g. http://your.proxy:8080, defaults to none
+
  
[last.fm]
+
[http://50hz.ws/mpdas/ mpdas] is an AudioScrobbler client for MPD written in C++. It uses {{Pkg|curl}} and {{Pkg|libmpd}}. mpdas supports the latest AudioScrobbler protocol (2.0) and will also cache unscrobbled plays in {{ic|~/.mpdascache}} if there is no network connectivity.
# last.fm section, comment if you do not use last.fm
+
url = http://post.audioscrobbler.com/
+
username = <your last.fm username>
+
password = <your last.fm password>
+
journal = /home/<YOUR_USERNAME>/.mpdscribble/lastfm.journal
+
  
[libre.fm]
+
{{AUR|mpdas}} is available in the [[AUR]].
# libre.fm section, comment if you do not use libre.fm
+
url = http://turtle.libre.fm/
+
username = <your libre.fm username>
+
password = <your libre.fm password>
+
journal = /home/<YOUR_USERNAME>/.mpdscribble/librefm.journal
+
}}
+
Please note that passwords can also be written down as MD5:
+
echo -n 'PASSWORD' | md5sum | cut -f 1 -d " "
+
  
* Add {{ic|mpdscribble}} to the file in which you start {{ic|mpd}} as well (e.g. {{ic|~/.xinitrc}}):
+
Configuration of mpdas is very simple, see the official [https://github.com/hrkfdn/mpdas/blob/master/README README]. A very basic example of {{ic|/etc/mpdasrc}} is also available as {{ic|/etc/mpdasrc}}.
{{bc|
+
pidof mpdscribble >& /dev/null
+
if [ $? -ne 0 ]; then
+
mpdscribble &
+
fi
+
}}
+
  
====Sonata & Ario====
+
Your password can also be in the form of an md5hash:
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.
+
$ echo -n 'PASSWORD' | md5sum | cut -f 1 -d " "
  
====lastfmsubmitd====
+
To autostart ''mpdas'' along with ''mpd'', add an entry for it into the file in which you start ''mpd'' (e.g. [[xinitrc]]):
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}}.
+
  
====Last.fm playback====
+
{{bc|<nowiki>[[ -z $(pgrep -xU $UID mpdas) ]] && mpdas &</nowiki>}}
=====Native Last.fm playback=====
+
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].
+
{{hc|/etc/mpd.conf|2=
+
$ playlist_plugin {
+
      name            "lastfm"
+
      user            "my_username"
+
      password        "my_password"
+
}
+
}}
+
Then use e.g. mpc to load streams
+
{{bc|$ mpc load "lastfm://artist/Beatles"}}
+
  
===Never play on start===
+
When ''mpd'' is started with a [[Music_Player_Daemon#Autostart_with_systemd|systemd user service]], it is better to start ''mpdas'' the same way:
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.
+
restore_paused "yes"
+
  
The following sections detail various methods to simulate the same feature for older versions of mpd.
+
$ systemctl --user start mpdas.service
  
====Installing mpd from the AUR====
+
{{Tip|If you get a failed {{ic|mpdas.service}} after system startup, consider using [[Music_Player_Daemon#Socket_activation|socket activation]] with {{ic|mpd.socket}} instead.}}
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.
+
  
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]].
+
=== mpdcron ===
  
====Method 1====
+
[http://alip.github.io/mpdcron/ mpdcron] is a cron-like daemon for MPD that listens for events and executes user defined actions. It can be extended via modules to show notifications, submit songs to Last.fm or Libre.fm (''scrobbling''), or to collect statistics about played songs.
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:
+
=====Method 1.1=====
+
Simpler, working method (disables playing on startup of mpd daemon):
+
  start)
+
...
+
      mpc -q pause #add this line only
+
      add_daemon mpd
+
      stat_done
+
  
To prevent updates from destroying these modifications, add this file to the {{ic|NoUpgrade}} variable in {{ic|/etc/pacman.conf}}:
+
{{AUR|mpdcron-git}} is available in the [[AUR]].
NoUpgrade = etc/rc.d/mpd
+
  
====Method 2====
+
See the official page for information about configuration and modules.
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).
+
  
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.
+
To autostart ''mpdcron'' along with ''mpd'', add an entry for it into the file in which you start ''mpd'' (e.g. [[xinitrc]]):
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.
+
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.
+
  
====Method 3====
+
{{bc|<nowiki>
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.
+
[[ -z $(pgrep -xU $UID mpdcron) ]] && mpdcron &
 +
</nowiki>}}
  
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}}):
+
=== mpdscribble ===
  
Non-GDM users can use their own login manager's method to launch the line at logout.
+
{{AUR|mpdscribble}} is a daemon available in the [[AUR]]. This is arguably the best alternative, because it is 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 does not need any changes to {{ic|/etc}} at all. Visit [http://mpd.wikia.com/wiki/Client:Mpdscribble the official website] for more information.
  
====Example configuration: Output with 44.1 KHz at e. g. 16 bit depth, multiple programs at once====
+
Example configuration:
''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.
+
  
''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.
+
{{hc|~/.mpdscribble/mpdscribble.conf|2=
 +
[mpdscribble]
 +
host = ''your mpd host'' # optional, defaults to $MPD_HOST or localhost
 +
port = ''your mpd port'' # optional, defaults to $MPD_PORT or 6600
 +
log = /home/''YOUR_USERNAME''/.mpdscribble/mpdscribble.log
 +
verbose = 2
 +
proxy = ''your proxy'' # optional, e. g. http://your.proxy:8080, defaults to none
 +
 
 +
[last.fm]
 +
# last.fm section, comment if you do not use last.fm
 +
url = http://post.audioscrobbler.com/
 +
username = ''your last.fm username''
 +
password = ''your last.fm password''
 +
journal = /home/''YOUR_USERNAME''/.mpdscribble/lastfm.journal
 +
 
 +
[libre.fm]
 +
# libre.fm section, comment if you do not use libre.fm
 +
url = http://turtle.libre.fm/
 +
username = ''your libre.fm username''
 +
password = ''your libre.fm password''
 +
journal = /home/''YOUR_USERNAME''/.mpdscribble/librefm.journal
 +
}}
 +
 
 +
Your password can also be in the form of an md5hash.
 +
echo -n "''password''" | md5sum | cut -f 1 -d " "
 +
 
 +
To autostart ''mpdscribble'' you can use the {{ic|mpdscribble.service}} under systemd user instance. See [[systemd/User]] for details.
 +
 
 +
Alternatively you can autostart ''mpdscribble'' along with ''mpd'', add an entry for it into the file in which you start ''mpd'' (e.g. {{ic|~/.xinitrc}}):
 +
 
 +
{{bc|<nowiki>
 +
[[ -z $(pgrep -xU $UID mpdscribble) ]] && mpdscribble &
 +
</nowiki>}}
 +
 
 +
{{Note|1=If you get a {{ic|[last.fm] handshake failed, username or password incorrect (BADAUTH)}} error, make sure your username and password are correct, and that your password is not [http://bugs.musicpd.org/view.php?id=3836 32 characters long].}}
 +
 
 +
=== Sonata ===
 +
 
 +
Sonata has built-in support for scrobbling, although that requires the program to run the whole time. Additionally, Sonata does not 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.
 +
 
 +
== Disable resume playback on startup ==
 +
 
 +
This feature is present in ''mpd'' after version 0.16.2. When this feature is enabled, ''mpd'' 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}} to enable this feature.
 +
restore_paused "yes"
 +
 
 +
== Example configuration: Output with 44.1 KHz at e. g. 16 bit depth, multiple programs at once ==
 +
 
 +
''Why these formats?'' Because they are the standard format for CD audio, because ALSA on its own allows more than one program "to sound" only with dmix — which uses an inferior resampling algorithm by default — 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.
 +
 
 +
''What is 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 is not too great a loss.
  
 
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}}:
 
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}}:
Line 124: Line 114:
 
audio_output {
 
audio_output {
 
         type                    "alsa" # Use the ALSA output plugin.
 
         type                    "alsa" # Use the ALSA output plugin.
name "HDA Intel" # Can be called anything or nothing tmk, but must be present.
+
name "your_custom_name" # Must be present and does not have to match the actual card name , e.g. what you have in /etc/asound.conf
 
         options                "dev=dmixer"
 
         options                "dev=dmixer"
         device                  "plug:dmix" # Both lines cause MPD to output to dmix.
+
         device                  "plug:dmix" # Both lines cause MPD to output to dmix
 
format         "44100:16:2" # the actual format
 
format         "44100:16:2" # the actual format
 
auto_resample "no" # This bypasses ALSA's own algorithms, which generally are inferior. See below how to choose a different one.
 
auto_resample "no" # This bypasses ALSA's own algorithms, which generally are inferior. See below how to choose a different one.
use_mmap "yes" # Minor speed improvement, should work with all modern cards.
 
 
}
 
}
 
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.
 
 
}}
 
}}
  
{{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.)}}
+
{{Note|MPD gives the mp3 format a special treatment at decoding: it is always put out as 24 bit. (The conversion as forced by the ''format'' line only comes after that.)}}
  
 
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".
 
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".
Line 141: Line 128:
 
{{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.}}
 
{{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.}}
  
=== Control MPD with lirc ===
+
== Control MPD with lirc ==
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.
+
  
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.
+
There are already some clients designed for communications between lircd and MPD, however, as far as the practical use, they are not very useful since their functions are limited.
  
First of all, please setup your remotes as referred to the '''[[Lirc]]''' article.
+
It is 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.
 +
 
 +
First of all, please setup your remotes as referred to the [[LIRC]] article.
  
 
Edit your favored lirc startup configuration file, default location is {{ic|~/.lircrc}}.
 
Edit your favored lirc startup configuration file, default location is {{ic|~/.lircrc}}.
Line 158: Line 146:
 
  end
 
  end
  
An useful example:
+
An example:
 
  ## irexec
 
  ## irexec
 
  begin
 
  begin
Line 236: Line 224:
 
There are more functions for mpc, run {{ic|man mpc}} for more info.
 
There are more functions for mpc, run {{ic|man mpc}} for more info.
  
===Control MPD with phone===
+
== PulseAudio ==
=====remuco via bluetooth=====
+
* 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])
+
* transfer remuco client -- jar/jad files from {{ic|/usr/share/remuco/client/}} to your phone and install it
+
* run {{ic|remuco-mpd}} (as current user)
+
* run remuco on your phone, define a new bluetooth remuco connection (pair first if you haven't done this previously) and explore its capabilities
+
  
=====others=====
+
=== Local (as your own user) ===
There are several MPD-specific clients available in the app-store/market of Symbian, Android and iOS.
+
  
=== MPD & PulseAudio ===
+
No special options are required; just add a pulse output as described in the comments of mpd's config file.
  
mpd supports both local and remote use of PulseAudio.
+
=== Local (with separate mpd user) ===
  
==== Local (with separate mpd user) ====
+
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:
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:
+
  
First, uncomment the tcp module in {{ic|/etc/pulse/default.pa}} or {{ic|~/.pulse/default.pa}} and set 127.0.0.1 as an allowed IP address; the home directory takes precedence:
+
First, uncomment the tcp module in {{ic|/etc/pulse/default.pa}} or {{ic|$XDG_CONFIG_HOME/pulse/default.pa}} (typically {{ic|~/.config/pulse/default.pa}}) and set 127.0.0.1 as an allowed IP address; the home directory takes precedence:
  
 
  ### Network access (may be configured with paprefs, so leave this commented
 
  ### Network access (may be configured with paprefs, so leave this commented
Line 261: Line 242:
 
  #load-module module-zeroconf-publish
 
  #load-module module-zeroconf-publish
  
Additional IP ranges in cidr notation may be added using {{ic|;}} as the separator. Once this is complete, restart pulseaudio:
+
Additional IP ranges in cidr notation may be added using {{ic|;}} as the separator. Once this is complete, restart pulseaudio:
 
  $ pulseaudio --kill
 
  $ pulseaudio --kill
 
  $ pulseaudio --start -or- start-pulseaudio-x11/kde
 
  $ pulseaudio --start -or- start-pulseaudio-x11/kde
Line 272: Line 253:
 
  }
 
  }
  
Once this is added, restart mpd:
+
Once this is added, restart mpd.
# systemctl restart mpd
+
  
 
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.
 
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.
  
==== Remote ====
+
=== Remote ===
  
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.
+
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.
  
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|~/.pulse/default.pa}} on the target computer using the IP address of the server.
+
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.
  
 
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.
 
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.
  
=== Cue Files ===
+
== Cue Files ==
  
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:
+
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.
 +
For example, the command {{ic|mpc load albumx/x.cue}} loads the file {{ic|''music_directory''/albumx/x.cue}} as playlist; or in the case of an CUESHEET tag, {{ic|mpc load albumx/x.flac}}.
  
* remove {{Ic|libcdio}} temporary ({{Ic|pacman -Rdd libcdio}})
+
Client support of CUE files is a bit limited. Two available programs that do support CUE files are {{Pkg|cantata}} and [[ncmpcpp]].
* install {{Pkg|libcue}}
+
* install mpd with [[ABS]] or from [[AUR]].
+
* install {{Ic|libcdio}} again
+
  
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.
+
== HTTP streaming ==
  
=== HTTP Streaming ===
+
Since version 0.15 there is a built-in HTTP streaming daemon/server that comes with MPD.
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:
+
  
  audio_output {  
+
=== Configuration ===
  type "httpd"  
+
 
  name "My HTTP Stream"  
+
To activate this server simply set it as output device in mpd.conf:
  encoder "vorbis" # optional, vorbis or lame   
+
 
  port "8000"  
+
  audio_output {
  # quality "5.0" # do not define if bitrate is defined  
+
  type "httpd"
  bitrate "128" # do not define if quality is defined  
+
  name "My HTTP Stream"
  format "44100:16:1"  
+
  encoder "vorbis" # optional
 +
  port "8000"
 +
  # quality "5.0" # do not define if bitrate is defined
 +
  bitrate "128" # do not define if quality is defined
 +
  format "44100:16:1"
 +
always_on      "yes" # prevent MPD from disconnecting all listeners when playback is stopped.
 +
tags            "yes" # httpd supports sending tags to listening streams.
 
  }
 
  }
 +
 +
==== Format ====
 +
 +
MPD supports several encoding formats. See what your MPD supports with:
 +
 +
$ mpd --version
 +
 +
=== Use ===
  
 
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/.
 
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/.
  
To use mpd to connect to the stream from another computer.
+
To use mpd to connect to the stream from another computer:
  
 
  mpc add http://192.168.1.2:8000
 
  mpc add http://192.168.1.2:8000
 +
 +
== MPRIS2 Support ==
 +
 +
Install the {{AUR|mpDris2}} package. It runs in the user session and monitors the mpd server.
 +
 +
Copy the default configuration file from {{ic|/usr/share/doc/mpdris2/mpDris2.conf}} to {{ic|~/.config/mpDris2/mpDris2.conf}}. Edit it as needed.
 +
 +
mpDris2 has a {{ic|.desktop}} file, but it will not show up by default. You can set this to autostart at login. If your desktop environment cannot do this, you can set it manually by making a symlink in {{ic|~/.config/autostart/}}
 +
 +
$ ln -s /usr/share/applications/mpdris2.desktop ~/.config/autostart/
 +
 +
It should now be autorun at login.

Latest revision as of 07:23, 25 October 2016

Go back to Music Player Daemon.

Organizing library

MPD does not manage your library. Check out beets or picard in the official repositories.

Last.fm/Libre.fm scrobbling

Note: mpd release 0.18 removed Last.fm support. However, some clients offer scrobbling independent of mpd.

To scrobble your songs to Last.fm or Libre.fm when using MPD, there are several possibilities.

mpdas

mpdas is an AudioScrobbler client for MPD written in C++. It uses curl and libmpd. mpdas supports the latest AudioScrobbler protocol (2.0) and will also cache unscrobbled plays in ~/.mpdascache if there is no network connectivity.

mpdasAUR is available in the AUR.

Configuration of mpdas is very simple, see the official README. A very basic example of /etc/mpdasrc is also available as /etc/mpdasrc.

Your password can also be in the form of an md5hash:

$ echo -n 'PASSWORD' | md5sum | cut -f 1 -d " "

To autostart mpdas along with mpd, add an entry for it into the file in which you start mpd (e.g. xinitrc):

[[ -z $(pgrep -xU $UID mpdas) ]] && mpdas &

When mpd is started with a systemd user service, it is better to start mpdas the same way:

$ systemctl --user start mpdas.service
Tip: If you get a failed mpdas.service after system startup, consider using socket activation with mpd.socket instead.

mpdcron

mpdcron is a cron-like daemon for MPD that listens for events and executes user defined actions. It can be extended via modules to show notifications, submit songs to Last.fm or Libre.fm (scrobbling), or to collect statistics about played songs.

mpdcron-gitAUR is available in the AUR.

See the official page for information about configuration and modules.

To autostart mpdcron along with mpd, add an entry for it into the file in which you start mpd (e.g. xinitrc):

[[ -z $(pgrep -xU $UID mpdcron) ]] && mpdcron &

mpdscribble

mpdscribbleAUR is a daemon available in the AUR. This is arguably the best alternative, because it is 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 does not need any changes to /etc at all. Visit the official website for more information.

Example configuration:

~/.mpdscribble/mpdscribble.conf
[mpdscribble]
host = your mpd host # optional, defaults to $MPD_HOST or localhost
port = your mpd port # optional, defaults to $MPD_PORT or 6600
log = /home/YOUR_USERNAME/.mpdscribble/mpdscribble.log
verbose = 2
proxy = your proxy # optional, e. g. http://your.proxy:8080, defaults to none

[last.fm]
# last.fm section, comment if you do not use last.fm
url = http://post.audioscrobbler.com/
username = your last.fm username
password = your last.fm password
journal = /home/YOUR_USERNAME/.mpdscribble/lastfm.journal

[libre.fm]
# libre.fm section, comment if you do not use libre.fm
url = http://turtle.libre.fm/
username = your libre.fm username
password = your libre.fm password
journal = /home/YOUR_USERNAME/.mpdscribble/librefm.journal

Your password can also be in the form of an md5hash.

echo -n "password" | md5sum | cut -f 1 -d " "

To autostart mpdscribble you can use the mpdscribble.service under systemd user instance. See systemd/User for details.

Alternatively you can autostart mpdscribble along with mpd, add an entry for it into the file in which you start mpd (e.g. ~/.xinitrc):

[[ -z $(pgrep -xU $UID mpdscribble) ]] && mpdscribble &
Note: If you get a [last.fm] handshake failed, username or password incorrect (BADAUTH) error, make sure your username and password are correct, and that your password is not 32 characters long.

Sonata

Sonata has built-in support for scrobbling, although that requires the program to run the whole time. Additionally, Sonata does not 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.

Disable resume playback on startup

This feature is present in mpd after version 0.16.2. When this feature is enabled, mpd will always start in the "paused" state, even if a song was playing when mpd was stopped. Add the line below to your mpd.conf to enable this feature.

restore_paused "yes"

Example configuration: Output with 44.1 KHz at e. g. 16 bit depth, multiple programs at once

Why these formats? Because they are the standard format for CD audio, because ALSA on its own allows more than one program "to sound" only with dmix — which uses an inferior resampling algorithm by default — 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 mpd.conf is not changed this way.

What is 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 is not too great a loss.

The following assumes that there are not already other settings which conflict resp. overwrite it. This applies especially to the current user's potential ~/.asoundrc — which MPD as its own user ignores, therefore the following should go to /etc/asound.conf:

/etc/asound.conf
defaults.pcm.dmix.rate 44100 # Force 44.1 KHz
defaults.pcm.dmix.format S16_LE # Force 16 bits
/etc/mpd.conf
audio_output {
        type                    "alsa" # Use the ALSA output plugin.
	name			"your_custom_name" # Must be present and does not have to match the actual card name , e.g. what you have in /etc/asound.conf
        options                 "dev=dmixer"
        device                  "plug:dmix" # Both lines cause MPD to output to dmix
	format	        	"44100:16:2" # the actual format
	auto_resample		"no" # This bypasses ALSA's own algorithms, which generally are inferior. See below how to choose a different one.
}
Note: MPD gives the mp3 format a special treatment at decoding: it is always put out as 24 bit. (The conversion as forced by the format line only comes after that.)

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".

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.

Control MPD with lirc

There are already some clients designed for communications between lircd and MPD, however, as far as the practical use, they are not very useful since their functions are limited.

It is 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.

First of all, please setup your remotes as referred to the LIRC article.

Edit your favored lirc startup configuration file, default location is ~/.lircrc.

Fill the file with the following pattern:

begin
     prog = irexec
     button = <button_name>
     config = <command_to_run>
     repeat = <0 or 1>
end

An example:

## irexec
begin
     prog = irexec
     button = play_pause
     config = mpc toggle
     repeat = 0
end

begin
     prog = irexec
     button = stop
     config = mpc stop
     repeat = 0
end
begin
     prog = irexec
     button = previous
     config = mpc prev
     repeat = 0
end
begin
     prog = irexec
     button = next
     config = mpc next
     repeat = 0
end
begin
     prog = irexec
     button = volup
     config = mpc volume +2
     repeat = 1
end
begin
     prog = irexec
     button = voldown
     config = mpc volume -2
     repeat = 1
end
begin
     prog = irexec
     button = pbc
     config = mpc random
     repeat = 0
end
begin
     prog = irexec
     button = pdvd
     config = mpc update
     repeat = 0
end
begin
     prog = irexec
     button = right
     config = mpc seek +00:00:05
     repeat = 0
end
begin
     prog = irexec
     button = left
     config = mpc seek -00:00:05
     repeat = 0
end
begin
     prog = irexec
     button = up
     config = mpc seek +1%
     repeat = 0
end
begin
     prog = irexec
     button = down
     config = mpc seek -1%
     repeat = 0
end

There are more functions for mpc, run man mpc for more info.

PulseAudio

Local (as your own user)

No special options are required; just add a pulse output as described in the comments of mpd's config file.

Local (with separate mpd user)

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:

First, uncomment the tcp module in /etc/pulse/default.pa or $XDG_CONFIG_HOME/pulse/default.pa (typically ~/.config/pulse/default.pa) and set 127.0.0.1 as an allowed IP address; the home directory takes precedence:

### Network access (may be configured with paprefs, so leave this commented
### here if you plan to use paprefs)
#load-module module-esound-protocol-tcp
load-module module-native-protocol-tcp auth-ip-acl=127.0.0.1
#load-module module-zeroconf-publish

Additional IP ranges in cidr notation may be added using ; as the separator. Once this is complete, restart pulseaudio:

$ pulseaudio --kill
$ pulseaudio --start -or- start-pulseaudio-x11/kde

Next, edit /etc/mpd.conf and add a new pulse output pointing to 127.0.0.1 as a "remote" server:

audio_output {
       type		"pulse"
       name		"Local Music Player Daemon"
       server		"127.0.0.1"
}

Once this is added, restart mpd.

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.

Remote

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; libpulse is the only requirement to act as a source and is already a dependency of mpd.

In order to send audio from mpd to another computer follow the directions above, editing /etc/mpd.conf on the server running mpd using the IP address of the target computer and /etc/pulse/default.pa or $XDG_CONFIG_HOME/default.pa (typically ~/.config/pulse/default.pa) on the target computer using the IP address of the server.

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.

Cue Files

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. For example, the command mpc load albumx/x.cue loads the file music_directory/albumx/x.cue as playlist; or in the case of an CUESHEET tag, mpc load albumx/x.flac.

Client support of CUE files is a bit limited. Two available programs that do support CUE files are cantata and ncmpcpp.

HTTP streaming

Since version 0.15 there is a built-in HTTP streaming daemon/server that comes with MPD.

Configuration

To activate this server simply set it as output device in mpd.conf:

audio_output {
	type		"httpd"
	name		"My HTTP Stream"
	encoder		"vorbis"		# optional
	port		"8000"
#	quality		"5.0"			# do not define if bitrate is defined
	bitrate		"128"			# do not define if quality is defined
	format		"44100:16:1"
	always_on       "yes"			# prevent MPD from disconnecting all listeners when playback is stopped.
	tags            "yes"			# httpd supports sending tags to listening streams.
}

Format

MPD supports several encoding formats. See what your MPD supports with:

$ mpd --version

Use

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/.

To use mpd to connect to the stream from another computer:

mpc add http://192.168.1.2:8000

MPRIS2 Support

Install the mpDris2AUR package. It runs in the user session and monitors the mpd server.

Copy the default configuration file from /usr/share/doc/mpdris2/mpDris2.conf to ~/.config/mpDris2/mpDris2.conf. Edit it as needed.

mpDris2 has a .desktop file, but it will not show up by default. You can set this to autostart at login. If your desktop environment cannot do this, you can set it manually by making a symlink in ~/.config/autostart/

$ ln -s /usr/share/applications/mpdris2.desktop ~/.config/autostart/

It should now be autorun at login.