QT player and continuous play of a list of songs problem

Mark Stuart mfstuart at cox.net
Thu Dec 6 00:11:08 EST 2012


Hi all,
I've built an MP3 player to play songs while at work.
I decided to add a checkbox "Continuous play" to allow the songs to play one
after the other, 
to the end of the list of songs.

To start the player, I double click on the first in the list (see "on
mouseDoubleUp" script below),
and it sets the player filename with the path and MP3 filename.
When it finishes playing that song, it should go to the next line in the
list and start playing that song.

I have a "on playStopped" script to handle that. But there's a problem with
it.
It skips a line and starts playing that song.

Here's the script for that:

on playStopped
   local TotalLines, tLineNum, tCPlay, tSong
   put the number of lines of fld "SongList" into TotalLines
   put the hilitedLine of fld "SongList" into tLineNum
   add 1 to tLineNum
   put the hilited of btn "Continuous Play" into tCPlay
   
   if tCPlay then
      if tLineNum <= TotalLines then
         set the hilitedLine of fld "SongList" to tLineNum
         --PlaySong
         put fld "MusicFolder" into MusicFolder
         put the selectedText of fld "SongList" into tSong
         replace tab with empty in tSong
         set the fileName of player "Player" to MusicFolder & slash & tSong
         set the currentTime of player "Player" to zero
         start player "Player"
      else
         set the hilitedLine of fld "SongList" to 1
      end if
   end if
end playStopped

Here's the peculiar behavior:
When the LC engine gets to "set the filename of player...", the engine goes
back to the "on playStopped" line and executes from the top again.
When it gets to "set the fileName of player..." again, it continues on to
"start player...", then goes to "end playStopped", which it should do.
But then it goes to the line "set the currentTime..." line and then the next
line "start player...".

Sometimes when it is playing the song, there's no audio at all.

Here's the SongList field script to get the player started:

global MusicFolder

on mouseDoubleUp
   local tSongTitle
   
   put fld "MusicFolder" into MusicFolder
   put the selectedText of me into tSongTitle
   
   -- SongList field is set as a table.
   -- First column is the MP3 filename and the 2nd column contains ".mp3"
   -- This is for asthetics, so you don't see the .mp3 in the list.
   replace tab with empty in tSongTitle   
   
   set the fileName of player "Player" to MusicFolder & slash & tSongTitle
   set the currentTime of player "Player" to zero
   start player "Player"
end mouseDoubleUp

How do I stop the "on playStopped" script from repeating itself and get it
to play without skipping a line?

Any and all help appreciated,
Mark Stuart





More information about the use-livecode mailing list