寻求暂停后台mplayer的方法

sh/bash/dash/ksh/zsh等Shell脚本
回复
头像
qqttdh
帖子: 896
注册时间: 2007-07-20 22:15
送出感谢: 0
接收感谢: 0

寻求暂停后台mplayer的方法

#1

帖子 qqttdh » 2008-10-08 11:57

代码: 全选

#!/bin/sh
#mplayer pause
if [ "`ps aux |grep ' mplayer '|grep -v grep|grep ' TL '|awk {'print $2'}|wc -l`" != 0 ];then
amixer -c 0 -- sset Master off
kill -CONT `ps aux |grep ' mplayer '|grep -v grep|awk {'print $2'}`
sleep 2
amixer -c 0 -- sset Master on
exit
fi

kill -STOP `ps aux |grep ' mplayer '|grep -v grep|awk {'print $2'}`
这是我目前的方法。。。有点强制性。。 :em03
头像
eexpress
帖子: 58428
注册时间: 2005-08-14 21:55
来自: 长沙
送出感谢: 4 次
接收感谢: 256 次

Re: 寻求暂停后台mplayer的方法

#2

帖子 eexpress » 2008-10-08 12:11

估计,还可以通过dbus发送暂停。下次我试试。你这情况,平时没必要而已。
● 鸣学
头像
bones7456
论坛版主
帖子: 8495
注册时间: 2006-04-12 20:05
来自: 杭州
送出感谢: 0
接收感谢: 8 次
联系:

Re: 寻求暂停后台mplayer的方法

#3

帖子 bones7456 » 2008-10-08 12:16

为什么要 amixer 一下?
关注我的blog: ε==3
头像
iblicf
帖子: 3766
注册时间: 2007-01-15 17:15
送出感谢: 0
接收感谢: 0

Re: 寻求暂停后台mplayer的方法

#4

帖子 iblicf » 2008-10-08 12:29

想法不错呢, amixer 我估计是强制禁音,不然这样停,可能声卡会一直噪音 ....

我都是 fuser -k /usr/bin/mplayer 了..... 建议lz 看看 man mplayer , 可能自带解决的, (我现在不在U下)
头像
c\nc
帖子: 231
注册时间: 2007-12-25 12:51
送出感谢: 0
接收感谢: 0

Re: 寻求暂停后台mplayer的方法

#5

帖子 c\nc » 2008-10-08 15:26

代码: 全选

#建个命令行管道:
mkfifo /tmp/mplayer.fifo
#播放文件:
mplayer -input file=$fifo ...
#控制mplayer:
echo pause > $fifo
用 mplayer -input cmdlist 查看可用的命令。
头像
qqttdh
帖子: 896
注册时间: 2007-07-20 22:15
送出感谢: 0
接收感谢: 0

Re: 寻求暂停后台mplayer的方法

#6

帖子 qqttdh » 2008-10-08 16:01

c\nc 写了:

代码: 全选

#建个命令行管道:
mkfifo /tmp/mplayer.fifo
#播放文件:
mplayer -input file=$fifo ...
#控制mplayer:
echo pause > $fifo
用 mplayer -input cmdlist 查看可用的命令。
这个不错....
头像
qqttdh
帖子: 896
注册时间: 2007-07-20 22:15
送出感谢: 0
接收感谢: 0

Re: 寻求暂停后台mplayer的方法

#7

帖子 qqttdh » 2008-10-09 14:23

代码: 全选

#!/bin/sh
#mplayer pause
if [ -e  /tmp/player.fifo ];then
if [ "`ps aux |grep ' mplayer '|grep -v grep|grep "/tmp/player.fifo"|wc -l`" != 0 ];then
echo pause > /tmp/player.fifo
fi
fi
exit
还有别的方法吗?
头像
c\nc
帖子: 231
注册时间: 2007-12-25 12:51
送出感谢: 0
接收感谢: 0

Re: 寻求暂停后台mplayer的方法

#8

帖子 c\nc » 2008-10-10 11:38

你这是哪门子方法?还开多个mplayer?
头像
qqttdh
帖子: 896
注册时间: 2007-07-20 22:15
送出感谢: 0
接收感谢: 0

Re: 寻求暂停后台mplayer的方法

#9

帖子 qqttdh » 2008-10-10 17:54

mplayer是我的主播放器。。。其次就是mpg123和ogg123。。。
有界面的不用。。。

