Sunday, April 24, 2016

how to configure mpd to output audio via pulseaudio and alsa

mpd (Music Player Daemon), it plays audio file such as mp3, wav, aac, ogg, etc in form as daemon, so you have to have a front end application to manage it, both can be cli or gui, and can also manage it from browser (http), or from mobile devices.

we can configure its audio output to
- alsa
- or just null it

*** if we output audio to alsa ****
1- install mpd to our system
$ sudo apt-get install mpd

2- edit mpd configuration file, /etc/mpd.conf as below (the music files store in /home/user1/Music)

music_directory        "/home/user1/Music"
playlist_directory        "/var/lib/mpd/playlists"
db_file            "/var/lib/mpd/tag_cache"
log_file            "/var/log/mpd/mpd.log"
pid_file            "/run/mpd/pid"
state_file            "/var/lib/mpd/state"
sticker_file                   "/var/lib/mpd/sticker.sql"
user                "mpd"
bind_to_address        "localhost"
password                        "password@read,add,control,admin"
input {
        plugin "curl"
audio_output {
       type            "alsa"
       name            "My ALSA Device"
       device          "hw:0,0" 

       format          "44100:16:2"    # optional
       mixer_device    "default"       # optional
       mixer_control   "Master"
       mixer_index     "0"             # optional
       mixer_type      "software"

filesystem_charset        "UTF-8"
id3v1_encoding            "UTF-8"

3- restart mpd service with exec the following command
$ sudo /etc/init.d/mpd restart

4- now you can use mpd client like cantata to start listen to music on online radio streaming

-cantata playing online radio screenshot

*** if we output audio to pulseaudio ***

1- edit pulse configuration /etc/pulse/ as bellow. this is configuration we add tcp access and allow ip and only
load-module module-device-restore
load-module module-stream-restore
load-module module-card-restore
load-module module-augment-properties
load-module module-switch-on-port-available
load-module module-udev-detect
load-module module-detect
load-module module-jackdbus-detect channels=2
load-module module-bluetooth-policy
load-module module-bluetooth-discover
load-module module-esound-protocol-unix
load-module module-native-protocol-unix
load-module module-native-protocol-tcp auth-ip-acl=; auth-anonymous=1
load-module module-zeroconf-publish
load-module module-gconf
load-module module-default-device-restore
load-module module-rescue-streams
load-module module-always-sink
load-module module-intended-roles
load-module module-suspend-on-idle
load-module module-console-kit
load-module module-systemd-login
load-module module-position-event-sounds
load-module module-filter-heuristics
load-module module-filter-apply

2- restart pulse service to make the new modify configuration take affect
$ sudo /etc/init.d/pulseaudio restart

3- add mpd user to group audio, pulse and pulse-access group
$ sudo usermod -a -G audio mpd
$ sudo usermod -a -G pulse mpd
$ sudo usermod -a -G pulse-access mpd 

4- edit mpd configuration file, /etc/mpd.conf as below
 music_directory        "/home/tun/mysongs"
playlist_directory        "/var/lib/mpd/playlists"
db_file            "/var/lib/mpd/tag_cache"
log_file            "/var/log/mpd/mpd.log"
pid_file            "/run/mpd/pid"
state_file            "/var/lib/mpd/state"
sticker_file                   "/var/lib/mpd/sticker.sql"
user                "mpd"
bind_to_address        "localhost"
password                        "password@read,add,control,admin"
input {
        plugin "curl"
audio_output {
    type        "pulse"
    name        "My Pulse Output"
    server        "localhost"
filesystem_charset        "UTF-8"
id3v1_encoding            "UTF-8"

5- restart the mpd service then we're ready to use it. and the mpd will output to pulseaudio, that it will share the audio device among programs that access to audio device, that is unlike alsa, that it will make the device not available to other applications if one application use .
$ sudo /etc/init.d/mpd restart

No comments:

Post a Comment