MPD播放器为C/S架构,MPD为Server,它的Client 有很多,MPC为其典型稳定的Client。
1.源码下载
在github 上有其源码,下载地址:https://github.com/MusicPlayerDaemon/
如下截图包括 MPD,libmpdclient和mpc 三部分,如下截图:
2. 编译
2.1安装所需要的依赖包
1)boost
boost 是C++ 库,mpd 和mpc都是C++,在实现过程会用的boost库,所有需要在ubuntu上先安装boost 。
boost下载地址:http://www.boost.org/users/history/version_1_66_0.html#tar xvzf boost_1_50_0.tar.gz
#cd boost_1_50_0
#sh ./bootstrap.sh
#./b2
编译完后会有如下log输出:
The following directory should be added to compiler include paths:
/home/nicole/work/mpd/boost_1_66_0
The following directory should be added to linker library paths:
/home/nicole/work/mpd/boost_1_66_0/stage/lib
2)meson、Ninja
编译libmpdclient 需要meson、Ninja
meson下载、编译、 安装:
源码下载:https://github.com/mesonbuild/meson
python3 setup.py build
sudo python3 setup.py install
安装Ninja:sudo apt-get install ninja
3)FFmpeg 安装
mpd 是基于FFmpeg 实现的,所有必须在编译mpd 前安装FFmpeg库:
下载地址:https://github.com/FFmpeg/FFmpeg
./configure
make
sudo make install
2.2 编译mpd
1)tar -xf mpd-0.20.18.tar.xz
2)cd mpd-0.20.18
3) ./configure --disable-jack --with-boost=XXX --enable-ffmpeg
--with-boost=指定boost库所在的路径如:/home/nicole/work/mpd/boost_1_66_0
4)make
5)sudo make install
编译成功后,会在src/路径下生产mpd 可执行程序。
2.3 编译libmpdclient
进入libmpdclient 目录,创建编译输出文件夹(mkdir output)
meson . output
ninja -C output
sudo ninja -C output install
可参照:https://github.com/MusicPlayerDaemon/libmpdclient
2.4 编译mpc
方法同libmpdclient:
进入mpc目录,创建编译输出文件夹(mkdir output)
meson . output
ninja -C output
sudo ninja -C output install
可参照:https://github.com/MusicPlayerDaemon/mpc
3. 运行mpd 和mpc
准备好mpd.conf配置文件
在一个终端执行:sudo mpd --stdout --no-daemon --verbose /etc/mpd.conf
打开另一个终端执行mpc,如查询mpd的版本信息:mpc version
mpc 更多命令和使用方法,可执行:mpc help 查看。
4.播放测试
4.1 播放本地音乐
把音乐拷贝到mpd.conf中music_directory所配置的目录下,如我的配置是:
在media目录下已经拷贝了以下几个音频文件
启动mpd 后,通过mpc进行添加播放列表和播放音频文件:
4.2 播放url 资源
gstreamer 上有大量各种格式的音频文件可用于测试:https://gstreamer.freedesktop.org/media/
测试方法同样是先确保mpd 已经起来,然后使用mpc add url
mpc add https://gstreamer.freedesktop.org/media/small/audio-short.ogg
mpc play 2
5. 运行时遇到的问题
问题1:mpc: error while loading shared libraries: libmpdclient.so.2: cannot open shared object file: No such file or directory
解决:sudo ln -sb /usr/local/lib/x86_64-linux-gnu/libmpdclient.so.2.14 /usr/lib/libmpdclient.so.2
问题2:mpc 播放MP3时提示“mpd: Failed to read mixer for 'My ALSA Device': no such mixer control: PCM”,如下log:
alsa_output: opened default type=IOPLUG
alsa_output: buffer: size=48..524288 time=1088..11888617
alsa_output: period: size=16..174763 time=362..3962880
alsa_output: default period_time = buffer_time/4 = 500000/4 = 125000
alsa_output: format=S24_LE (Signed 24 bit Little Endian)
alsa_output: buffer_size=22050 period_size=5512
output: opened plugin=alsa name="hw:0,0" audio_format=44100:24:2
exception: Failed to open mixer for 'hw:0,0': no such mixer control: PCM
player: played "test.mp3"
playlist: stop
output: closed plugin=alsa name="hw:0,0"
解决:修改mpd.conf,
audio_output {
type "alsa"
# name "plug:dmix"
name "My ALSA Device"
# device "plughw:0,0"
# format "44100:16:2" # optional
# mixer_type "software"
# mixer_device "default" # optional
# mixer_control "PCM" # optional
# mixer_index "0" # optional
}
修改为:
audio_output {
type "alsa"
# name "plug:dmix"
name "My ALSA Device"
device "plughw:0,0"
format "44100:16:2" # optional
mixer_type "software"
# mixer_device "default" # optional
# mixer_control "PCM" # optional
# mixer_index "0" # optional
}