。。。然后又因为fifo必须有接收端时才能用。。。所以。。。就整了个脚本

顺便贴一下我的几个播放脚本---我用的是gnome

单曲循环播放

代码: 全选

#!/bin/sh
#killall mplayer;
#echo "`ps aux |grep mplayer |grep -v grep|awk {'print $2'}`"
#sleep 1
if [ "`ps aux |grep ' mplayer '|grep -v grep|wc -l`" != 0 ];then
kill -9 `ps aux |grep ' mplayer '|grep -v grep|awk {'print $2'}`
fi

if [ "`ps aux |grep ' mpg123 ' |grep -v grep|wc -l`" != 0 ];then
kill -9 `ps aux |grep ' mpg123 '|grep -v grep|awk {'print $2'}`
fi

if [ "`ps aux |grep ' ogg123 '|grep -v grep|wc -l`" != 0 ];then
kill -9 `ps aux |grep ' ogg123 '|grep -v grep|awk {'print $2'}`
fi
#killall  flac123 beep-media-player audacious;
# 
if [ -z $1 ]; then exit;fi;
#建立管道:
if ! [ -e /tmp/player.fifo ];then
mkfifo /tmp/player.fifo
fi
#sleep 1
case "$1" in
*.ogg|*.OGG)
exec mplayer "$1" -loop 0 -input file=/tmp/player.fifo;;
#exec ogg123 -z "$1";;
#exec ogg123 "$1";;
# *ogg)
#exec ogg123 -z@ "$1";;
*.mp3|*.MP3)
exec mplayer "$1" -loop 0 -input file=/tmp/player.fifo;;
#exec mpg123 -Z "$1";;
*.m4a)
exec mplayer "$1" -loop 0 -input file=/tmp/player.fifo;;
#exec mpg123 "$1";;
#*mp3
#exec mpg123 -Z@ "$1";;
#exec audacious "$1";;
#*flac|*FLAC
#exec mplayer "$1";;
#exec flac123 "$1";;
#*.avi
#exec aviplay "$1";;
#exec totem "$1";;
*.wma)
exec mplayer "$1" -loop 0 -input file=/tmp/player.fifo;;
*.mlist)
exec mplayer -playlist "$1" -input file=/tmp/player.fifo;;
*)
exec mplayer "$1" -loop 0 -input file=/tmp/player.fifo;;
esac
exit
歌曲随机播放

代码: 全选

#!/bin/bash
#kill players
killall mplayer mpg123;
if [ "`ps aux |grep ' mplayer '|grep -v grep|wc -l`" != 0 ];then
kill -9 `ps aux |grep ' mplayer '|grep -v grep|awk {'print $2'}`
fi
#clean
if [ -s /tmp/mlist ]; then
rm /tmp/mlist
fi

#make play list
dr=`pwd`
#dr=`dirname "$1"`
#cd "$dr"
#st=${1##*\/}
st="`echo "$1"|sed 's/\[/\\\[/g;s/\]/\\\]/g'`"
echo "$st"
list="`ls "$dr"|grep -v ".jpg"|grep -v ".srt"|grep -v "padding_file"`"
a="`echo "$list"|grep -n "$st"|sed -n 1p|awk -F : '{print $1}'`"
b="`echo "$list"|wc -l`"
#error manage
c=$#
if [ -z $a ];then a=1;c=0;fi
#######
for((i=$a;i<=$b;i++))do
if [ $c = 0 ];then
song="`echo "$list"|sed -n $i,$(($i))p`"
echo "$dr/$song" >>/tmp/mlist
elif [ $c = 1 ];then
song="`echo "$list"|sed -n $i,$(($i))p`"
echo "$dr/$song" >>/tmp/mlist
else
song="`echo "$list"|sed -n $i,$(($i))p`"
song1="`echo "$song"|sed 's/\[/\\\[/g;s/\]/\\\]/g'`"
need_list="`echo "$*"|grep "$song1"|wc -l`"
if [ $need_list = 1 ];then
echo "$dr/$song" >>/tmp/mlist
fi
fi
done
#建立管道:
if ! [ -e /tmp/player.fifo ];then
mkfifo /tmp/player.fifo
fi
#play with list
if [ -s /tmp/mlist ]; then
#if [ $c = 0 ];then
#mplayer -playlist /tmp/mlist
if [ $c = 1 ];then
mplayer -loop 0 -playlist /tmp/mlist -shuffle -input file=/tmp/player.fifo
else
mplayer -loop 0 -playlist /tmp/mlist -shuffle -input file=/tmp/player.fifo
fi
#clean
rm /tmp/mlist
fi

