Shiplu Mokaddim
Shiplu Mokaddim

Reputation: 57660

Html5 audio does not load/play even on click handlers

I am using the following code to load sound on iPad Safari.

    var EI={sound:{}};
    EI.sound.load = function(){
        var preferFlash = true;
        if (Ext.os.is('iOS') && Ext.browser.is('WebKit'))
            preferFlash = false;
        // Load sound modules
        soundManager.setup({
            debugMode: true,
            preferFlash: false,
            onready: function(){
                var s = EI.sound; 
                s.audio = soundManager.createSound({
                    id: 'audio',
                    url: 'sound/sprite.mp3'
                });
                var opt = s.opt.online, f = opt.start+opt.duration, t=f+1500;
                if (s.enabled)  s.audio.play({from:opt.start, to:opt.start+opt.duration});
            }
        });
    }

The opt is defined as

EI.sound.opt = {
    "msg":{start: 53, duration: 701},
    "offline":{start: 1904, duration: 487},
    "online":{start: 3548, duration: 2476},
}

And a buttons click event handler looks like this,

handler: function(btn){
    EI.sound.load();
}

The problem is when the button is clicked the sound does not play. I am aware that Mobile Safari has limitation on html5 audio. These are steps that I took to over come it.

  1. Only one file can be loaded. So I make an audio sprite and playing only some portion of it.
  2. Sound can be loaded only on click or touchstart even handler. So I am loading on click event handler.

But still no sound. I expect to hear sound when I press that button. Its a splash image type button. Its the first button a user must have to press to use the application.

How can I make the audio play successfully?

Here are some resources

  1. http://www.ibm.com/developerworks/library/wa-ioshtml5/index.html
  2. SoundManager2 on iPhone - Sound not playing on jQuery Load

Upvotes: 1

Views: 653

Answers (1)

Snsxn
Snsxn

Reputation: 167

You are using "EI.sound.load()" while you have to use "EI.sound.play()" or autplay: true in your soundmanager setup.

Upvotes: 0

Related Questions