Question

I have a web app for Tizen OS. I need to play one sound twice and do some actions after every time.

In browser it works perfect, but acts really strange on a device. Sometimes first time sound plays as it should be, second time there is no sound. Sometimes both times it plays, but callbacks are not called.

Code:

var callback = function() {
    doAction()
};
SoundManager.playSound(soundID, callback);
setTimeout(function() {
    callback = function() {
        doAnotherAction();
    };
    SoundManager.playSound(soundID, callback);
}, 3000);

Sound Manager:

SoundManager.playSound = function(id, callback) {
    if (callback != null) {
        var func = function() {
            callback();
            this.removeEventListener('ended', func, false);
        }
        $(SoundManager.sounds[id])[0].addEventListener('ended', func, false);
    }
    $(SoundManager.sounds[id])[0].play();
};
Was it helpful?

Solution

Found solution.

Every time just add 'ended' callback to the audio and reset time:

this.currentTime = 0;
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top