mp3 files and the player object

Chris Sheffield cm_sheffield at yahoo.com
Wed Feb 19 10:27:01 EST 2003


Thank you all very much for the suggestions.  I
couldn't get the playStopped message solution to work
quite right.  It still kept cutting off the previous
sound and playing the next one.  Anyway, I followed a
slightly similar solution to what Klaus suggested.  My
problem is that I have to control the player from the
handler of a Start button, which the user will click
to begin.  What happens is there is text on the screen
that highlights a different color as each sentence is
read out loud (thus the mp3 files).  Here is what I
did:

-------
on mouseUp
  global myArray
  global sentenceCount

  wait 1 sec

  repeat with x = 1 to sentenceCount
    if x > 1 then
      ## set the previous line back to black
      set the foregroundColor of char myArray[x-1,1]
to myArray[x-1,2] of field "myField" to black
    end if

    ## set the current sentence to blue
    set the foregroundColor of char myArray[x,1] to
myArray[x,2] of field "myField" to blue

    ## set the current sound file and play it
    set the fileName of player "myPlayer" to
"./sounds/sound" & x & ".mp3"
    start player "myPlayer"
    wait (the duration of player "myPlayer" / the
timeScale of player "myPlayer") seconds

    wait 1 sec
    
  end repeat

  ## set the last sentence back to black
  set the foreGround of char myArray[x,1] to
myArray[x,2] of field "myField" to black

end mouseUp
-----------

The global variables myArray and sentenceCount are
both set in the mouseUp message of another button,
simply because I'm using the Free Edition right now
and am limited on the scripts.  Basically myArray
contains the start and end chars of each sentence, and
sentenceCount contains the number of sentences in the
text field.

This all works just fine, but I was wondering if I'm
going to notice any performance issues when dealing
with fairly large bodies of text and quite a few sound
files.

Thanks for any feedback.

Chris Sheffield
Read Naturally

--- Klaus Major <k_major at os.surf2000.de> wrote:
> Hi Chris,
> 
> > I want to use the player object to play several
> mp3
> > files in a row.  I am successful at changing the
> > FileName property and playing my files, but the
> trick
> > is that I need to wait until each sound is
> finished
> > playing before playing the next one.  Is there any
> way
> > to do this?  Such as a 'wait until player
> "myPlayer"
> > is done' type of command?  Please help.
> >
> > Thanks,
> >
> > Chris Sheffield
> > Read Naturally
> 
> here is another smart ;-) approach to your problem.
> 
> I will use the "send xxx in yyy" command.
> 
> My example requires a field "mp3list", where the
> filenames
> of the mp3 files are stored. Could of course be a
> variable or
> custom-property, too.
> 
> ###############
> 
> global songmessage
> ## the name does not matter, call it walter if you
> like :-)
> 
> ## here we will store the id of the message that we
> will send
> ## when the current mp3 is finished. So we can
> cancel that
> ## message from being delivered when we close this
> card of stack.
> ## See "pendingmessages" in the docs...
> 
> on mouseup
> ## can of course be "on opencard" or whenever you
> want to start the 
> songs...
>    set the filename of player "xyz" to line 1 of fld
> "mp3list"
>    start player "xyz"
>    send "nextsong" to me in (the duration of player
> "xyz"/the timescale 
> of player "xyz") secs
>    ## This means that this message will be send
> exactly when the current 
> song has finished...
> 
>    ## Every sound- or video-file can (and will ;-)
> have a duration. 
> Surprise, surprise... ;-)
>    ## Unfortunately this duration is measured in the
> files own 
> timescale...
>    ## Means how much timeunits per second that file
> will be measured in..
>    ## But both properties can be queried :-)
> 
>    put the result into songmessage
>    ## Each command that will be "send..." will be
> managed by the engine
>    ## in the "pendingmessages" and gets its own id.
>    ## Now we store this id in this global var
> "sonmessage", so we can 
> cancel
>    ## it when leaving this card or closing this
> stack
>    ## You can take another name for that var, of
> course...
> end mouseup
> 
> on nextsong
>    put lineoffset(the filename of player "xyz", fld
> "mp3list") into 
> whatline
>    ##what is the current song...
> 
>    if whatline < the num of lines of fld "mp3list"
> then
>        ## only if it is not the last song in this
> list...
> 
>        set the filename of player "xyz" to empty
>        set the filename of player "xyz" to line
> (whatline + 1) of fld 
> "mp3list"
>        start player "xyz"
>        ## next one...
> 
>       send "nextsong" to me in (the duration of
> player "xyz"/the 
> timescale of player "xyz") secs
>       put the result into songmessage
>    end if
> end nextsong
> 
> ################# Does even fit in the StarterKit
> limit :-)
> 
> Then you could write this in the cardscript:
> 
> on closecard
>    global songmessage
>    if "songmessage" is in the pendingmessages then
>    ## Maybe much time has already passed and all
> songs have been 
> played...
>    ## Omit this "if...then..." caluse if you LOVE
> error-dialogs ;-)
>        cancel songmessage
>    end if
> ...
> end closecard
> 
> 
> Hope this helps.
> 
> 
> Regards
> 
> Klaus Major
> k_major at os.surf2000.de
> 
> _______________________________________________
> use-revolution mailing list
> use-revolution at lists.runrev.com
>
http://lists.runrev.com/mailman/listinfo/use-revolution


__________________________________________________
Do you Yahoo!?
Yahoo! Shopping - Send Flowers for Valentine's Day
http://shopping.yahoo.com



More information about the use-livecode mailing list