Audio播放

 <audio controls="controls" id="warnAudio" hidden>
        <source src="~/mp3/HasNewWarn.mp3" type="audio/mpeg" />
    </audio>

使用audio元素播放mp3

更改播放为先判断未在播放状态后,才播放:

 var gWarnAudioEl = document.getElementById("warnAudio");
 var isPlaying = gWarnAudioEl.currentTime > 0 && !gWarnAudioEl.paused && !gWarnAudioEl.ended
                                && gWarnAudioEl.readyState > 2;

                            if (!isPlaying) {
                                gWarnAudioEl.play();
                            }

参考资料:

https://stackoverflow.com/questions/36803176/how-to-prevent-the-play-request-was-interrupted-by-a-call-to-pause-error

posted @ 2019-04-02 11:13  _York  阅读(...)  评论(...编辑  收藏