This content has been marked as final. Show 6 replies
Try using an onEnterFrame event to listen for a change in the sounds position. Like this
actually Gaz - you already have the right idea, if as you indicate, you only need to check the sound at the time the condition is called - there's just a couple of things you need to do differently. you should check the position against the 'durration' of the sound - and you need a return type on the method.
Thanks for your help Noel,
The problem I'm having is I need my code to decide, almost instantly, if a sound needs to be played or not. (within milliseconds, not 2 seconds unfortunately)
It seems that a sound that's 10,000 milliseconds long will have a position value of 0 before it's played and a value of 10,000 when it has finished. However if the sound was stopped somewhere in the middle, the position value freezes at the point it was when the sound stopped.
Later in the code, I want to start that sound again if the sound isn't playing, but if it already is, then I don't want to start it.
I can write an if statement to see if the sound hasn't been played (mySound.position==0) or if it has reached the end (mySound.position==mySound.duration) but if it was stopped mid flow (so to speak) and the position value is 3045, for example, I can't find a way of telling if the sound was stopped at 3045 milliseconds, or if it is currently playing and just happens to be at 3045 ms.
I thought by checking the position at two separate intervals (of a playing sound), then a few milliseconds will have lapsed between statements and the values would be different. Unfortunately they were exactly the same. :( So a playing sound would give the same result as a stopped sound. I could put a delay in between the two readings, but that would slow my animation down too much.
I've got over the problem by using boolean variables for each sound that get set to 'True' when a sound is started, get set to 'False' using an .onSoundComplete command, or get set to 'False' if the sound is stopped mid flow.
It's a bit of a clumsy way of doing it, but it seems to work and it makes my if Statement a bit easier.
If someone else has a better way, then I'd be over the moon to learn
Unfortunately that only tells me that the play position is somewhere in the middle and not whether it's moving or stationary, I should have clarified the sound could have been stopped part way through it's playing cycle, and that's what I needed to determine (if it's playing or stopped).
Thanks for your help.
if that is the case you should already 'know' that the sound was stopped - use a master variable and set it when stop() is called.
Thanks for that,
That's what I've done to resolve it (in my reply to Noelballand), it looks like there's no other way, I thought there may have been a built in method to check if a sound was playing that I'd overlooked.
Many thanks for your help.