[lastbash-cvs] lastbash lastbash,1.102,1.103
Status: Beta
Brought to you by:
cstroie
|
From: Costin S. <cs...@us...> - 2006-12-21 13:16:51
|
Update of /cvsroot/lastbash/lastbash In directory sc8-pr-cvs6.sourceforge.net:/tmp/cvs-serv22489 Modified Files: lastbash Log Message: Detect if the player is running and display the led. Index: lastbash =================================================================== RCS file: /cvsroot/lastbash/lastbash/lastbash,v retrieving revision 1.102 retrieving revision 1.103 diff -u -d -r1.102 -r1.103 --- lastbash 12 Dec 2006 13:44:50 -0000 1.102 +++ lastbash 21 Dec 2006 13:16:47 -0000 1.103 @@ -67,6 +67,7 @@ PLAYERS="mplayer" HTTP_CLIENTS="wget curl" REQ_PROGRAMS="rm date tput md5sum dd chmod" +PLAYER_PID="" declare -a HTTP_HEADERS HTTP_RESPONSE declare -a HISTORY_ARTIST HISTORY_ALBUM HISTORY_TRACK HISTORY_DURATION HISTORY_MIN_SEC HISTORY_ACTION CR=$'\x0d' @@ -972,7 +973,7 @@ # - P: record to profile is on # - D: Discovery mode is on # - B: Debug mode is on - L1="-" + player_running && L1="R" || L1="-" [ "${META_RTP}" == "1" ] && L2="P" || L2="-" [ "${META_DISCOVERY}" == "1" ] && L3="D" || L3="-" [ "${DEBUG}" == "y" ] && L4="B" || L4="-" @@ -1604,6 +1605,27 @@ tui_sbar } +# Function: Check if the player is running {{{1 +#----------------------------------------------------------------------------- +function player_running() +{ + local RET + + if [ "${PLAYER_PID}" ] + then + if kill -0 "${PLAYER_PID}" >/dev/null 2>&1 + then + RET="0" + else + RET="1" + fi + else + RET="1" + fi + + return "${RET}" +} + # Function: Send commands to the player {{{1 #----------------------------------------------------------------------------- function player_command() @@ -1656,11 +1678,11 @@ if [ "${PLAYER}" == "mplayer" ] then mplayer -cache 512 -idle -slave -quiet -input file="${PLAYER_PIPE}" >/dev/null 2>&1 & - debug "${FUNCNAME}: Player ${PLAYER} started" + PLAYER_PID=$! elif [ "${PLAYER}" == "mpg123" ] then mpg123 --remote --remote-err --quiet <"${PLAYER_PIPE}" >/dev/null 2>&1 & - debug "${FUNCNAME}: Player ${PLAYER} started" + PLAYER_PID=$! else debug "${FUNCNAME}: No player started" tui_sbar "No supported player found" @@ -1668,11 +1690,21 @@ # Wait a second sleep 1 + # Check if the player is still running + if player_running + then + debug "${FUNCNAME}: Player ${PLAYER} started" + tui_sbar "Player started (${PLAYER})" + RET="0" + # Load the stream, if configured to + [ "${AUTO_PLAY}" == "y" ] && player_load + else + debug "${FUNCNAME}: Could not start player ${PLAYER}" + tui_sbar "Player ${PLAYER} could not be started" + RET="1" + fi - # Update the status line - tui_sbar "Player started (${PLAYER})" - - [ "${AUTO_PLAY}" == "y" ] && player_load + return "${RET}" } # Function: Load the stream in player {{{1 @@ -1680,7 +1712,7 @@ function player_load() { # Return if no player is to be used - [ "${USE_PLAYER}" != "y" ] && return + player_running || return # Set the status line tui_sbar "Loading the stream..." @@ -1708,7 +1740,7 @@ #----------------------------------------------------------------------------- function player_stop() { - [ "${USE_PLAYER}" != "y" ] && return + player_running || return # Set the status line tui_sbar "Stop playing the stream..." @@ -1724,7 +1756,7 @@ #----------------------------------------------------------------------------- function player_quit() { - [ "${USE_PLAYER}" != "y" ] && return + player_running || return # Set the status line tui_sbar "Closing the player..." @@ -1734,7 +1766,7 @@ player_command "quit" elif [ "${PLAYER}" == "mpg123" ] then - killall mpg123 + kill "${PLAYER_PID}" else tui_sbar "No supported player is running" debug "${FUNCNAME}: No player running" @@ -1888,6 +1920,9 @@ # Remove stale files rm -f "${PID_FILE}" "${PLAYER_PIPE}" "${COMMAND_FILE}" "${COMMAND_FILE_LOCK}" fi + + # Wait for all background processes to finish + wait } |