Shell之MP3播放器
Posted xfgnongmin
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Shell之MP3播放器相关的知识,希望对你有一定的参考价值。
以下的程序实现一个简单的mp3播放功能。能够设置路径对全部mp3文件进行搜索并顺序播放。
#!/bin/sh
# very simple example shell script for mp3 player
# 2014-5-6 by slwang
#实现搜索全部mp3文件并顺序播放歌曲
path1=~/Music
path2=~/Downloads
temp_file=/tmp/temp_files$$
musicset=""
menu_choice=""
isnext="n"
trap ‘rm -f $temp_file && audacious -s‘ EXIT
set_menu_choice() {
clear
echo "mp3 player menu :-"
echo " p) play"
echo " u) pause"
echo " s) stop"
echo " n) next"
echo " c) count"
echo " l) list"
echo " q) quit"
echo "please input: \c"
read menu_choice
}
clear
echo "welcome to mp3 player"
sleep 1
IFS="
"
find $path1 $path2 -name *.mp3 -print > $temp_file
musicset=$(cat $temp_file)
#more $musicset > $temp_file
for music in $musicset
do
echo "Beign to play $music"
audacious -h $music
isnext="n"
while [ "$isnext" = "n" ]
do
set_menu_choice
case $menu_choice in
p) audacious -p
;;
u) audacious -u
;;
s) audacious -s
;;
n) isnext="y"
;;
c) IFS=" "
set $(wc -l $temp_file)
lines=$1
echo "total include $lines songs"
echo "press return"
IFS="
"
read x
;;
l) more $temp_file
echo "press return"
read x
;;
q) exit 0
;;
esac
done
done
IFS=" "
rm -f $temp_file
audacious -s
echo "finished"
exit 0
(转载请注明作者和出处:http://blog.csdn.net/awakewind 未经同意请勿用于商业用途)
(想与博主一起在技术上成长,请移步
knowthendo.cn)