【小知識(shí)】js 播放wav,mp3音頻

事情是這個(gè)樣子

做了一個(gè)web應(yīng)用,有個(gè)提交成功的操作,突然想干一件事,就是無論成功與失敗都有個(gè)提示音效,就像微信收款成功的提醒似的,
話不多說,上代碼

function playSound()
    {
      var borswer = window.navigator.userAgent.toLowerCase();
      if ( borswer.indexOf( "ie" ) >= 0 )
      {
        //IE內(nèi)核瀏覽器
        var strEmbed = '<embed name="embedPlay" src="https://www.xing2020.com/static/flash/success.wav"></embed>';
        if ( $( "body" ).find( "embed" ).length <= 0 )
          $( "body" ).append( strEmbed );
        var embed = document.embedPlay;

        //瀏覽器不支持 audion,則使用 embed 播放
        embed.volume = 100;
        //embed.play();這個(gè)不需要
      } else
      {
        //非IE內(nèi)核瀏覽器
        var strAudio = "<audio id='audioPlay' src='https://www.xing2020.com/static/flash/success.wav' hidden='true'>";
        if ( $( "body" ).find( "audio" ).length <= 0 )
          $( "body" ).append( strAudio );
        var audio = document.getElementById( "audioPlay" );

        //瀏覽器支持 audion
        audio.play();
      }
    }

有需要的親們自行搬走,只求點(diǎn)個(gè)贊,互相關(guān)注一下,期待著在簡書能夠遇到同行,交個(gè)朋友??!

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容