exit

歌曲循环播放

代码: 全选

#!/bin/bash
#kill players
killall mplayer mpg123;
if [ "`ps aux |grep ' mplayer '|grep -v grep|wc -l`" != 0 ];then
kill -9 `ps aux |grep ' mplayer '|grep -v grep|awk {'print $2'}`
fi
#clean
if [ -s /tmp/mlist ]; then
rm /tmp/mlist
fi

#make play list
dr=`pwd`
#dr=`dirname "$1"`
#cd "$dr"
#st=${1##*\/}
st="`echo "$1"|sed 's/\[/\\\[/g;s/\]/\\\]/g'`"
echo "$st"
list="`ls "$dr"|grep -v ".jpg"|grep -v ".srt"|grep -v "padding_file"`"
a="`echo "$list"|grep -n "$st"|sed -n 1p|awk -F : '{print $1}'`"
b="`echo "$list"|wc -l`"
#error manage
c=$#
if [ -z $a ];then a=1;c=0;fi
#######
for((i=$a;i<=$b;i++))do
if [ $c = 0 ];then
song="`echo "$list"|sed -n $i,$(($i))p`"
echo "$dr/$song" >>/tmp/mlist
elif [ $c = 1 ];then
song="`echo "$list"|sed -n $i,$(($i))p`"
echo "$dr/$song" >>/tmp/mlist
else
song="`echo "$list"|sed -n $i,$(($i))p`"
song1="`echo "$song"|sed 's/\[/\\\[/g;s/\]/\\\]/g'`"
need_list="`echo "$*"|grep "$song1"|wc -l`"
if [ $need_list = 1 ];then
echo "$dr/$song" >>/tmp/mlist
fi
fi
done
#建立管道:
if ! [ -e /tmp/player.fifo ];then
mkfifo /tmp/player.fifo
fi
#play with list
if [ -s /tmp/mlist ]; then
#if [ $c = 0 ];then
#mplayer -playlist /tmp/mlist
if [ $c = 1 ];then
mplayer -playlist /tmp/mlist -input file=/tmp/player.fifo
else
mplayer -playlist /tmp/mlist -loop 0 -input file=/tmp/player.fifo
fi
#clean
rm /tmp/mlist
fi

exit

停止

代码: 全选

#!/bin/sh
killall blackscreen mpg123 ogg123 my_apt-get adsl_pppoe;
#killall mplayer;
#echo "`ps aux |grep mplayer |grep -v grep|awk {'print $2'}`"

#sleep 1
if [ "`ps aux |grep ' mplayer '|grep -v grep|grep -v "/tmp/player.fifo"|wc -l`" != 0 ];then
kill -9 `ps aux |grep ' mplayer '|grep -v grep|grep -v "/tmp/player.fifo"|awk {'print $2'}`
fi

if [ "`ps aux |grep ' mpg123 ' |grep -v grep|wc -l`" != 0 ];then
kill -9 `ps aux |grep ' mpg123 '|grep -v grep|awk {'print $2'}`
fi

if [ "`ps aux |grep ' ogg123 '|grep -v grep|wc -l`" != 0 ];then
kill -9 `ps aux |grep ' ogg123 '|grep -v grep|awk {'print $2'}`
fi
#killall  flac123 beep-media-player audacious;
#
if [ "`ps aux |grep ' mplayer '|grep -v grep|grep "/tmp/player.fifo"|wc -l`" != 0 ];then
if(zenity --question --text="全部停止?")then
echo quit > /tmp/player.fifo
sleep 0.1
kill -9 `ps aux |grep ' mplayer '|grep -v grep|awk {'print $2'}`
fi
fi
头像
yy890521
帖子: 580
注册时间: 2008-11-09 18:07
来自: SCU
送出感谢: 0
接收感谢: 0

Re: 寻求暂停后台mplayer的方法

#10

帖子 yy890521 » 2009-05-22 21:37

我也在等这个脚本 :em06
。。。。。。。。感觉好山寨。。。。。。。。。
回复

回到 “Shell脚本”