OpenWrt/Music

From Wiki

OpenWrt music streaming

Streaming music via OpenWrt on 4MB flash router Since /etc is preserved during sysupgrades, we keep everything there.

Install packages

opkg update
opkg install kmod-usb-audio kmod-usb-ohci kmod-usb-core kmod-sound-core madplay

create "madplay.sh"

mkdir /etc/scripts
touch /etc/scripts/madplay.sh
chmod +x /etc/scripts/madplay.sh
vi /etc/scripts/madplay.sh
/etc/scripts/madplay.sh:
#! /bin/sh

while true
 do
 	sleep 2
 	wget -O - http://192.168.111.10:8000 | madplay -
 	sleep 18
 done

create "mpc.sh"

mkdir /etc/scripts
touch /etc/scripts/mpc.sh
chmod +x /etc/scripts/mpc.sh
vi /etc/scripts/mpc.sh
/etc/scripts/mpc.sh:
#!/bin/sh
IP=192.168.111.10

mpc -h $IP clear
mpc -h $IP repeat on
mpc -h $IP random off
mpc -h $IP single off
mpc -h $IP consume off
mpc -h $IP enable 2

mpc -h $IP load "Alarm Clock Intro"
mpc -h $IP shuffle
mpc -h $IP play

sleep 60

mpc -h $IP stop
mpc -h $IP clear
mpc -h $IP load "Alarm Clock"
mpc -h $IP random on
mpc -h $IP play

create madplay init.d script

touch /etc/init.d/madplay
chmod +x /etc/init.d/madplay
vi /etc/init.d/madplay
/etc/init.d/madplay:
#!/bin/sh /etc/rc.common
# madplay script

START=99

DAEMON=/etc/scripts/madplay.sh
DAEMONNAME=madplay
PIDFILE=/var/run/madplay.pid

start() {
	echo -n "starting: $DAEMONNAME" 

	if [ -f $PIDFILE ] ; then
	   echo
	   echo "$DAEMONNAME already running (PID=`cat $PIDFILE`)"
	   exit
	fi	

	touch $PIDFILE
	start-stop-daemon -S -p $PIDFILE -m -b -x $DAEMON
	echo "(PID=`cat $PIDFILE`)"
}

stop() {
	if [ ! -f $PIDFILE ] ; then
	   echo "$DAEMONNAME is not running"
	   exit
	fi

	PID=`cat $PIDFILE`
	echo "stopping: $DAEMONNAME(PID=$PID)"
		
	kill -INT $PID
	pkill -INT -P $PID

	rm -f $PIDFILE
}