1

I have created a KornShell (ksh) script that plays a list of songs on youtube by searching the song name + the artist name and hitting the first link (the list of song names and artists are stored in a file).

I would like to change my current approach of having the user enter some value (read x < /dev/tty) on the terminal to play the next song. I want the script to simply switch over to the next song as soon as the first one stops playing. While I am aware that the approach may have caveats (what if another sound starts and stops while the song is still playing) - this would still meet my basic requirements. Any ideas on how to poll the sound card through shell?

javaPlease42
  • 4,699
  • 7
  • 36
  • 65
jawsnnn
  • 91
  • 2
  • 11
  • Could you share your ksh script that "triggers an instance of browser (google-chrome) to open a youtube page to search the song name + the artist name and hit the first link to play it". @Arpan Malviya – javaPlease42 Jan 07 '14 at 20:21

1 Answers1

0

Strange question. Why not just loop while playing doesn't fail (in bash-speak):

while [ $? -eq 0 ]; do
   smth;
   other;
   ...
   mplayer $file;
done

If you must you can always check with fuser or lsof for pids occupying sound device file.

ypb
  • 118
  • 6
  • I am not using a media player to play the songs. As I mentioned above, I am triggering an instance of browser (google-chrome) to open a youtube page and I want to wait until that has finished playing. I will look into the other options you have listed. – jawsnnn Nov 08 '11 at 04:53
  • The other options are linux specific, but you should be able to hunt down the equivalent with `man -k`. Perhaps using _mplayer_ together with _youtube-dl_ would be less awkward than fiddling with flash inside browser. – ypb Nov 08 '11 at 15:37