首先路由器上要有usb接口,然后还需要有个usb声卡。随便X宝上买个几块钱的那种免驱的usb声卡就能用。
方式一:手机控制播放OpenWrt上的音乐(播放的数据来源路由本身)
这种方式下,一般还需要一个usb分线器(X宝上买个十来块,4口的usb hub,不太差的就行)和一个u盘,u盘上创建个“mp3”目录和“.mpd”目录,往这个目录放些mp3格式的歌曲(wma的就不要放进去了,播放太吃力了,在make kernel_menuconfig的是选上了 浮点模拟,测试没什么效果)。
自己编译固件,make menuconfig时选择
Base system-->block-mount
Kernel modules-->Filesystems-->kmod-fs-ext4
Kernel modules-->Filesystems-->kmod-fs-msdos
Kernel modules-->Filesystems-->kmod-fs-ntfs
Kernel modules-->Filesystems-->kmod-fs-vfat
Kernel modules-->Native Language Support-->kmod-nls-utf8
Kernel modules-->Native Language Support-->kmod-nls-cp437
Kernel modules-->Sound Support-->kmod-sound-core
Kernel modules-->Sound Support-->kmod-usb-audio
Kernel modules-->USB Support-->kmod-usb-hid
Kernel modules-->USB Support-->kmod-usb-storage
Kernel modules-->USB Support-->kmod-usb-storage-extras
Kernel modules-->USB Support-->kmod-usb2
Libraries-->libffmpeg-mini
Sound-->madplay #测试用
Sound-->mpd-full
Utilities-->alsa-utils
刷固件或安装上面编译的软件包,然后就是在openwrt系统下挂载u盘到/tmp/extroot,其他地方也行。用命令:madplay /tmp/extroot/mp3/xx.mp3测试看看能否正常播放。然后运行amixer命令或者控制器,我这里获取到是“Speaker”,在编辑/etc/mpd.conf文件和/etc/init.d/mpd文件时会用到。
root@OpenWrt:/etc# amixer
Simple mixer control 'Speaker',0
Capabilities: pvolume pswitch pswitch-joined
Playback channels: Front Left - Front Right
Limits: Playback 0 - 151
Mono:
Front Left: Playback 83 [55%] [-12.81dB] [on]
Front Right: Playback 83 [55%] [-12.81dB] [on]
Simple mixer control 'Mic',0
Capabilities: pvolume pvolume-joined cvolume cvolume-joined pswitch pswitch-joined cswitch cswitch-joined
Playback channels: Mono
Capture channels: Mono
Limits: Playback 0 - 127 Capture 0 - 16
Mono: Playback 64 [50%] [11.99dB] [off] Capture 9 [56%] [13.39dB] [on]
Simple mixer control 'Auto Gain Control',0
Capabilities: pswitch pswitch-joined
Playback channels: Mono
Mono: Playback [on]
vi编辑/etc/mpd.conf配置文件。内容如下:
//vi /etc/mpd.conf
#=== edit options as follows ===
music_directory "/tmp/extroot/mp3"
playlist_directory "/tmp/extroot/.mpd/playlist"
db_file "/tmp/extroot/.mpd/mpd.db"
log_file "/tmp/extroot/.mpd/mpd.log"
#error_file "/tmp/extroot/.mpd/mpd.error"
pid_file "/tmp/extroot/.mpd/mpd.pid"
state_file "/tmp/extroot/.mpd/mpdstate"
user "root"
group "users"
bind_to_address "0.0.0.0"
port "6600"
# use this if you want to use OSS audio output
audio_output {
type "alsa"
name "My ALSA Device"
device "hw:0,0"
format "44100:16:2"
mixer_control "Speaker" #Speaker是amixer命令获取到的
}
auto_update "yes"
gapless_mp3_playback "yes"
filesystem_charset "UTF-8"
id3v1_encoding "GBK"
#=== edit end ===
编辑/etc/init.d/mpd,修改如下:
# Set the initial volume to something manageable
[ -x /usr/bin/amixer ] && /usr/bin/amixer set PCM 40
改成
# Set the initial volume to something manageable
[ -x /usr/bin/amixer ] && /usr/bin/amixer set Speaker 80% >/dev/null 2>&1
然后将下面的
if [ -x /bin/nice ]; then
# This has real-time constraints, so let's at least tell the OS
# that this should have higher priority to avoid skipping
# when doing other things in the background.
nice -n -10
fi
改成
if [ -x /bin/nice ]; then
# This has real-time constraints, so let's at least tell the OS
# that this should have higher priority to avoid skipping
# when doing other things in the background.
nice -n -10 "/usr/bin/mpd" # nice -n -10的后面添加"/usr/bin/mpd"
fi
运行如下命令,正常的话,就可以用手机控制播放路由器上的音乐了。
root@OpenWrt:/etc/init.d/mpd enable
root@OpenWrt:/etc/init.d/mpd start
安卓手机端控制软件用“mpd播放器”。
方式二:手机推送音乐到OpenWrt上播放(播放的数据来源是手机)
此方式不需要usb hub和u盘。首先在openwrt源码目录下:
./scripts/feeds update -a
./scripts/feeds install -a
然后就是要加入gmediarender软件,openwrt没有这此软件包,需自行加入,添加gmediarender软件包的补丁文件gmrender.patch如下:
// gmrender.patch 文件
--- /dev/null 2014-10-09 15:03:28.117439574 +0800
+++ feeds/packages/multimedia/gmediarender/files/gmediarender.config 2014-10-15 11:09:43.520258640 +0800
@@ -0,0 +1,7 @@
+config gmediarender 'core'
+ option enabled '1'
+ option name 'OpenWrtRender'
+ option mixer 'Speaker'
+ option mixervolume '80%'
+ option rendervolume '-10'
+ option alsadevice 'sysdefault'
--- /dev/null 2014-10-09 15:03:28.117439574 +0800
+++ feeds/packages/multimedia/gmediarender/files/gmediarender.init 2014-10-15 14:14:06.004563683 +0800
@@ -0,0 +1,44 @@
+#!/bin/sh /etc/rc.common
+
+START=90
+STOP=10
+
+USE_PROCD=1
+PROG=/usr/bin/gmediarender
+
+start_instance()
+{
+ config_get_bool enabled "$1" 'enabled' 0
+ [ $enabled -eq 0 ] && return
+
+ config_get name "$1" 'name' 'OpenWrtRender'
+ config_get mixer "$1" 'mixer'
+ config_get mixervolume "$1" 'mixervolume'
+ config_get rendervolume "$1" 'rendervolume' '-10'
+ config_get alsadevice "$1" 'alsadevice'
+ uuid=`ip link show | awk '/ether/ {print "salt:)-" $2}' | head -1 | md5sum | awk '{print $1}'`
+
+ [ -n "$mixer" -a -n "$mixervolume" -a -x "/usr/bin/amixer" ] &&
+ /usr/bin/amixer set "$mixer" "$mixervolume" >/dev/null 2>&1
+
+ if [ -n "$alsadevice" ]; then
+ sinkparam="--gstout-audiosink=alsasink"
+ deviceparam="--gstout-audiodevice=$alsadevice"
+ fi
+
+ procd_open_instance
+ procd_set_param command "$PROG" -f "$name" -u "$uuid" --gstout-initial-volume-db=$rendervolume $sinkparam $deviceparam
+ procd_close_instance
+}
+
+start_service()
+{
+ config_load 'gmediarender'
+ config_foreach start_instance 'gmediarender'
+}
+
+service_triggers()
+{
+ procd_add_reload_trigger 'gmediarender'
+}
+
--- /dev/null 2014-10-09 15:03:28.117439574 +0800
+++ feeds/packages/multimedia/gmediarender/files/gmediarender.hotplug 2014-10-15 13:42:49.752511946 +0800
@@ -0,0 +1,15 @@
+case "$ACTION" in
+ add)
+ if [ -c "/dev/audio" ] &&
+ !(pgrep -f gmediarender >/dev/null 2>&1) &&
+ [ -x "/usr/bin/gmediarender" ]; then
+ /etc/init.d/gmediarender start
+ fi
+ ;;
+ remove)
+ if [ ! -c "/dev/audio" ] &&
+ (pgrep -f gmediarender >/dev/null 2>&1); then
+ /etc/init.d/gmediarender stop
+ fi
+ ;;
+esac
--- /dev/null 2014-10-09 15:03:28.117439574 +0800
+++ feeds/packages/multimedia/gmediarender/Makefile 2014-10-15 11:20:44.788276874 +0800
@@ -0,0 +1,56 @@
+#
+# Copyright (C) 2013 OpenWrt.org
+#
+# This is free software, licensed under the GNU General Public License v2.
+# See /LICENSE for more information.
+#
+
+include $(TOPDIR)/rules.mk
+
+PKG_NAME:=gmediarender
+PKG_REV:=275
+PKG_VERSION:=r$(PKG_REV)
+PKG_RELEASE:=1
+
+PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.gz
+PKG_SOURCE_URL:=https://github.com/hzeller/gmrender-resurrect/trunk
+PKG_SOURCE_SUBDIR:=$(PKG_NAME)-$(PKG_VERSION)
+PKG_SOURCE_VERSION:=$(PKG_REV)
+PKG_SOURCE_PROTO:=svn
+
+PKG_FIXUP:=autoreconf
+PKG_INSTALL=1
+PKG_REMOVE_FILES:=autogen.sh aclocal.m4
+
+include $(INCLUDE_DIR)/package.mk
+include $(INCLUDE_DIR)/nls.mk
+
+define Package/gmediarender
+ SECTION:=multimedia
+ CATEGORY:=Multimedia
+ DEPENDS:= +gstreamer +glib2 +libupnp
+ TITLE:=A Headless UPnP Renderer
+endef
+
+define Package/gmediarender/description
+ gmediarender implements the server component that provides UPnP
+ controllers a means to render media content (audio, video and images)
+ from a UPnP media server.
+endef
+
+CONFIGURE_ARGS+= \
+ --with-build-cc="$(HOSTCC)" \
+ --prefix="/usr"
+
+define Package/gmediarender/install
+ $(INSTALL_DIR) $(1)/usr/bin
+ $(INSTALL_BIN) $(PKG_INSTALL_DIR)/usr/bin/$(PKG_NAME) $(1)/usr/bin/
+ $(INSTALL_DIR) $(1)/etc/config
+ $(CP) ./files/gmediarender.config $(1)/etc/config/gmediarender
+ $(INSTALL_DIR) $(1)/etc/init.d
+ $(INSTALL_BIN) ./files/gmediarender.init $(1)/etc/init.d/gmediarender
+ $(INSTALL_DIR) $(1)/etc/hotplug.d/usb
+ $(INSTALL_DATA) ./files/gmediarender.hotplug $(1)/etc/hotplug.d/usb/10-gmediarender
+endef
+
+$(eval $(call BuildPackage,gmediarender))
--- /dev/null 2014-10-09 15:03:28.117439574 +0800
+++ feeds/packages/multimedia/gmediarender/patches/000-add-std-c99-option.patch 2014-10-15 14:15:45.816566435 +0800
@@ -0,0 +1,11 @@
+--- a/configure.ac 2014-03-02 04:11:26.000000000 +0800
++++ b/configure.ac 2014-09-04 14:28:02.000000000 +0800
+@@ -20,7 +20,7 @@
+ if test -n "$GCC"; then
+ EXTRA_GCC_DEBUG_CFLAGS="$CFLAGS"
+ EXTRA_GCC_DEBUG_CXXFLAGS="$CXXFLAGS"
+- CFLAGS+=" -Wall -Wpointer-arith -Wmissing-prototypes -Wmissing-declarations -Wwrite-strings"
++ CFLAGS+=" -Wall -Wpointer-arith -Wmissing-prototypes -Wmissing-declarations -Wwrite-strings -std=c99"
+ CXXFLAGS+=" -Wall -Wpointer-arith"
+ fi
+
将补丁文件保存在openwrt源码目录下执行: patch -p0 < gmrender.patch,然后执 行命令:
./scripts/feeds update -i
./scripts/feeds install gmediarender
make menuconfig,选择需要的软件包:
Kernel modules-->Native Language Support-->kmod-nls-utf8
Kernel modules-->Native Language Support-->kmod-nls-cp437
Kernel modules-->Sound Support-->kmod-sound-core
Kernel modules-->Sound Support-->kmod-usb-audio
Libraries-->libupnp
Multimedia-->gmediarender
Multimedia-->gst-mod-autodetect
Multimedia-->gst-mod-flac
Multimedia-->gst-mod-id3demux
Multimedia-->gst-mod-mad
Multimedia-->gst-mod-ogg
Multimedia-->gst-mod-souphttpsrc
Multimedia-->gst-mod-wavparse
Multimedia-->gst-plugins-base
Multimedia-->gstreamer
make V=s编译。刷固件或安装上面编译的软件包,进入openwrt系统以后,执行命令:/etc/init.d/gmediarender start。正常情况下就可以用手机端软件直接推送音乐到路由上播放了。手机上的软件可以用UPnPlay或者BubbleUPnP。
备注:2014-10-15更新:gmediarender添加/etc/config/gmediarender和/etc/hotplug.d/usb/gmediarender文件,以及修改了/etc/init.d/gmediarender。目的是让gmediarender能像mjpg-streamer一样,在插入usb声卡后能让gmediarender服务自动运行,在移除usb声卡后自动的停止gmediarender服务。详情可以参看上面提供的gmrender.patch补丁文件。