0

I am building a website, in which there is a feature to play audio in a single ear headphone randomly, all of the code is working fine in Google Chrome, Firefox, Microsoft Edge, but not working in IE(11). I have been stuck in solving this bug but it's always showing the following error

SCRIPT445: Object doesn't support this action

the code Is there.

(document).ready(function(){
    var clickCount=0;
    var counterall=0;
     var item;
    $('#start_sample').click(function(){
      clickCount=1;
    $('audio#audio2')[0].play();

      var items = Array(1,-1,1,-1,1,-1,1,-1,1,-1,1,-1,1,-1,1,-1,1,-1,1,-1,1,-1,1,-1,1,-1,1,-1,1,-1);
     item = items[Math.floor(Math.random() * items.length)];

    if(item==-1){         
    //$('#audio2').prop('disabled', true);
        $('#start_sample').css('background-color','lightgray');
      var audioCtx = new (window.AudioContext || window.webkitAudioContext);
      var myAudio = document.querySelector('audio');        

      var source = audioCtx.createMediaElementSource(myAudio);

      var panNode = audioCtx.createStereoPanner();

      panNode.pan.value = -1;

      source.connect(panNode);
      panNode.connect(audioCtx.destination);
      var aud = document.getElementById("audio2");
      aud.onended = function() { 

      $('#start_sample').css('background-color','#157eef');

      audioend=0;
     };
      
    }

Kindly Help out me or give me a parallel solution so I can remove it.

  • 1
    Web Audio API isn't available in Internet Explorer. – HankMoody Aug 04 '20 at 17:17
  • Can we use a similar code to solve it? – Haseeb Ahad Aug 04 '20 at 17:19
  • 1
    You can try an audio library that implements HTML5 audio as a fallback, e.g. Howler.js. – HankMoody Aug 04 '20 at 17:21
  • what i want to redirect sound in one earbud on playing sound. can you help it? – Haseeb Ahad Aug 04 '20 at 17:22
  • 1
    Web Audio API is [not compatible with IE](https://developer.mozilla.org/en-US/docs/Web/API/Web_Audio_API#Browser_compatibility). According to [this thread](https://stackoverflow.com/questions/26275394/alternate-for-web-audio-api), if you need to do dynamic synthesis, audio routing, etc, there's no alternative for Web Audio API in IE. I think you can only check Web Audio API support and give users a reminder if it's not support in some browsers. If you only need to play audio files, then you can use [howler.js](https://github.com/goldfire/howler.js#documentation) as an alternative. – Yu Zhou Aug 05 '20 at 06:40
  • @YuZhou I have used Howler.js and its playing sound but still, its function is not working according to my requirements. – Haseeb Ahad Aug 05 '20 at 06:55
  • 1
    I think we can't do anything in IE except playing the audio. And there is no polyfill for the Web Audio API. You can only detect the browser support for Web Audio API and offer a fallback if it's not supported like in [this thread](https://stackoverflow.com/questions/27708341/html5-how-to-replace-webaudio-api-for-internet-explorer-for-javascript-games). I think you can only drop the support of `AudioContext` in IE. – Yu Zhou Aug 05 '20 at 08:30

0 Answers0