View Single Post
Old 02-14-2013, 01:11 AM   PM User | #6
Old Pedant
Supreme Master coder!

 
Old Pedant's Avatar
 
Join Date: Feb 2009
Posts: 23,172
Thanks: 59
Thanked 3,993 Times in 3,962 Posts
Old Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to all
Well, see, my *GUESS* was that for some reason when you got the reference to the playing sound via
Code:
    var birdSound = document.getElementById("player");
that for some reason that was getting the state of the player *AT THE TIME* of that assignment. (Don't ask me why! Shouldn't be true, but...)

So since my code above seemed to work, it seems to me the answer is to just move that assignment inside the function:

But... but with this new code, I don't see any reason to refer to that variable, anyway.

What about:
Code:
    birdSound.addEventListener(
        'timeupdate', 
        function () {
            console.log(this.currentTime);
            if (coverBirds.paused) 
           {
                if (this.currentTime > trigger ) 
                {
                    alert("eventalert");
                    birdSound.play; // **** IS THIS RIGHT ??? ****
                }
           }
       }
    );
But in that code, shouldn't birdSound.play really be coverBirds.play ?

And are you sure it should be .play? You used that property, above, to indicate that the element *is* playing (or not). Here you seem to be wanting to invoke a *method* that tells it to start playing?

I just checked the docs. I'm right. To start something playing you use .play( ) -- call the method. Using just .play doesn't tell you anything except whether the object in question *has* a play method! So you were using it wrong all along.

So I *think* the line in question should be coverBirds.play( )

Assuming I understand your intent.
__________________
An optimist sees the glass as half full.
A pessimist sees the glass as half empty.
A realist drinks it no matter how much there is.

Last edited by Old Pedant; 02-14-2013 at 01:14 AM..
Old Pedant is offline   Reply With Quote