help-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Help-bash] play audio-CD in consol


From: Mart Frauenlob
Subject: Re: [Help-bash] play audio-CD in consol
Date: Tue, 29 Jan 2013 14:52:19 +0100
User-agent: Mozilla/5.0 (Windows NT 5.1; rv:17.0) Gecko/20130107 Thunderbird/17.0.2

On 29.01.2013 01:13, Gerard ROBIN wrote:
Hello,
the dvd burner of my laptop died and I replaced it with a external dvd burner,
but now cdcd can not play the cd audio. It sees the tracks but no sound.
alsaplayer-text works and I have written a bash script to simulate cdcd (not 
very professional).
Can someone help me to improve it?
It is there: http://dl.free.fr/ibSYXRaTe

I don't speak french, but I managed to download your file :p


thanks in advance.

#!/bin/bash

title="ALSAPLAYER-TEXT"
frame="==============="
center="\t\t\t\t"
cpt=0

function prompt { echo -n "alsaplayer> " ;}

echo -e "\n"$center$frame"\n" $center$title"\n"$center$frame

echo -e "\n\tListen to audio CDs with alsaplayer (http://www.alsaplayer.org/)"
echo -e "\n\tFirst of all you must edit the ~/.alsaplayer/config
\tComplement or add the following lines:
\n\t 1 cdda.cddb_servername=freedb.freedb.org
\t 2 cdda.cddb_serverport=8880
\t 3 cdda.device=/dev/sr0 # replace /dev/sr0 by the good path of your box.
\t 4 cdda.do_cddb_lookup=true"

echo -e "\n\t\tTo play a CD, type: play, then Enter
\t\tTo exit alsaplayer, keep playing, type exit and Enter
\t\tTo stop the CD, if it is playing, type stop and Enter
\t\tEnter ? for more help"


hard to read, I'd prefer printf, or here-document redirection here.

file -s /dev/sr0 &>/dev/null
if [ $? -eq 0 ]; then
        echo -e "\n\t\t\e[1;31mSORRY NO AUDIO CD IN THE DRIVE\e[0m"
        exit;
fi

why not:
if command; then ...
fi

prompt

The variable PROMPT_COMMAND might be handy, you don't need to call 'prompt' every time.


while read  anwser

you don't need the variable 'answer'. if you don't split the reply into several variables, but omit them completely, the input is put into the variable REPLY.

do
        ps -C alsaplayer &>/dev/null
        if [ $? -eq 0 ] ;then run=0 ;else run=1 ;fi
you use #!/bin/bash, so...
if (($?)); then
        greater_zero_commands
else
        is_zero_commands
fi
but again, easier in this case:
if command; then ...else ...fi
                
        
        case $anwser in

                \?) echo -e " ?, play/stop, exit, prev/next, pause/unpause, 
status"
                        prompt ;;

                exit)   exit;;

                stop)   cpt=0
                        alsaplayer --quit
                        prompt;;

                play)   >/dev/null
                        if [ $cpt -eq 0 ] && [ $run -eq 1 ]  ; then
                                cpt=$(( $cpt+1 ))

if ((cpt == 0 && run == 1)); then
or:
if ((! cpt && run)); then
let cpt+=1
or
((++cpt))
shorter, nicer imho

or to make you crazy:
if ! ((! cpt && run ? ++cpt : 0)); then
        alsaplayer ...
fi

                                alsaplayer -q CD.cdda &> /dev/null &
                                prompt
                        else
                                echo "Alsaplayer is playing a CD"
                                prompt
                        fi;;
                prev)   alsaplayer --prev
                        prompt;;

                next)   alsaplayer --next
                        prompt;;

                pause) alsaplayer --pause
                        prompt;;

                unpause) alsaplayer --start
                          prompt;;

                status) alsaplayer --status
                        prompt;;

                *) if [ "$anwser" = "" ]; then

using #!/bin/bash:

if [[ $answer ]]; then....

                        prompt
                  else
                        echo "unknown command  $anwser"
                        prompt
                  fi ;;
        esac
done


Best regards

Mart



reply via email to

[Prev in Thread] Current Thread [Next in Thread]