Sound not playing sometimes. Why? FOUND IT!

Barry Levine themacguy at macosx.com
Fri Nov 15 22:55:01 EST 2002


Eureka! I found the problem -and- the solution. Firstly, thanks to the 
listas who provided suggestions. Though none of them provided the 
ultimate answer, they caused me to examine other paths which led me to 
the happy ending.

Speaking of paths (as was one lista): I had a "resources" folder at the 
same level of my stack so the pathnames I used (both hardcoded and 
programmatically set) were of the form "resources/mySound.aif". When I 
compile the app, I copy the resources folder into the same folder as 
the app and everything works just fine.

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.

then I add:
set the currentTime of player "player1" to 0 -- that's a zero
-- this forces a "rewind" of the player in case something causes a 
premature halt to the sound.
-- now the next time I play the sound, it's ready to play from start to 
end.

I went through multiple levels of Cat Skinning to nail this SOB but it 
works and, hopefully, Rev2 (or maybe OSX 10.2.3 or QT6.1) will resolve 
it.

Barry

On Friday, November 15, 2002, at 07:00 PM, 
use-revolution-request at lists.runrev.com wrote:

> Message: 1
> Date: Fri, 15 Nov 2002 10:04:50 -0700
> Subject: Sound not playing sometimes. Why?
> From: Barry Levine <themacguy at macosx.com>
> To: use-revolution at lists.runrev.com
> Reply-To: use-revolution at lists.runrev.com
>
> I have a stack with a player object. No matter how I assign the
> fileName property or play the sound (via transcript or the message
> box), I have at least one audio file that will not play some of the
> time. My audio files are all AIF 22KHz, 16bit, mono.
>
> It was suggested that I first set the fileName to empty and then re-set
> the property to the correct name. I've tried this. Also tried playing
> the "empty" player before re-setting the fileName property. No luck.
>
> I've tried "pre-playing" the sound (playing it with the playLoudness
> set to 0) and then playing it at the proper volume. No luck.
>
> I've found some consistency:
>
> Play the sound the first time and it will fail (even if played twice in
> one handler).
> Play the same sound the second time (without changing the fileName to
> something else and back again) and it plays fine.
> Change the fileName property to some other audio file and it plays
> (with the other sound).
> Change it back to the original fileName and it will fail to play. Play
> it again (another event triggering the same handler) and it plays fine.
>
> I've even tried playing the sound TWICE in one handler (with no "wait"
> delay between) and the same consistency applies.
>
> What can I do to work around this? Another audio format? Will Rev 2.0
> resolve it?
>
> Thanks,
> Barry
>
--------------------------------------------------------
Barry Jay Levine
"The Mac Guy"

Macintosh Troubleshooting, System Engineering, Training,
AppleShare/OSX Server Setup, System Upgrades and Enhancements,

On-Site service for K20, Business, Consumer

Phone/VoiceMail: 915-581-1105
             Fax: 915-581-8167
           eMail: themacguy at macosx.com

MacOS X: It does. You can. It will.
WindowsXP: Insert wallet into Drive A: Press any key to empty
--------------------------------------------------------




More information about the use-livecode mailing list