Play Audio - iOS Does Not Play Sound - Sound Output Delay

0

I have this function to load, remove, start and pause the audio.

media = (function(){
    return{
        create : function(name, src){
            mediaData[name] = new Audio();
            mediaData[name].src = baseURL+'/media/'+src;
            mediaData[name].volume = .5;
        },
        remove : function(name){
            if(mediaData[name]){
                delete mediaData[name];
            }
        },
        play : function(name){
            return mediaData[name].play();
            if(!Modernizr.touch)
                mediaData[name].currentTime = 1;
        },
        stop : function(name){
            mediaData[name].pause();
            if(!Modernizr.touch)
                mediaData[name].currentTime = 0;
        },
        replay : function(name){
            if(!Modernizr.touch)
                mediaData[name].currentTime = 0;
        }
    }
})();

But Safari from iPad I'm having problems. Some audios charge and work, others do not play. And other browsers work normally.

What can it be?

An example of how I call audio via JS .

setTimeout(function() {
  media.play("chime-01"); /////////////// FUNCIONA
  setTimeout(function() {
    $("div#gift").addClass('anime');
    var randomGift = Math.floor((Math.random() * totalGifts) + 1);
    var gift = $('div#gift > .gifts > div:nth-child(' + randomGift + ')');
    gift.addClass('active');
    setTimeout(function() {
      gift.addClass('rotate');
      //Frase do objeto
      var audio = gift.data('audio');
      setTimeout(function() {
        media.play(audio); ////////////// NÃO FUNCIONA
      }, 1400);
    }, 2000);
    media.play("tada");
  }, 100);
}, 250);

In the code above I commented the line that the audio works and the line that does not work on iOS - Safari - iPad.

But in other browsers, the two lines work. So, before anyone claims, the audio path is right, the variables with their values as well.

I was reading through the Safari documentation and found this:

  

In Safari on iOS (for all devices, including iPad), where the user may be on a cellular network and be charged per data unit, preload and autoplay are disabled. No data is loaded until the user initiates it.

Translating:

In Safari on iOS (for all devices including iPad) where the user can be on a cellular network and be charged per data unit (3G, 4G), preloading and autoplay are disabled. No data is loaded until the user starts it.

What now? Is not no way for this?

    
asked by anonymous 25.08.2015 / 16:09

0 answers