這篇文章將為大家詳細(xì)講解有關(guān)openwrt上怎么用usb聲卡聽音樂,小編覺得挺實(shí)用的,因此分享給大家做個(gè)參考,希望大家閱讀完這篇文章后可以有所收獲。
創(chuàng)新互聯(lián)建站是一家專業(yè)從事成都網(wǎng)站制作、成都網(wǎng)站設(shè)計(jì)、網(wǎng)頁(yè)設(shè)計(jì)的品牌網(wǎng)絡(luò)公司。如今是成都地區(qū)具影響力的網(wǎng)站設(shè)計(jì)公司,作為專業(yè)的成都網(wǎng)站建設(shè)公司,創(chuàng)新互聯(lián)建站依托強(qiáng)大的技術(shù)實(shí)力、以及多年的網(wǎng)站運(yùn)營(yíng)經(jīng)驗(yàn),為您提供專業(yè)的成都網(wǎng)站建設(shè)、營(yíng)銷型網(wǎng)站建設(shè)及網(wǎng)站設(shè)計(jì)開發(fā)服務(wù)!
首先路由器上要有usb接口,然后還需要有個(gè)usb聲卡。隨便X寶上買個(gè)幾塊錢的那種免驅(qū)的usb聲卡就能用。
方式一:手機(jī)控制播放OpenWrt上的音樂(播放的數(shù)據(jù)來源路由本身)
這種方式下,一般還需要一個(gè)usb分線器(X寶上買個(gè)十來塊,4口的usb hub,不太差的就行)和一個(gè)u盤,u盤上創(chuàng)建個(gè)“mp3”目錄和“.mpd”目錄,往這個(gè)目錄放些mp3格式的歌曲(wma的就不要放進(jìn)去了,播放太吃力了,在make kernel_menuconfig的是選上了 浮點(diǎn)模擬,測(cè)試沒什么效果)。
自己編譯固件,make menuconfig時(shí)選擇
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 #測(cè)試用 Sound-->mpd-full Utilities-->alsa-utils
刷固件或安裝上面編譯的軟件包,然后就是在openwrt系統(tǒng)下掛載u盤到/tmp/extroot,其他地方也行。用命令:madplay /tmp/extroot/mp3/xx.mp3測(cè)試看看能否正常播放。然后運(yùn)行amixer命令或者控制器,我這里獲取到是“Speaker”,在編輯/etc/mpd.conf文件和/etc/init.d/mpd文件時(shí)會(huì)用到。
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配置文件。內(nèi)容如下:
//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
運(yùn)行如下命令,正常的話,就可以用手機(jī)控制播放路由器上的音樂了。
root@OpenWrt:/etc/init.d/mpd enable root@OpenWrt:/etc/init.d/mpd start
安卓手機(jī)端控制軟件用“mpd播放器”。
方式二:手機(jī)推送音樂到OpenWrt上播放(播放的數(shù)據(jù)來源是手機(jī))
此方式不需要usb hub和u盤。首先在openwrt源碼目錄下:
./scripts/feeds update -a ./scripts/feeds install -a
然后就是要加入gmediarender軟件,openwrt沒有這此軟件包,需自行加入,添加gmediarender軟件包的補(bǔ)丁文件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 +
將補(bǔ)丁文件保存在openwrt源碼目錄下執(zhí)行: patch -p0 < gmrender.patch,然后執(zhí) 行命令:
./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編譯。刷固件或安裝上面編譯的軟件包,進(jìn)入openwrt系統(tǒng)以后,執(zhí)行命令:/etc/init.d/gmediarender start。正常情況下就可以用手機(jī)端軟件直接推送音樂到路由上播放了。手機(jī)上的軟件可以用UPnPlay或者BubbleUPnP。
備注:2014-10-15更新:gmediarender添加/etc/config/gmediarender和/etc/hotplug.d/usb/gmediarender文件,以及修改了/etc/init.d/gmediarender。目的是讓gmediarender能像mjpg-streamer一樣,在插入usb聲卡后能讓gmediarender服務(wù)自動(dòng)運(yùn)行,在移除usb聲卡后自動(dòng)的停止gmediarender服務(wù)。
關(guān)于“openwrt上怎么用usb聲卡聽音樂”這篇文章就分享到這里了,希望以上內(nèi)容可以對(duì)大家有一定的幫助,使各位可以學(xué)到更多知識(shí),如果覺得文章不錯(cuò),請(qǐng)把它分享出去讓更多的人看到。
分享文章:openwrt上怎么用usb聲卡聽音樂
當(dāng)前鏈接:http://jinyejixie.com/article0/igodio.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供面包屑導(dǎo)航、移動(dòng)網(wǎng)站建設(shè)、建站公司、品牌網(wǎng)站建設(shè)、營(yíng)銷型網(wǎng)站建設(shè)、小程序開發(fā)
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)