mp3 files and the player object
Klaus Major
k_major at os.surf2000.de
Wed Feb 19 07:10:01 EST 2003
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
More information about the use-livecode
mailing list