MPD播放器为C/S架构,MPD为Server,它的Client 有很多,MPC为其典型稳定的Client。
MPD 简介
MPD官网: https://www.musicpd.org/
OPENWRT安装教程: https://tnetter.wordpress.com/2015/03/14/install-mpd-di-openwrt/
用户手册:https://www.musicpd.org/doc/user/ 用户手册:https://mpd.readthedocs.io/en/stable/user.html
开源代码
基于web的MPD GUI:https://ympd.org/
1.源码下载
在github 上有其源码
下载地址:https://github.com/MusicPlayerDaemon/
包括
- MPD
- libmpdclient
- mpc
2. 编译
编译环境要求
- C++17 编译器 (例如: GCC 8 or clang 7)
- Meson 0.56.0 and Ninja
- Boost 1.58
- pkg-config
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 Boost C++ Libraries were successfully built!
The following directory should be added to compiler include paths:
/home/mpddev/code/mpd/boost_1_66_0
The following directory should be added to linker library paths:
/home/mpddev/code/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
tar -xf mpd-0.20.18.tar.xz
cd mpd-0.20.18
./configure --disable-jack --with-boost=XXX --enable-ffmpeg
说明:
--with-boost=
指定boost库所在的路径如:/home/mpddev/code/mpd/boost_1_66_0
make
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配置文件
/etc/mpd.conf
内容:
music_directory "/Media/SD-P1/music"
playlist_directory "/Media/SD-P1/music/.mpd"
db_file "/Media/SD-P1/music/.mpd/mpd.db"
log_file "/Media/SD-P1/music/.mpd/mpd.log"
pid_file "/Media/SD-P1/music/.mpd/mpd.pid"
state_file "/Media/SD-P1/music/.mpd/mpd.state"
bind_to_address "any"
port "6600"
audio_output {
type "alsa"
name "MT7688"
use_mmap "yes"
mixer_control "Playback"
}
直接运行,在一个终端执行:
sudo mpd --stdout --no-daemon --verbose /etc/mpd.conf
作为启动mpd服务
/etc/init.d/mpd restart
打开另一个终端执行mpc
如查询mpd的版本信息:
mpc version
mpc 更多命令和使用方法,可执行:mpc help
查看。
4.播放测试
4.1 播放本地音乐
把音乐拷贝到mpd.conf中music_directory所配置的目录下,如我的配置是:
music_directory "/Media/SD-P1/music"
复制一个mp3文件到/Media/SD-P1/music
目录下,并改名为test.mp3
等。
启动mpd后,通过mpc进行添加播放列表和播放音频文件:
mpc add test.mp3
mpc play 1
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
}