Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JavaScript audio object addEventListener canplaythrough not working on IPAD Chrome

I have two functions in JavaScript. Its working fine on Windows 7 Chrome but loadedAudio_chrome function is not being fired on IPAD.

function preloadAudio_chrome(url)
{
  try 
  {
       var audio = new Audio();
       audio.addEventListener('canplaythrough', loadedAudio_chrome, false);
       //audio.src = filePath;
  } catch (e) {
    alert(e.message);
  }
}

function loadedAudio_chrome()
{
   //alert('not firing this alert on IPAD');
}
like image 625
Afnan Ahmad Avatar asked Dec 16 '16 16:12

Afnan Ahmad


1 Answers

You seem to be missing audio.load() from your snippet, try adding that as shown below and it should work.

function preloadAudio_chrome(url)
{
  try 
  {
       var audio = new Audio();
       audio.addEventListener('canplaythrough', loadedAudio_chrome, false);
   // EDIT HERE ADD audio.load();
       audio.load();
  } catch (e) {
   alert(e.message);
  }
}
like image 122
M. Waqas Khan Avatar answered Nov 14 '22 23:11

M. Waqas Khan