Difference between revisions of "Music Player Daemon/Tips and tricks"
Lolilolicon (talk | contribs) m (→Cue Files: Add example of loading embedded cuesheet with mpc) |
(→mpdcron) |
||
(19 intermediate revisions by 9 users not shown) | |||
Line 6: | Line 6: | ||
=== Organizing === | === Organizing === | ||
− | MPD does not provide a tool to preserve the file structure of your audio files. Check out [http://beets.radbox.org/ beets]. | + | MPD does not provide a tool to preserve the file structure of your audio files. Check out [http://beets.radbox.org/ beets] or [http://musicbrainz.org/doc/MusicBrainz_Picard/ picard]. |
− | === Last.fm scrobbling === | + | === Last.fm/Libre.fm scrobbling === |
− | To scrobble your songs to [http://www.last.fm Last.fm] when using MPD, there are several possibilities. | + | {{Note|mpd release 0.18 removed Last.fm [http://git.musicpd.org/cgit/master/mpd.git/tree/NEWS support]. Many clients still support scrobbling.}} |
+ | To scrobble your songs to [http://www.last.fm Last.fm] or [http://libre.fm Libre.fm] when using MPD, there are several possibilities. | ||
==== mpdas ==== | ==== mpdas ==== | ||
− | mpdas is an AudioScrobbler client for MPD written in C++. It uses {{Pkg|curl}} and {{Pkg|libmpd}}. | + | 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 ~/.mpdascache if there's no network connectivity. |
{{AUR|mpdas}} is available in the [[AUR]]. Visit [http://50hz.ws/mpdas/ the official website] for more information. | {{AUR|mpdas}} is available in the [[AUR]]. Visit [http://50hz.ws/mpdas/ the official website] for more information. | ||
− | + | Configuration of mpdas is very simple, below is an example: | |
− | + | * Edit the file {{ic|/etc/mpdasrc}}: | |
− | * Edit the file {{ic| | ||
{{hc|/etc/mpdasrc|2= | {{hc|/etc/mpdasrc|2= | ||
− | username = LASTFM USER | + | username = LASTFM USER |
password = PASSWORD IN MD5 | password = PASSWORD IN MD5 | ||
debug = 1 | debug = 1 | ||
Line 35: | Line 35: | ||
port = MPDPORT | port = MPDPORT | ||
}} | }} | ||
+ | |||
+ | A very basic example of {{ic|/etc/mpdasrc}} is also available as {{ic|/etc/mpdasrc}}. | ||
To get your password in md5 hash, just run: | To get your password in md5 hash, just run: | ||
Line 46: | Line 48: | ||
fi | fi | ||
}} | }} | ||
+ | |||
+ | ==== mpdcron ==== | ||
+ | |||
+ | mpd 'cron-daemon' that listens for events and executes user defined stuff. | ||
+ | |||
+ | {{AUR|mpdcron-git}} is available in the [[AUR]]. Visit [http://alip.github.io/mpdcron/ the official website] for more information. | ||
==== mpdscribble ==== | ==== mpdscribble ==== | ||
− | {{ | + | {{AUR|mpdscribble}} is a daemon available in the [[AUR]] (if you prefer, {{AUR|mpdscribble-git}} is also available). 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. |
After you have installed mpdscribble, do the following (not as root): | After you have installed mpdscribble, do the following (not as root): | ||
Line 56: | Line 64: | ||
* Create the file {{ic|~/.mpdscribble/mpdscribble.conf}} and add the following: | * Create the file {{ic|~/.mpdscribble/mpdscribble.conf}} and add the following: | ||
{{hc|~/.mpdscribble/mpdscribble.conf|2= | {{hc|~/.mpdscribble/mpdscribble.conf|2= | ||
− | [mpdscribble] | + | [mpdscribble] |
host = ''your mpd host'' # optional, defaults to $MPD_HOST or localhost | host = ''your mpd host'' # optional, defaults to $MPD_HOST or localhost | ||
port = ''your mpd port'' # optional, defaults to $MPD_PORT or 6600 | port = ''your mpd port'' # optional, defaults to $MPD_PORT or 6600 | ||
Line 69: | Line 77: | ||
url = http://post.audioscrobbler.com/ | url = http://post.audioscrobbler.com/ | ||
username = ''your last.fm username'' | username = ''your last.fm username'' | ||
− | password = ''your last.fm password'' | + | password = ''your last.fm password'' |
journal = /home/''YOUR_USERNAME''/.mpdscribble/lastfm.journal | journal = /home/''YOUR_USERNAME''/.mpdscribble/lastfm.journal | ||
Line 98: | Line 106: | ||
Create a directory for mpdscribble and copy the example .conf | Create a directory for mpdscribble and copy the example .conf | ||
$ mkdir ~/.mpdscribble | $ mkdir ~/.mpdscribble | ||
− | $ cp /usr/share/mpdscribble/mpdscribble.conf.example ~/.mpdscribble.conf | + | $ cp /usr/share/mpdscribble/mpdscribble.conf.example ~/.mpdscribble/mpdscribble.conf |
− | With the current version {{Pkg|mpdscribble 0.22-5}}, adding the sections mentiond above to ~/.mpdscribble.conf is not necessary. Just add your username and password. | + | With the current version {{Pkg|mpdscribble 0.22-5}}, adding the sections mentiond above to {{ic|~/.mpdscribble/mpdscribble.conf}} is not necessary. Just add your username and password. |
Then, edit a new file ~/.config/systemd/user/mpdscribble.service | Then, edit a new file ~/.config/systemd/user/mpdscribble.service | ||
Line 115: | Line 123: | ||
}} | }} | ||
− | Now, enable and start mpdscribble.service as per user | + | Now, enable and start mpdscribble.service as per user |
$ systemctl --user enable mpdscribble | $ systemctl --user enable mpdscribble | ||
$ systemctl --user start mpdscribble | $ systemctl --user start mpdscribble | ||
− | ==== Sonata | + | ==== Sonata and Ario ==== |
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. | 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. | ||
Line 125: | Line 133: | ||
==== lastfmsubmitd ==== | ==== lastfmsubmitd ==== | ||
− | The daemon lastfmsubmitd is a daemon which may be installed from the | + | The daemon lastfmsubmitd is a daemon which may be installed from the official repositories as well. To install it, first edit {{ic|/etc/lastfmsubmitd.conf}} to reflect your requirements and activate both {{ic|lastfmsubmitd}} and {{ic|lastmp}} systemd services. |
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
=== Never play on start === | === Never play on start === | ||
Line 276: | Line 269: | ||
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. | ||
− | === | + | === MPD and PulseAudio === |
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
mpd supports both local and remote use of PulseAudio. | mpd supports both local and remote use of PulseAudio. | ||
Line 312: | Line 292: | ||
==== 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. | + | 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|$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: | 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: | ||
Line 322: | Line 302: | ||
#load-module module-zeroconf-publish | #load-module module-zeroconf-publish | ||
− | Additional IP ranges in cidr notation may be added using {{ic|;}} as the separator. | + | 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 339: | Line 319: | ||
==== Remote ==== | ==== Remote ==== | ||
− | As with any PulseAudio-enabled program, mpd can send sound over the network. | + | 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|$XDG_CONFIG_HOME/default.pa}} (typically {{ic|~/.config/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. | ||
Line 348: | Line 328: | ||
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. | 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 | + | 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}}. |
=== HTTP Streaming === | === HTTP Streaming === | ||
Line 356: | Line 336: | ||
audio_output { | audio_output { | ||
type "httpd" | type "httpd" | ||
− | name "My HTTP Stream" | + | name "My HTTP Stream" |
− | encoder "vorbis" # optional, vorbis or lame | + | encoder "vorbis" # optional, vorbis or lame |
− | port "8000" | + | port "8000" |
− | # quality "5.0" # do not define if bitrate is defined | + | # quality "5.0" # do not define if bitrate is defined |
− | bitrate "128" # do not define if quality is defined | + | bitrate "128" # do not define if quality is defined |
− | format "44100:16:1" | + | format "44100:16:1" |
} | } | ||
Revision as of 14:26, 3 December 2013
Go back to Music Player Daemon.
Contents
Tips and tricks
Organizing
MPD does not provide a tool to preserve the file structure of your audio files. Check out beets or picard.
Last.fm/Libre.fm scrobbling
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's no network connectivity.
mpdasAUR is available in the AUR. Visit the official website for more information.
Configuration of mpdas is very simple, below is an example:
- Edit the file
/etc/mpdasrc
:
/etc/mpdasrc
username = LASTFM USER password = PASSWORD IN MD5 debug = 1 #runas is an optional feature. It change the user mpdas runs as runas = USERNAME #host is an optional feature to set the current mpd host host = HOST #mpdpassword is an optional feature to set the current mpd password mpdpassword = MPDPASS #port is an optional feature to set the current mpd port port = MPDPORT
A very basic example of /etc/mpdasrc
is also available as /etc/mpdasrc
.
To get your password in md5 hash, just run:
echo -n 'PASSWORD' | md5sum | cut -f 1 -d " "
- Add
mpdas
to the file in which you startmpd
as well (e.g.~/.xinitrc
):
pidof mpdas >& /dev/null if [ $? -ne 0 ]; then mpdas & fi
mpdcron
mpd 'cron-daemon' that listens for events and executes user defined stuff.
mpdcron-gitAUR is available in the AUR. Visit the official website for more information.
mpdscribble
mpdscribbleAUR is a daemon available in the AUR (if you prefer, mpdscribble-gitAUR is also available). 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.
After you have installed mpdscribble, do the following (not as root):
$ mkdir ~/.mpdscribble
- Create the file
~/.mpdscribble/mpdscribble.conf
and add the following:
~/.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 sleep = 1 musicdir = your music directory 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
Please note that passwords can also be written down as MD5:
echo -n 'PASSWORD' | md5sum | cut -f 1 -d " "
- Add
mpdscribble
to the file in which you startmpd
as well (e.g.~/.xinitrc
):
pidof mpdscribble >& /dev/null if [ $? -ne 0 ]; then mpdscribble & fi
mpdscribble per user with systemd
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.
Install mpdscribble.
Create a directory for mpdscribble and copy the example .conf
$ mkdir ~/.mpdscribble $ cp /usr/share/mpdscribble/mpdscribble.conf.example ~/.mpdscribble/mpdscribble.conf
With the current version mpdscribble 0.22-5, adding the sections mentiond above to ~/.mpdscribble/mpdscribble.conf
is not necessary. Just add your username and password.
Then, edit a new file ~/.config/systemd/user/mpdscribble.service
~/.config/systemd/user/mpdscribble.service
[Unit] Description = MPD Scribbler [Service] ExecStart = /usr/bin/mpdscribble -D Restart = always [Install] WantedBy = default.target
Now, enable and start mpdscribble.service as per user
$ systemctl --user enable mpdscribble $ systemctl --user start mpdscribble
Sonata and Ario
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.
lastfmsubmitd
The daemon lastfmsubmitd is a daemon which may be installed from the official repositories as well. To install it, first edit /etc/lastfmsubmitd.conf
to reflect your requirements and activate both lastfmsubmitd
and lastmp
systemd services.
Never play on start
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 mpd.conf
file 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 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 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 "HDA Intel" # Can be called anything or nothing tmk, but must be present. 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. 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.
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".
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 useful 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.
MPD and PulseAudio
mpd supports both local and remote use of 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.
If you want to start mpd with systemd, put the following file into /etc/systemd/system/mpd-myuser.service
:
.include /usr/lib/systemd/system/mpd.service [Unit] Description=Music Player Daemon (running as MYUSER) [Service] User=MYUSER PAMName=system-local-login
(replacing MYUSER for your username). Then do sudo systemctl enable mpd-myuser && sudo systemctl start mpd-myuser
.
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/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
.
HTTP Streaming
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 { type "httpd" name "My HTTP Stream" encoder "vorbis" # optional, vorbis or lame 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" }
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