Alsaplayer in command line with bash

The programme cdcd is no longer working with an external player of audio CDs. Thus now, I listen audio CDs from the command line, with alsaplayer-text. This program works with GNU bash, version 4.2.37 on wheezy (Debian).
To get alsaplayer-text, perform : sudo apt-get install alsaplayer-text
To detect if a CD is in the drive I use the package cd-discid, therefore apt-get install cd-discid.
Name this program cdplay, for example.
Make it executable: chmod u+x cdplay
To execute it : ./cdplay or cdplay if it is in the directory /home/user/bin and if this directory is in the variable PATH

This program is imperfect, this is due to my lack of professionalism, but also due to alsaplayer that is still developing. But it is better than nothing.
Note:
Debian provides a manpage with the package alsaplayer.


begin cdplay

#!/bin/bash

title="ALSAPLAYER-TEXT"
frame="==============="
warning="SORRY NO AUDIO CD IN THE DRIVE"
cpt=0

function prompt { printf "alsaplayer> " ;}

printf "%50s\n%50s\n%50s\n" "$frame" "$title" "$frame"
cat << EOF

Listen to audio CDs with alsaplayer (http://www.alsaplayer.org/)

First of all you must edit the ~/.alsaplayer/config
Complement or add the following lines:

cdda.cddb_servername=freedb.freedb.org
cdda.cddb_serverport=8880
cdda.device=/dev/sr0 # replace /dev/sr0 by the good path of your box.
cdda.do_cddb_lookup=true"

To play a CD, type: play, then Enter
To exit alsaplayer, keep playing, type exit and Enter
To stop the CD, if it is playing, type stop and Enter
Enter ? for more help"
EOF

if ! cd-discid /dev/sr0 &>/dev/null ; then
printf  "\e[1;31m%60s\e[0m\n"  "$warning"
exit
fi
prompt

while read
do
if ps -C alsaplayer &>/dev/null  ; then run=0 ; else run=1 ; fi

case $REPLY in
\?)  echo -e " ?, play/stop, exit, prev/next, pause/unpause, status, ejectcd"
prompt  ;;

exit)   exit ;;

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

play)  >/dev/null
if  ((! cpt && run ? ++cpt : 0)) ; then
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 ;;

ejectcd)  if  (( ! $run)) ; then
echo "Asaplayer is playing a CD, stop it before eject"
prompt
else
eject /dev/sr0
prompt
fi ;;

*)  if   [[ ! $REPLY ]] ; then
prompt
else
echo "unknown command $anwser"
prompt
fi  ;;

esac
done
end cdplay