Sound not playing sometimes. Why? FOUND IT!

Scott Rossi scott at tactilemedia.com
Sat Nov 16 05:59:01 EST 2002


> The problem? It's a mathematical or timing error in Rev (or QT?) -
> maybe something to do with rounding but here is what I found: I needed
> to have a sound play completely before proceeding with another sound
> and, during the handler, some images are being displayed and hidden. So
> I use the following line of code to cause the handler to wait until the
> sound in complete.
> 
> wait (the duration of player "player1") / (the timeScale of player
> "player1") seconds
> 
> What sometimes happens (I eventually discovered by looking at the
> player object's properties) is that something causes the audio file to
> stop playing prematurely, maybe as little a 5% or less from the end of
> the file. The next time the handler tells the player to start playing,
> only the last few % of the file plays. It sounds like the audio
> vanishes and then starts back up at the end but it's really just the
> end of the file that plays. The "wait..." code makes it seem as if
> everything is timed properly (because currentTime is ignored). The next
> time you run through the handler, everything plays fine because the
> sound file is back at the beginning (well, really the end but playing
> it from the beginning is really the only course open at this point).
> 
> I've also found that the "wait..." line of code, above, does not always
> result in the correct amount of time passing before the handler
> proceeds. The result is sometimes less so the sound stops prematurely
> when some other line of code executes in the handler.
> 
> The "fix" I put into place is as follows:
> 
> wait (the duration of player "player1") / (the timeScale of player
> "player1") + .2 seconds
> --note the "+.2" I added. Sometimes I can use .1, it appears. This
> guarantees that any small error in timing won't cause the handler to
> continue prematurely.


Did you take a look at the playStopped message?  Without knowing what you're
trying to do, it sounds like this is something you should investigate.

In any event, you might consider eliminating the "wait" command from your
script -- it prevents Rev/MC from executing until the time/condition is met.
Instead, consider using the "send" command, something like:

on doStuff
  do some stuff
  put (the duration of player "player1") / (the timeScale of player
    "player1") + .2 seconds into tDelay
  send "doMoreStuff" to me in tDelay seconds
end doStuff

on doMoreStuff
  doSomeOtherStuff
end doMoreStuff

Regards,

Scott Rossi
Creative Director

Tactile Media, Multimedia & Design
Email: scott at tactilemedia.com
Web: www.tactilemedia.com




More information about the Use-livecode mailing list