JavaScript audio object addEventListener canplaythrough not working on IPAD Chrome

By | July 12, 2018
Questions:

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');
}
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);
  }
}

Leave a Reply

Your email address will not be published. Required fields are marked *