Cheese Puffs
Cheese Puffs

Reputation: 985

Playing sounds in Android mobile browser

I have having some troubles with HTML5 Audio in Android Browser. I need to play the same sound, 9 times. Which works great the first time I play them, because a make 9 sound objects. It may not be ideal but it works... atleast I thought it did.

This is how i do it:

var setSounds = function(){
    Sounds[0] = new x.Sound();
};

And then I play the sound like this:

       Sounds[0].play();

I have tried the following

        Sounds.[0].pause();
        Sounds.[0].play();

And

        Sound.[0].currentTime = 0;

I have more sounds then this just but to give you an idea. It plays all the sounds correctly the first time, but the second time I want to play all the sounds, its silent. This problem only occurs in Android browser.

Playing all the 9 sound objects first time - Perfect

Replaying the 9 sound objects again - Silent

How can i play my sound objects again? Any advice or solutions are welcome.

Upvotes: 1

Views: 451

Answers (1)

Matt
Matt

Reputation: 3847

The easiest work-around is to re-initialize the sound after it's been played.

Call sound[0].play(), then call setSounds(). If you're worried about the overhead in re-creating all the sounds, you could just re-initialize the one sound:

Sounds[0].play();
Sounds[0] = new x.Sound();

Upvotes: 1

Related Questions