JS implementation of wav audio file playback compatible with IE

Time:2021-3-17

When the online audio resources cannot be played in ie, try the embedded tag

/**
 *Get the recording label according to the browser
 *@ param {recording media playback address} SRC 
 */
function getAudioDom(src) {
  var userAgent =  navigator.userAgent ; // get the useragent string of the browser
  if (
    (userAgent.indexOf("Trident") > -1 && userAgent.indexOf("rv:11.0")) ||
    (userAgent.indexOf("compatible") > -1 && userAgent.indexOf("MSIE") > -1)
  ) {
    //If it is IE browser, embedded will be displayed
    return (
      '<embed class="embed"  type="audio/wav"  menu="true" loop="false" align="center" preload="auto" autostart="false">\
                                    </embed>'
    );
  } else {
    return (
      '<audio controls="controls" type="audio/wav" id="record-audio" preload></audio>'
    );
  }
}

Audio style in IE

embed{
border:1px solid gray;
height: 40px;
width: 350px;
margin-left: 10px; 
background-color:#F8F8F8;
 }