<div>
    @*音乐*@
    <audio id="warning-sound" loop="loop" src="/Areas/MapTest/Content/Sound/WarningSound.wav"></audio>

</div>

在页面body中插入以上<audio>标签,loop代表循环播放,src指向音频地址。

当然要控制音频播放、暂停还需要加入JS代码。

<script type="text/javascript">
    $(document).ready(function () {
        //控制预警开启或者关闭
        $("#WarningLight").click(function () {
            var audio = document.getElementById("warning-sound");
            if (audio !== null) {
                //检测播放是否已暂停.audio.paused 在播放器播放时返回false.
                console.log(audio.paused);
                if (audio.paused == true) {
                    audio.play();   //播放
                }
                else{
                    audio.pause();  //暂停
                }
            }
        }
    }
</script>

 

相关文章:

  • 2022-12-23
  • 2021-10-10
  • 2021-07-08
  • 2021-12-24
  • 2021-07-09
  • 2021-11-06
  • 2022-12-23
  • 2021-11-02
猜你喜欢
  • 2021-12-16
  • 2021-08-30
  • 2021-06-25
  • 2021-12-24
  • 2021-07-04
  • 2021-12-18
  • 2021-10-04
相关资源
相似解决方案