問題:我找不到任何方法可靠地獲取MPlayer播放列表中的當前播放文件。獲取MPlayer從模式下的當前播放文件
這是我得到了多少。此工作灰腳本通過當前播放列表的路徑監視文本文件。當我更新文件,腳本關閉MPlayer的舊的實例並打開一個新的新的播放列表:
# POLL PLAYLIST FILE FOR CHANGES
CURRENTPLAYLISTPATH=/home/tc/currentplaylist
INFIFO=/tmp/mplayer-in
CURRENTPLAYLIST="NEVERMATCHAPLAYLIST"
FIRSTRUN=1
while [ 1 ];
do
# CHECK FOR NEW PLAYLIST
NEWPLAYLIST=$(head -n 1 $CURRENTPLAYLISTPATH)
if [[ "$NEWPLAYLIST" != "$CURRENTPLAYLIST" ]]; then
if [ "$FIRSTRUN" == 0 ]; then
echo "quit" > "$INFIFO"
fi
# CREATE NAMED PIPE, IF NEEDED
trap "rm -f $INFIFO" EXIT
if [ ! -p $INFIFO ]; then
mkfifo $INFIFO
fi
# START MPLAYER
mplayer -fixed-vo -nolirc -vc ffmpeg12vdpau,ffh264vdpau, -playlist $NEWPLAYLIST -loop 0 -geometry 1696x954 -slave -idle -input file=$INFIFO -quiet -msglevel all=0 -identify | tee -a /home/tc/mplayer.log &
CURRENTPLAYLIST=$NEWPLAYLIST
FIRSTRUN=0
fi
sleep 5;
done
我原來的計劃是隻使用「-identify」標誌和分析日誌文件。這實際上工作得很好,直到我需要截斷日誌文件以避免它變得太大。由於我的截斷腳本運行不久,MPlayer的停止寫入日誌文件:
FILENAME=/home/tc/mplayer.log
MAXCOUNT=100
if [ -f "$FILENAME" ]; then
LINECOUNT=`wc -l "$FILENAME" | awk '{print $1}'`
if [ "$LINECOUNT" -gt "$MAXCOUNT" ]; then
REMOVECOUNT=`expr $LINECOUNT - $MAXCOUNT`
sed -i 1,"$REMOVECOUNT"d "$FILENAME"
fi
fi
我已經搜查,搜查,但一直無法找到獲取當前播放文件,工程的任何其他方式。
我已經嘗試將輸出管道輸出到另一個命名管道,然後監控它,但只能工作幾秒鐘,然後MPlayer完全凍結。
我也使用bash(代替灰)和管道輸出到類似下面的函數嘗試過,但得到了同樣的凍結問題:
function parseOutput()
{
while read LINE
do
echo "get_file_name" > /tmp/mplayer-in
if [[ "$LINE" == *ANS_FILENAME* ]]
then
echo ${LINE##ANS_FILENAME=} > "$CURRENTFILEPATH"
fi
sleep 1
done
}
# START MPLAYER
mplayer -fixed-vo -nolirc -vc ffmpeg12vdpau,ffh264vdpau, -playlist $NEWPLAYLIST -loop 0 -geometry 1696x954 -slave -idle -input file=/tmp/mplayer-in -quiet | parseOutput &
我懷疑我失去了一些東西很明顯這裏,所以任何幫助,想法,點在正確的方向將不勝感激。
飼料
我用一個稍微不同的版本,不需要事先知道資產路徑,只打印文件名:'lsof -p $(pidof -s mplayer)2>/dev/null | grep -E「[0-9] + r。* REG」| grep -oE「[^ /] + $」'。第一個grep從'lsof'的輸出中選擇一個具有讀權限([0-9] + r)的常規文件(REG),第二個從匹配行中提取文件名。 – 2016-02-15 11:40:54