playlist

Visuals, audio, animation. Blended, not stirred. If LiveCode is part of your rich media production toolbox, this is the forum for you.

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
newrev
Posts: 6
Joined: Thu Nov 05, 2009 7:29 am

playlist

Post by newrev » Thu Nov 05, 2009 7:50 am

hello all...

i'm a novice programmer new to rev. I want to create an audio file player that functions as a playlist where once one audio file has ended the next one plays.

I do not know how to make the player wait until the file has finished before starting the next one. I know about the playstopped message but do not know how to implement it...meaning I can have the player "wait x seconds with messages" (which is inadequate because the audio files are all different durations), but i cannot seem to have the player "wait until playstopped then play next audiofile" (it never plays the next file).

here's my code for the "play" button:

Code: Select all

on mouseUp
//audio files are already loaded into a table field.  I want to cycle through the files in that field and play the entire file

     repeat for each line tFile in filteredFiles()
      if the filename of player 1 is  " " then exit mouseUp 
        
      set the filename of player 1 to tFile
      
      start player 1
      
//is it possible to use a "wait until" line here? it has not worked for me.
      wait 2 seconds with messages
      
      
      end repeat
      
end mouseUp
any help is much appreciated!

SparkOut
Posts: 2862
Joined: Sun Sep 23, 2007 4:58 pm

Post by SparkOut » Thu Nov 05, 2009 10:42 am

You can do things, particularly with callbacks to achieve results, which may also perhaps be usefully extended to do more sophisticated things.

To find the number of seconds a clip will last for you can

Code: Select all

put the duration of player 1 / the timeScale of player 1 into theDurationSeconds

However, that's not the only way RunRev lets you skin this cat, and your code is interesting because it illustrates the difference between a property and a message, so as you say you are new to RunRev, it's probably worth a little focus. Apologies if this sounds patronising - it's not meant to be.

Code: Select all

on mouseUp 
//audio files are already loaded into a table field.  I want to cycle through the files in that field and play the entire file 

     repeat for each line tFile in filteredFiles()
      --initialise the property we need to check for this loop
      set the uStoppedFlag of player 1 to false         
      
      if the filename of player 1 is  " " then exit mouseUp

          --prevent playStopped message being sent when the filename of the player changes
          lock messages

          set the filename of player 1 to tFile

          --allow messages again after the filename is set
          unlock messages
      start player 1 

      --now we can have the wait loop check for a PROPERTY
      wait until the uStoppedFlag of player 1 is true with messages
      
      end repeat 
      
end mouseUp
To set a property that we can then interrogate, we can handle the playStopped message that is sent when a player comes to the end of its track.
Put a handler for the playStopped message in an appropriate place in the message path (the player, card or stack, depending)

Code: Select all

on playStopped
      set the uStoppedFlag of player 1 to true
end playStopped
This intercepts the message that is sent, and takes action to set a property accordingly. That property can then be used in the polling wait loop. A wait... until loop cannot intercept a message, it can check the state of a property. So your code above was nearly right, it just needed to be adjusted to take that concept into consideration.

HTH
SparkOut

newrev
Posts: 6
Joined: Thu Nov 05, 2009 7:29 am

Post by newrev » Wed Nov 11, 2009 8:20 pm

excellent. working fine now.

thanks for the info and thanks especially for the conceptual overview, sparkout.

Post Reply

Return to “Multimedia”