--- layout: post title: "安装和配置 MPD" description: "使用 i3 窗口管理器,感觉很舒服,更有帅帅的 i3status 点缀之,在 GitHub 搜了下,发现有个 i3status 修改版,可以显示 MPD 的播放状态,于是又用起 MPD。" category: tech thumb: IMG_PATH/archlinux.svg tags: [MPD, MPC, 播放器] --- * toc {:toc} 使用 i3 窗口管理器,感觉很舒服,更有帅帅的 i3status 点缀之,在 GitHub 搜了下,发现有个i3status 修改版[[1]][1],可以显示 MPD 的播放状态,于是又用起 MPD。 MPD [[2]][2] 是一个实用的音乐播放器,以其独特的 C/S 结构获得人们的喜爱。充其量 MPD 只是作为一个守护进程(或者可以说服务)运行于后台,想要控制它的播放,还需要一个客户端,一般只选用 MPC (Music Player Command), MPC 虽为命令行客户端,但已够用。 下面一起来安装配置 MPD,获得恰到好处的使用体验 ## MPD 安装 MPD, MPC # pacman -S mpd mpc 创建 MPD 的配置文件
~/.mpdconf
music_directory "~/Music/"
playlist_directory "~/.mpd/playlists"
db_file "~/.mpd/database"
log_file "~/.mpd/log"
pid_file "~/.mpd/pid"
state_file "~/.mpd/state"
user "fooleap"
group "users"
bind_to_address "localhost"
port "6600"
audio_output {
type "alsa"
name "My ALSA Device"
mixer_control "Master"
}
更多配置可参考 /usr/share/mpd/mpd.conf.example
$ mkdir -p ~/.mpd/playlists
$ touch ~/.mpd/{database,log,pid,state}
至此,可直接运行 mpd 命令以启动
通过 systemd 设置自启,默认配置不是普通用户的,遂先修改 mpd.service 文件,指定配置
/usr/lib/systemd/system/mpd.service
...
[Service]
ExecStart=/usr/bin/mpd /home/fooleap/.mpdconf --no-daemon
...
# systemctl enable mpd
## 均衡器
播放器是有了,但 MPD 不带均衡器,在此使用 Alsaequal[[3]][3] 充当均衡器
安装
$ yaourt -S alsaequal caps
配置
~/.asoundrc
ctl.equal {
type equal;
}
pcm.plugequal {
type equal;
# Modify the line below if you do not
# want to use sound card 0.
#slave.pcm "plughw:0,0";
#by default we want to play from more sources at time:
slave.pcm "plug:dmix";
}
#pcm.equal {
# If you don't want the equalizer to be your
# default soundcard comment the following
# line and uncomment the above line. (You can
# choose it as the output device by addressing
# it with specific apps,eg mpg123 -a equal 06.Back_In_Black.mp3)
pcm.!default {
type plug;
slave.pcm plugequal;
}
重启 Alsa 后,可调整增益值
$ alsamixer -D equal
![Alsaequal]({{site.IMG_PATH}}/installation-and-configuration-mpd-01.png)
配置 MPD
~/.mpdconf
...
audio_output {
type "alsa"
name "My ALSA Device"
device "plug:plugequal"
mixer_control "Master" # optional
}
...
## MPC
尝试播放
$ mpc listall | mpc add
$ mpc play
~/.xbindkeysrc
"mpc toggle"
XF86AudioPlay
"mpc stop"
XF86AudioStop
"mpc prev"
XF86AudioPrev
"mpc next"
XF86AudioNext
"amixer sset Master 2-"
XF86AudioLowerVolume
"amixer sset Master 2+"
XF86AudioRaiseVolume
"amixer sset Master toggle"
XF86AudioMute
将 xbindkeys & 添加到 ~/.xinitrc 使其随 X 启动
## 键映射
在此之前,可能需要通过 Xmodmap[[5]][5] 修改键映射
~/.Xmodmap
!Media
keycode 173 = XF86AudioPrev
keycode 172 = XF86AudioPlay
keycode 171 = XF86AudioNext
keycode 174 = XF86AudioStop
!Volume
keycode 121 = XF86AudioMute
keycode 122 = XF86AudioLowerVolume
keycode 123 = XF86AudioRaiseVolume
将 xmodmap ~/.Xmodmap & 添加到 ~/.xinitrc 使其随 X 启动
![i3status with mpd]({{site.IMG_PATH}}/installation-and-configuration-mpd-02.png)
i3status with mpd
## 参考资料
[1]: https://github.com/Gravemind/i3status "i3status 修改版"
[2]: https://wiki.archlinux.org/index.php/Music_Player_Daemon "Music Player Daemon"
[3]: http://www.thedigitalmachine.net/alsaequal.html "Alsaequal"
[4]: https://wiki.archlinux.org/index.php/Xbindkeys "Xbindkeys"
[5]: https://wiki.archlinux.org/index.php/Xmodmap "Xmodmap"
**本文历史**
* 2012 年 12 月 01 日 创建文章
* 2012 年 12 月 02 日 修正 mpc 歌曲列表部分的错误
* 2012 年 12 月 15 日 添加配置均衡器
* 2015 年 05 月 24 日 换图床