mp3 files and the player object

John jburtt at earthlink.net
Thu Feb 20 00:32:01 EST 2003


>
><    wait (the duration of player "myPlayer" / the
>timeScale of player "myPlayer") seconds>
>
>This works and that's most important, but...
>Everything, including user interaction, suspends while the sound is playing,
>thus preventing the user from stopping the sound in midplay. If these sounds
>are brief you can probably 'get away' with that, but it's friendlier to
>leave control to the user. Klaus' SEND example allows for interruption
>during and between sound plays.
>
>I wonder why playstopped isn't 100% reliable.
>
>Jim Lambert

I've received so many answers from the list, I'm happy to finally be 
able to send a few suggestions myself.

I built a mp3 player and also had trouble with the playStopped 
message. This is my workaround:

on playAllSounds --- this command is called to start the whole thing
   --- a return delimited list of soundFilePaths is located in fld "SoundData"
    Global gSoundList
    put fld "SoundData" into gSoundList
    playSoundList
end playAllSounds

on playSoundList --- this command holds the soundFilePaths
                             ---and plays them one after the other
    Global gSoundPlaying,gSoundList
        --- UnLoad the player (you must set player fileName to empty
        --- before setting a new fileName. I don't know why???)
    put "false" into gSoundPlaying
    set the fileName of player "SoundPlayer" to empty
    set the paused of player "SoundPlayer" to "true"
        --- Load the player with new fileName if there is one
    if gSoundList is empty then exit to top --- no more sounds to play
    get line 1 of gSoundList
    delete line 1 of gSoundList --- this prepares soundList for next call
    set the fileName of player "SoundPlayer" to it
    set the currentTime of player "SoundPlayer" to "0"
    startPlayer
end playSoundList

on startPlayer --- this command is called by the "playSoundList" command
           --- or by a button to restart a paused sound at the place 
it was paused
    Global gSoundPlaying
    if the fileName of player "SoundPlayer" is empty then exit startPlayer
    set the paused of player "SoundPlayer" to "false"
    put "true" into gSoundPlaying
    updateSoundProgress
end startPlayer

on pausePlayer --- this command is called by a "Pause" button
    Global gSoundPlaying
    if the fileName of player "SoundPlayer" is empty then exit pausePlayer
    set the paused of player "SoundPlayer" to "true"
    put "false" into gSoundPlaying
end pausePlayer

on updateSoundProgress --- this command is the key to starting a new
                                           --- sound when the current 
sound is done
    Global gSoundPlaying
    if gSoundPlaying is not "true" then exit updateSoundProgress
    put the duration of player "SoundPlayer" into soundDone
    get the currentTime of player "SoundPlayer"
    if it is soundDone then
       playSoundList
    else
       send "updateSoundProgress" to me in 20 ticks
    end if
end updateSoundProgress

  Hope this helps...  John







More information about the use-livecode mailing list