您好,登錄后才能下訂單哦!
這篇文章將為大家詳細講解有關openwrt上怎么用usb聲卡聽音樂,小編覺得挺實用的,因此分享給大家做個參考,希望大家閱讀完這篇文章后可以有所收獲。
首先路由器上要有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服務。
關于“openwrt上怎么用usb聲卡聽音樂”這篇文章就分享到這里了,希望以上內容可以對大家有一定的幫助,使各位可以學到更多知識,如果覺得文章不錯,請把它分享出去讓更多的人看到。
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。