Command line music player arch linux

Music Player Daemon

MPD (music player daemon) 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 client is needed.

Contents

Installation

Install the mpd package, or mpd-git AUR for the development version.

Configuration

MPD is able to run in #Per-user configuration or #System-wide configuration mode (settings apply to all users). Also it is possible to run multiple instances of MPD in a #Multi-MPD setup. The way of setting up MPD depends on the way it is intended to be used: a local per-user configuration is easier to setup and may prove more adapted on a desktop system. The system-wide setup might be better suited for a always-on audio server with multiple users but a shared MPD instance.

In order for MPD to be able to playback audio, ALSA, optionally with PulseAudio, must be setup and working. The #Audio configuration section thereafter describes the parameters needed for ALSA or PulseAudio.

MPD is configured in the file mpd.conf(5) which can be located in various paths depending on the setup chosen (system-wide or per-user). In short, the two common locations used are:

/.config/mpd/mpd.conf in per-user configuration mode, this is the first location searched,

  • /etc/mpd.conf in system-wide configuration.
  • These are some of the most commonly used configuration options:

    • pid_file — The file where MPD stores its process ID
    • db_file — The music database
    • state_file — MPD’s current state is noted here
    • playlist_directory — The folder where playlists are saved into
    • music_directory — The folder that MPD scans for music
    • sticker_file — The sticker database

    Per-user configuration

    MPD can be configured per-user. Running it as a normal user has the benefits of:

      Regrouping into one single directory

    /.config/mpd/ (or any other directory under $HOME ) all the MPD configuration files.

  • Avoiding unforeseen directory and file permission errors.
  • Configure the location of files and directories

    In user mode, the configuration is read from $XDG_CONFIG_HOME/mpd/mpd.conf . We will assume here $XDG_CONFIG_HOME equals the default of

    To build the user configuration, the MPD configuration example included in the package is a good starting point, copy it using the following lines:

    A good practice is to use this newly created

    /.config/mpd/ directory to store, together with the configuration file, other MPD related files like the database or the playlists. The user must have read write access to this directory.

    Then edit the configuration file in order to specify the required and optional files and directories:

    If playlists are enabled in the configuration, the specified playlist directory must be created:

    MPD can now be started (an optional custom location for the configuration file can be specified):

    In order to build the database file, MPD must scan into the music_directory defined above. To request this task, one of the MPD clients must be used. For example with mpc the command is:

    or alternatively one can set the option auto_update to «yes» in the configuration to refresh the database whenever files are changed in music_directory .

    Audio configuration

    If ALSA is used, autodetection of the default device should work out of the box without any particular setting. If not, the syntax for ALSA audio output definition is provided thereafter; the required name parameter specifies a unique name for the audio output. The exact device as displayed using aplay —list-pcm from the package alsa-utils can optionally be indicated with the device option.

    Users of PulseAudio will need to make the following modification:

    Starting with version 0.23 of MPD, PipeWire support can be configured:

    Autostart with systemd

    The mpd package provides a user service file. The service starts the process as user, there is no need to change permission nor use the user and group variables in the MPD configuration file.

    Start/enable the user unit mpd.service (i.e. with the —user flag).

    /.config/mpd/mpd.conf , see systemd#Editing provided units if you would like to indicate a custom configuration file path.

    Autostart on tty login

    To start MPD on login add the following to

    Scripted configuration

    The mpd-configure tool creates a MPD configuration optimized for bit perfect audio playback, without any resampling or conversion, using the ALSA interface hardware address (hw:x,y).

    System-wide configuration

    The default /etc/mpd.conf keeps the setup in /var/lib/mpd which is assigned to user as well as primary group MPD.

    Music directory

    The music directory is defined by the option music_directory in the configuration file /etc/mpd.conf .

    MPD needs to have execute permission on all parent directories of the music collection and also read access to all directories containing music files. This may conflict with the default configuration of the user directory, like

    /Music , where the music is stored.

    While there are several solutions to this issue, one of these should be most practical:

    • Switch to the #Per-user configuration mode instead
    • Add the mpd user to the user’s group and grant group execute permission to the user directory. This way the mpd user has permission to open the user directory:
    • Store the music collection in a different path, either:
      • by moving it entirely,
      • with a bind mount,
      • or with Btrfs#Subvolumes (you should make this change persistent with an entry to /etc/fstab ).
    Читайте также:  Изменить место резервного копирования itunes mac os

    The MPD configuration file must define only one music directory. If the music collection is contained under multiple directories, create symbolic links under the main music directory in /var/lib/mpd . Remember to set permissions accordingly on the directories being linked.

    To exclude a file — or files — from the update, create a file called .mpdignore in its parent directory. Each line of that file may contain a list of shell wildcards. Matching files in the current directory and all subdirectories are then excluded from subsequent updates.

    Start with systemd

    MPD can be controlled with mpd.service using systemd. The first startup can take some time as MPD will scan your music directory.

    Test everything by starting a client application ( ncmpc is a light and easy to use client), and play some music!

    Socket activation

    mpd provides a mpd.socket unit. If mpd.socket is enabled (and mpd.service is disabled), systemd will not start MPD immediately, it will just listen to the appropriate sockets. Then, whenever an MPD client attempts to connect to one of these sockets, systemd will start mpd.service and transparently hand over control of these ports to the MPD process.

    If you prefer to listen to different UNIX sockets or network ports (even multiple sockets of each type), or if you prefer not to listen to network ports at all, edit the mpd.socket unit appropriately and modify /etc/mpd.conf to match the configuration (see mpd.conf(5) for details).

    User id startup workflow

    MPD should never run as root, you may use the user option in the configuration to make MPD change its user id after initialization. Do not use this option if you start MPD as an unprivileged user. To describe how MPD drops its superuser privileges and switch to those of the user set in the configuration, the steps of a normal MPD startup are listed thereafter:

    1. Since MPD is started as root by systemd, it first reads the /etc/mpd.conf file.
    2. MPD reads the user variable in the configuration, and changes from root to this user.
    3. MPD then reads the rest of the configuration file and configures itself accordingly. Uses of

    in the configuration file points to the home user’s directory, and not root’s directory.

    Multi-MPD setup

    Running an Icecast server

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

    /.xinitrc above — but be sure to have a different port number, avoiding a conflict with the first MPD daemon.

    Satellite setup

    The method described in #Running an Icecast server 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 concurrently. MPD has a satellite mode where one instance can receive the database from an already running MPD instance.

    In your config-icecast add this, where host and port reflect your primary MPD server:

    Clients

    A separate client is needed to control MPD. See a long list of clients at the mpd website. Popular options are:

    Источник

    Music Player Daemon/Tips and tricks

    Contents

    Organizing library

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

    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 is no network connectivity.

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

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

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

    mpdscribble

    mpdscribble AUR 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.

    A sample config is included: /usr/share/mpdscribble/mpdscribble.conf.example , copy it to

    /.mpdscribble/mpdscribble.conf and edit to suit.

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

    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.

    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.

    YAMS is a Last.FM scrobbling daemon for MPD written in Python.

    As it’s written for v2.0 of Last.FM’s scrobbling API, YAMS does not store your username or password locally, but opts to use a cookie instead. Similar to other scrobblers, YAMS can save failed scrobbles and upload them at a later date. It also offers a decent amount of configuration options for when/how a scrobble should be made (including ignoring duplicate scrobbles when a track is played multiple times in a row).

    In order to authenticate, the user must run the yams command in an interactive terminal, at least once, and follow the printed instructions.

    Afterwards, YAMS can be started with its binary:

    yams runs as a daemon by default ( yams -N will run it in the foreground).

    yams -k will kill the current running instance.

    yams -a will attach to the current running instance’s log file, allowing you to watch the daemon’s output.

    yams -h will print all command line options.

    YAMS also comes with a systemd service file that can be started with systemctl —user start yams after authentication is complete.

    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.

    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 :

    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

    Fill the file with the following pattern:

    There are more functions for mpc, run mpc(1) 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, edit the PulseAudio configuration — either the user configuration in $XDG_CONFIG_HOME/pulse/default.pa (typically

    /.config/pulse/default.pa ) if it exists, otherwise the system-wide configuration file in /etc/pulse/default.pa and uncomment the TCP module and set 127.0.0.1 as an allowed IP address like this:

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

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

    Once this is added, restart 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. This allows MPD to broadcast its music to HTTP clients.

    This is not meant to be used as a streaming solution (e.g. replacement of Spotify, Deezer, etc.). First, it only allows one stream to be played, and multiple users cannot listen to multiple musics at the same time. Second, MPD buffers audio a lot so that it plays reliably even when the client drops the connection for a while, therefore it introduces a non-negligeable latency when changing songs. To use MPD as a streaming solution, see #Music streaming with the satellite setup.

    Configuration

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

    Format

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

    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:

    Music streaming with the satellite setup

    While #HTTP streaming allows the user to broadcast its music over HTTP, the satellite setup allows multiple users to listen to different songs at the same time, on separate machines.

    Topology

    The satellite setup involves two or more machines: a server and multiple clients. The server is typically the machine that has the music files. It runs an MPD instance that will browse these files and build a database. The clients are the machines that will actually play the music (e.g. your phone or your laptop). They will also run MPD instances, though these ones will fetch the database from the server MPD and play the music. You might notice that MPD on the server is not necessary, however it greatly increases the speed to list all songs, as the client’s MPD will not have to browse all the files remotely.

    Besides, you will need a way for the server to make the music files available to the clients. MPD supports multiple storage plugins to fetch the music with. For example, if you choose the curl plugin, you will need a WebDAV server on the server.

    Finally, you will need a secure communication tunnel between the server and each client. This is because the protocol used to control MPD is not encrypted and does not provide authentication. A VPN or a SSH tunnel will be useful here.

    Configuration

    On the server, write the configuration file for the MPD instance that will build the database:

    Then, setup either the WebDAV server, the NFS server or the Samba share.

    On each client, write the configuration file for the MPD instance that will play the music:

    MPRIS support

    mpDris2

    Install the mpDris2 AUR 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

    It should now be autorun at login.

    mpd-mpris

    After installation, you can start or enable the mpd-mpris.service user service through systemd.

    By default mpd-mpris connects to localhost:6600 (which is the default host/port of mpd). To change this settings copy /usr/lib/systemd/user/mpd-mpris.service to

    /.config/systemd/user/ then edit run parameters as needed.

    Notifications

    The mpDris2 AUR package optionally supports displaying graphical notifications. If you do not want mpris support and are looking for a more lightweight or specific option, here are some alternatives:

    musnify-mpd

    musnify-mpd is a simple python script that provides notification support for Music Player Daemon using libnotify . It can also display the album covers loaded from last fm or load it from the user-local music library.

    After installation you may want to configure your mpd host and port. To do this copy the «.example» file into

    To enable artworks from last.fm, you will need to edit

    /.config/musnify-mpd and provide a apiKey. You can create your apiKey here

    mpd-notification

    Notify about tracks played by mpd . This runs in the background and produces notifications whenever mpd produces an event (e.g. new track is played, playback paused or stopped). This also supports local or .mp3 album artworks.

    After installation, just run mpd-notification to run it once. A systemd user service can be enabled with

    Adding a separate volume control (ALSA)

    While MPD does not allow you to adjust its own volume by default ( mpc volume affects global volume), you can easily make a MPD-specific volume slider using the softvol ALSA module. Just add this to asound.conf :

    And link it to MPD:

    Afterwards you should be able to adjust song volume both through mpc and amixer . (You may need to reboot for the control to work properly.)

    Control the remote mpd server

    To control the remote mpd server, if you have an ssh server on the same machine, you can login and use ncmpcpp to control it.

    Or, if your mpd server is listening on an accessible interface/port ( $ ss -p -l -t on the mpd machine will show mpd listening on 0.0.0.0, for example) then you can set the MPD_HOST variable which directs a local client like mpc to the remote server.

    Источник

    Читайте также:  Intel i219lm linux driver
    Оцените статью