[lastbash-cvs] lastbash lastbash,1.104,1.105
Status: Beta
Brought to you by:
cstroie
|
From: Costin S. <cs...@us...> - 2006-12-21 13:47:15
|
Update of /cvsroot/lastbash/lastbash In directory sc8-pr-cvs6.sourceforge.net:/tmp/cvs-serv2820 Modified Files: lastbash Log Message: Improved the player control and checking. Index: lastbash =================================================================== RCS file: /cvsroot/lastbash/lastbash/lastbash,v retrieving revision 1.104 retrieving revision 1.105 diff -u -d -r1.104 -r1.105 --- lastbash 21 Dec 2006 13:20:01 -0000 1.104 +++ lastbash 21 Dec 2006 13:47:11 -0000 1.105 @@ -1614,18 +1614,23 @@ { local RET + # If the PID is not null... if [ "${PLAYER_PID}" ] then + # And can be signalled... if kill -0 "${PLAYER_PID}" >/dev/null 2>&1 then RET="0" else RET="1" + PLAYER_PID="" fi else RET="1" + PLAYER_PID="" fi + # Return the status return "${RET}" } @@ -1637,11 +1642,24 @@ [ "${USE_PLAYER}" == "y" ] || return + local RET + if [ -p "${PLAYER_PIPE}" ] then - echo "$1" > "${PLAYER_PIPE}" - debug "${FUNCNAME} (${PLAYER}): $1" + if echo "$1" > "${PLAYER_PIPE}" + then + debug "${FUNCNAME} (${PLAYER}): Command \"$1\" sent" + RET="0" + else + debug "${FUNCNAME} (${PLAYER}): Command \"$1\" not sent" + RET="1" + fi + else + RET="1" fi + + # Return the status + return "${RET}" } # Function: Start the player {{{1 @@ -1655,7 +1673,6 @@ then tui_sbar "No way to control the player, mkfifo is absent" "2" debug "${FUNCNAME}: mkfifo is absent" - USE_PLAYER="n" return 1 fi @@ -1674,7 +1691,7 @@ else debug "${FUNCNAME}: Pipe not created" tui_sbar "Unable to create the player controlling pipe" "1" - return 1 + return 2 fi # Start the player in background @@ -1687,12 +1704,13 @@ mpg123 --remote --remote-err --quiet <"${PLAYER_PIPE}" >/dev/null 2>&1 & PLAYER_PID=$! else - debug "${FUNCNAME}: No player started" + debug "${FUNCNAME}: No supported player found" tui_sbar "No supported player found" fi # Wait a second sleep 1 + # Check if the player is still running if player_running then @@ -1704,9 +1722,10 @@ else debug "${FUNCNAME}: Could not start player ${PLAYER}" tui_sbar "Player ${PLAYER} could not be started" - RET="1" + RET="3" fi + # Return the status return "${RET}" } @@ -1717,6 +1736,8 @@ # Return if no player is to be used player_running || return + local RET + # Set the status line tui_sbar "Loading the stream..." @@ -1724,19 +1745,30 @@ if [ "${PLAYER}" == "mplayer" ] then player_command "loadfile ${LASTFM_STREAM}" + RET=$? elif [ "${PLAYER}" == "mpg123" ] then player_command "load ${LASTFM_STREAM}" + RET=$? else - debug "${FUNCNAME}: No player running" + debug "${FUNCNAME}: No supported player running" tui_sbar "No supported player is running" + RET="1" fi - # Wait a second - sleep 1 + # Wait a second (or even longer, to let the stream be loaded) + sleep 5 # Update the status line - tui_sbar "Stream loaded and playing" "1" + if [ "${RET}" == "0" ] + then + tui_sbar "Stream loaded and playing" "5" + else + tui_sbar "Stream not loaded" + fi + + # Return the status + return "${RET}" } # Function: Stop playing {{{1 @@ -1745,14 +1777,32 @@ { player_running || return + local RET + # Set the status line tui_sbar "Stop playing the stream..." - player_command "stop" + # Stop playing + if [ "${PLAYER}" == "mplayer" ] + then + RET="1" + tui_sbar "Command not supported" + elif [ "${PLAYER}" == "mpg123" ] + then + RET="1" + tui_sbar "Command not supported" + else + RET="1" + debug "${FUNCNAME}: No supported player running" + tui_sbar "No supported player is running" + fi # Restore the status bar sleep 1 tui_sbar + + # Return the status + return "${RET}" } # Function: Stop the player {{{1 @@ -1767,22 +1817,32 @@ if [ "${PLAYER}" == "mplayer" ] then player_command "quit" + RET=$? elif [ "${PLAYER}" == "mpg123" ] then kill "${PLAYER_PID}" + RET=$? else tui_sbar "No supported player is running" - debug "${FUNCNAME}: No player running" + debug "${FUNCNAME}: No supported player running" + RET="1" fi # Wait a second sleep 1 - # Remove the FIFO - rm -f "${PLAYER_PIPE}" + # Check the result + if [ "${RET}" == "0" ] + then + tui_sbar "Player closed" + # Remove the FIFO + rm -f "${PLAYER_PIPE}" + else + tui_sbar "Could not close the player" + fi - # Set the status line - tui_sbar "Player closed" + # Return the status + return "${RET}" } # Function: Check if another instance is running {{{1 @@ -1806,6 +1866,7 @@ RET="0" fi + # Return the status return "${RET}" } |