MPD (Français)
From ArchWiki
i18n |
---|
English |
Polski |
Nederlands |
Русский |
简体中文 |
Türkçe |
Français |
Contents |
Qu'est-ce que mpd ?
mpd (Music Player Daemon) est un player audio qui utilise une architecture serveur-client. mpd reste en arrière plan en temps que daemon, gère les listes de lecture et une base de données des morceaux, et utilise très peu de ressources. Pour communiquer avec mpd, vous avez besoin d'un client à part. Vous pouvez avoir plus d'informations sur leur site web.
Procédure d'installation du daemon
Installez le avec pacman:
# pacman -S mpd
Maintenant, ajouer l'utilisateur mpd au groupe des utilisateurs :
# gpasswd -a mpd users
Instructions d'installation
Pour plus d'informations sur la configuration de mpd, allez voir http://mpd.wikia.com/wiki/Configuration
Suivi du comportement de mpd sur une installation basique fonctionnelle
- mpd se lance au démarrage avec le /etc/rc.conf, en étant inclus à la ligne DAEMONS. (Cela peut également être fait manuellement à chaque lancement en lancant /etc/rc.d/mpd start avec les droits root).
- Puisque mpd est démarré en temps que root, il lit d'abord le fichier /etc/mpd.conf.
- mpd lit la variable user dans le fichier /etc/mpd.conf, et passe de root à cet utilisateur.
- mpd lit alors le contenu du fichier /etc/mpd.conf et se configure selon ce fichier.
Notez que mpd passe de root à l'utilisateur nommé dans le fichier /etc/mpd.conf. De ce fait, l'utilisation du caractère "~" dans le fichier de configuration pointera correctement vers le dossier "home" de l'utilisateur, et non vers celui du "root". Il pourrait être intéressant de changer tous les "~" en "/home/nom_de_l'utilisateur" pour éviter toute confusion.t
Un fichier de configuration propre
- En tant que root, vérifiez si /etc/mpd.conf existe et supprimez le fichier si il existe. Pas de danger.
Mpd est fourni avec un fichier de configuration d'exemple, disponible à /etc/mpd.conf.example. Ce fichier contient beaucoup d'informations sur la configuration de mpd, et a les valeurs par défaut du mixeur de son que vous pouvez simplement décommenter.
- En tant que root, copiez ce fichier d'exemple vers /etc/mpd.conf.
# cp /etc/mpd.conf.example /etc/mpd.conf
Ne mettez jamais ce fichier dans le répertoire de l'utilisateur comme certains tutoriaux le suggèrent. Cela compliquerait les choses et la plupart du temps le faire est inutile (notez que vous êtes en train de lire un tutorial d'installation rapide). Si vous avez déjà crée un fichier .mpdconf dans votre home, enlevez le maintenant. C'est important pour empêcher les conflits. En le plaçant dans /etc, comme on l'a fait ici, mpd pourra se lancer en tant que daemon au démarrage. Sinon, un script devra être lancé APRÈS que l'utilisateur se soit connecté (comme kdm ou ~/.fluxbox/starttup) ou bien ça demanderait un déplacmenet manuel à chaque fois. Pour une unique collection de musique, la méthode utilisée ici est juste meilleure, même si la collecion est partagée par de plusieurs utilisateurs. Aussi, n'ayez pas peur des droits root: même si mpd se lance en daemon, il ne se lance jamais complètemeny avec les droits root vu qu'il laisse ces droits à l'exécution.
Sound Setup Correctly
Pour que la sortie audio marche maintenant, assurez vous que vous avez bien installé votre carte audio et le mixeur correctement. Voyez ALSA. N'oubliez pas d'activer les canaux requis dans alsamixer, augmentez le volume et sauvez les changements avec alsactl store. Lisez ~/.mpd/error si ça ne marche toujours pas.
Assurez vous que votre carte peut mixer le son de manière matérielle (la plupart peuvent, onboard audio incluses). Sinon cela pourrait poser des problèmes avec plusieurs lecteurs de son. Par exemple, cea peut empêcher Mplayer de lire du son pendant que le daemon mpd est lancé, en renvoyant un message d'erreur disant que la ressource est occupée.
Editing mpd.conf
Pour éditer le fichier, en tant que root :
# VOTREÉDITEUR /etc/mpd.conf
Keeps the setup in /var and uses "mpd" as default user instead of cluttering up ~/. This is the way the arch package is installed.
Editez le /etc/mpd.conf pour qu'il ressemble à ça
music_directory "/home/user/music" # votre dossier de musique playlist_directory "/var/lib/mpd/playlists" db_file "/var/lib/mpd/db" log_file "/var/log/mpd/mpd.log" error_file "/var/log/mpd/mpd.error" pid_file "/var/run/mpd/mpd.pid" state_file "/var/lib/mpd/mpdstate" user "mpd" # Binding to address and port causing problems in mpd-0.14.2 best to leave # commented. # bind_to_address "127.0.0.1" # port "6600"
Lisez avec attention les étapes ci-dessous, les permissions doivent être réglées proprement.
- Keep user as "mpd", double check to make sure user "mpd" home directory is set to /var/lib/mpd
$ cat /etc/passwd | grep mpd
- lAssurez vous également que /var/lib/mpd est détenu par mpd:mpd.
$ ls -l /var/lib/ | grep mpd
- Maintenant en tant que root crééz les fichiers que vous avez spécifiés dans /etc/mpd.conf, si les répertoires n'existent pas, créés les également. Ce n'est pas nécessaire si vous utilisez les paquet d'arch par défaut.
# touch /var/lib/mpd/db # touch /var/lib/mpd/mpdstate # touch /var/run/mpd/mpd.pid # touch /var/log/mpd/mpd.log # touch /var/log/mpd/mpd.error
- Maintenant rendez l'utilisateur "mpd" propriétaire des répertoires que vous avez créés
# chown -R mpd:mpd /var/lib/mpd # chown -R mpd:mpd /var/run/mpd # chown -R mpd:mpd /var/log/mpd
- Si votre collection musicale est contenue par plusieurs dossiers, vous pouvez faire plusieurs dans /var/lib/mpd et mettre 'music_dir' dans le mpd.conf sur le répertoire contenant les liens symboliques. Souvenez vous de régler les permissions selon les répertoies vers lequels sont dirigés les raccourcis.
- Crééz la base de données de mpd en tant que root.
# mpd --create-db
Installation alternative
Utile si vous voulez par exemple lancer un serveur icecast. MPD n'a pas besoin d'être lancé avec les droits root. La seule raison pour laquelle MPD doit être lancé en tant que root (en étant lancé depuis /etc/rc.conf) est que les fichiers et répertoires de la configuration par défaut pointent vers des répertoires détenus par root (le répertoire /var). Une approche moins habituelle, mais peut-être plus sensible, est de faire marcher MPD avec des fichiers et des répertoires détenus par un utilisateur normal. Lancer MPD en tant qu'utilisateur classique a plusieurs avantages : (1) on peut facilement avoir un seul répertoire ~/.mpd (ou bien n'importe quel répertoire dans /home/nomdutilisateur) pour tous les fichiers de configuration de MPD, (2) pas d'erreurs de lecture/écriture à cause des permissions, et (3) des lancements plus souples de MPD en utlisant ~/.xinitrc au lieu d'inclure 'mpd' à la ligne DAEMONS dans le /etc/rc.conf.
Les étapes ci-dessous montrent comment lancer MPD en tant que simple utilisateur.
- Copiez le contenu du fichier de configuration d'exemple de MPD dans /etc/mpd.conf.example vers votre home. Un bon endroit pourrait être "/home/usr/.mpd/config".
- Follow the 'old setup instructions' from above, ignoring the first part about copying the config to /etc/mpd.conf.
- Let MPD start on bootup by calling it from your ~/.xinitrc as follows:
$ mpd /home/username/.mpd/config
- Note that you don't have to put a "&" at the end of the line here, since MPD will automatically daemonize itself.
Lastly, delete the entry 'mpd' from your DAEMONS array in /etc/rc.conf, as we are not running it as root anymore.
Multi-MPD Setup
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., /home/username/.mpd/config-icecast), and only change the log_file, error_file, pid_file, and state_file parameters (e.g., mpd-icecast.log, 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 ~/.xinitrc above. (Just be sure to have a different port number, so as to not conflict with your first MPD daemon).
Troubleshooting
Autodetection failed
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 /etc/mpd.conf over from /etc/mpd.conf.example as mentionned above, you can simply uncomment:
Example for alsa output type:
audio_output { type "alsa" name "My ALSA Device" device "hw:0,0" # optional format "44100:16:2" # optional }
Example for alsa mixer:
mixer_type "alsa" mixer_device "default" mixer_control "PCM"
Note: in case of permission problems when using ESD with mpd run this as root:
# chsh -s /bin/true mpd
Executable Permissions
MPD needs to have +x permissions on ALL parent directories to your music collection (ie. if it's located outisde of "mpd" home directory /var/lib/mpd). By default useradd sets permissions on home dir to 1700 drwx------. So if your like me you will need to change permissions of /home/user. Example... my music collection is located /home/user/music.
# chmod a+x /home/user # chmod -R a+x /home/user/music
Astuces
To get rid of timeouts (i.e. when you paused music for long time) in gpmc and other clients uncomment and increase connection_timeout option in mpd.conf.
If files and/or titles are shown in wrong encoding, uncomment and change filesystem_charset and id3v1_encoding options. Note that you cannot set encoding for ID3 v2 tags. To workaround this you may use external tag readers.
If you want to use another computer to control mpd over a network, the bind_to_address option in mpd.conf will need to be set to either your IP address, or any if your IP address changes frequently. Remember to add mpd to the /etc/hosts.allow file to enable external access.
Client Install Procedure
Install a client program for mpd. Popular options are:
- mpc – client en LIgne de Commande (vous le voudrez probablementde toute façon)
- ncmpc – Client en NCurses (celui là est très pratique à lancer dans une console) Site officiel de ncmpc
- ncmpcpp – Clone de ncmpc avec quelques nouvelles fonctionnalités, et écrit en C++ Site officiel de ncmpcpp
- pms – Client en NCurses (très configurable et accessible) Site Sourceforge de pms
- ario – Client GTK+ avec un explorateur de collection qui ressemble à celui de Rhythmbox Site officiel d'Ario
- sonata – Client en Python GTK+ Site officiel de Sonata
- gmpc – Client GNOME Site officiel de gmpc
Installez les avec :
# pacman -Sy mpc # pacman -Sy ncmpc # pacman -Sy ncmpcpp # pacman -Sy pms # pacman -Sy ario # pacman -Sy sonata # pacman -Sy gmpc
Extra stuff
Last.fm scrobbling
Pour scrobbler vos chansons vers Last.fm en utilisant MPD il y a plusieurs alternatives.
mpdscribble
mpdscribble is another daemon, but is only available in the 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 /etc at all. Visit the official website for more information.
To install mpdscribble, just install it from the AUR and do the following (not as root):
- $ mkdir ~/.mpdscribble
- Create the file ~/.mpdscribble/mpdscribble.conf and add the following:
username = <your last.fm username> password = <md5 sum of your last.fm password> # Generated using "echo -n password | md5sum" host = <your mpd host> # defaults to $MPD_HOST or localhost port = <your mpd port> # defaults to $MPD_PORT or 6600 log = ~/.mpdscribble/mpdscribble.log journal = ~/.mpdscribble/mpdscribble.cache verbose = 2 sleep = 1 musicdir = <your music directory>
- Add mpdscribble to your ~/.xinitrc.
Sonata
The easiest way, if you don't care about having to have a program window open all the time, is using Sonata which is a graphical frontend to MPD. It has built-in support for Last.fm scrobbling in its preferences. The 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.
lastfmsubmitd
lastfmsubmitd is a daemon which is available in the "community" repository. To install it, first edit /etc/lastfmsubmitd.conf and add both lastfmsubmitd and lastmp to the DAEMONS array in /etc/rc.conf.
Last.fm playback with lastfmproxy
lastfmproxy is a python script that streams a last.fm music stream to another media player. To setup, install from AUR: yaourt -S lastfmproxy 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.
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.
Never play on start
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 /etc/rc.d/mpd file:
... stat_busy "Starting Music Player Daemon"
# always start in paused state awk '/^state_file[ \t]+"[^"]+"$/ { match($0, "\".+\"") sfile = substr($0, RSTART + 1, RLENGTH - 2) } /^user[ \t]+"[^"]+"$/ { match($0, "\".+\"") user = substr($0, RSTART + 1, RLENGTH - 2) } END { if (sfile == "") exit; if (user != "") sub(/^~/, "/home/" user, sfile) system("sed -i \x27s|^\\(state:[ \\t]\\{1,\\}\\)play$|\\1pause|\x27 \x27" sfile "\x27") }' /etc/mpd.conf
/usr/bin/mpd /etc/mpd.conf &> /dev/null ...
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 /etc/pacman.conf:
NoUpgrade = etc/rc.d/mpd
MPD & Alsa
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 /var/log/mpd/mpd.error)
Error opening alsa device "hw:0,0": Device or resource busy
And here is the solution (dmix saving our life again). Apply these lines in your /etc/mpd.conf:
audio_output { type "alsa" name "Sound Card" options "dev=dmixer" device "plug:dmix" }
And then restart with /etc/rc.d/mpd restart.
Searching on Internet I found the reason for why that happens in Gentoo's wiki:
- The sound card does not support hardware mixing (uses dmix plugin)
- An application does not work with ALSA with it's default settings
High CPU usage with ALSA
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.
For most users the problem should be solved by telling MPD not to use resampling by adding auto_resample "no" into audio_output-part of /etc/mpd.conf.
Example from mpd.conf:
audio_output { type "alsa" name "My ALSA Device" auto_resample "no" }
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: MPD wiki
Control mpd with lirc
There are already some clients designe 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.
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.
Problèmes
mpd --create-db échoue
C'est une erreur classique causée par des tags mp3 corrompus. Voici une façon expérimentale de résoudre ce problème.
Requirements:
- kid3
- easytag
This method is very tedious, expecially with a huge database. Just as a baseline it took 2.5h to fix a 16Gb DB.
Easy Tag
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. 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 stoped scanning for songs, make note of the culprit and kill easytag.
KID3
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.
Repeat this procedure until your music library is done.