玩轉Openwrt(二) — 配合Android手機打造無線音樂播放器

來源:互聯網
上載者:User


前一篇文章大概介紹了刷入帶ADSL驅動的openwrt以及簡單的配置,這次就總結下一個好玩的應用,使用android手機+mpd打造一台無線音樂播放器。

所需裝備:
  • DB120或者RG100A或者其它BCM6358晶片的路由一台
  • USB音效卡一件(我手裡的兩個音效卡都能很好的工作,一個是steelseries
    5HV2,一個是北藍鼠 USB音效卡 7.1音效卡,就這兩個的音質來說更加傾向於steelseries 5HV2)
  • USB2.0的移動硬碟或者隨身碟一個
  • 運行android系統的手機或者平板

 

首先要保證路由器已經刷入了openwrt,並且已經能正常上網

安裝USB、檔案系統的核心模組

opkg update
opkg install kmod-usb-core
opkg install kmod-usb-storage
opkg install kmod-usb-ohci
opkg install kmod-usb-ohci
opkg install kmod-fs-ext2
opkg install kmod-fs-ext3
opkg install kmod-fs-vfat
opkg install kmod-fuse
opkg install ntfs-3g

配置自動掛載USB存放裝置

安裝mount工具

opkg install mount-utils

編輯設定檔

vi /etc/hotplug.d/block/10-mount
#!/bin/sh

# Copyright (C) 2009 OpenWrt.org (C) 2010 OpenWrt.org.cn

blkdev=`dirname $DEVPATH`
if [ `basename $blkdev` != "block" ]; then

device=`basename $DEVPATH`
case “$ACTION” in
add)
mkdir -p /mnt/$device
# vfat & ntfs-3g check
if [ `which fdisk` ]; then
isntfs=`fdisk -l | grep $device | grep NTFS`
isvfat=`fdisk -l | grep $device | grep FAT`
isfuse=`lsmod | grep fuse`
isntfs3g=`which ntfs-3g`
else
isntfs=”"
isvfat=”"
fi

# mount with ntfs-3g if possible, else with default mount
if [ "$isntfs" -a "$isfuse" -a "$isntfs3g" ]; then
ntfs-3g -o nls=utf8 /dev/$device /mnt/$device
elif [ "$isvfat" ]; then
mount -t vfat -o iocharset=utf8,rw,sync,umask=0000,dmask=0000,fmask=0000 /dev/$device /mnt/$device
else
mount /dev/$device /mnt/$device
fi
if [ -f /dev/${device}/swapfile ]; then
mkswap /dev/${device}/swapfile
swapon /dev/${device}/swapfile
fi
;;
remove)
if [ -f /dev/${device}/swapfile ]; then
swapoff /dev/${device}/swapfile
fi
umount /dev/$device
;;
esac

fi

修改可執行許可權

chmod 777 /etc/hotplug.d/block/10-mount

配置USB音效卡

安裝音效卡核心模組

opkg install kmod-input-core
opkg install kmod-soundcore
opkg install kmod-usb-audio

然後查看/dev下是否有dsp、audio、mixer
測試音效卡是否工作正常,音效卡與音箱串連並且插入含有MP3檔案的USB存放裝置
這裡假設usb裝置掛載路徑為/mnt/sdb1

opkg install madplay
madplay /mnt/sba1/*.mp3

如正常發聲則表示音效卡驅動成功

安裝配置MPD

opkg install mdnsresponder
opkg install libspeex
opkg install mpd

編輯mpd設定檔
vi /etc/mpd.conf
修改為:

#=== edit options as follows ===
music_directory “/mnt/sdb1″
playlist_directory “/mnt/sdb1/.mpd/playlist”
db_file “/mnt/sdb1/.mpd/mpd.db”
log_file “/mnt/sdb1/.mpd/mpd.log”
error_file “/mnt/sdb1/.mpd/mpd.error”
pid_file “/mnt/sdb1/.mpd/mpd.pid”
state_file “/mnt/sdb1/.mpd/mpdstate”

# use this if you want to use OSS audio output
audio_output {
type “oss”
name “my OSS sound card”
device “/dev/dsp” # optional
format “44100:16:2″ #optional
}

# OSS Mixer
mixer_type “oss”
mixer_device “/dev/mixer”
mixer_control “PCM”

#=== edit end ===

建立mpd所需目錄與檔案

mkdir -p /mnt/sdb1/.mpd/playlist
touch /mnt/sdb1/.mpd/{mpd.db,mpd.log,mpd.error,mpd.pid,mpdstate}

運行mpd

/usr/bin/mpd –create-db

安裝mpc控制播放

opkg install mpc
mpc listall | mpc add
mpc play

用手機控制播放

手機連線路由器,在android電子市場裡搜尋 MPDroid 並安裝
運行MPDroid,在WLAN based connection裡選擇串連無線路由的essid
在Host選項裡填入路由器的IP地址,其它則預設,然後返回到主介面
此時即可用手機無線控制路由器的播放、暫停以及其它操作

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.