音频只能在Google Chrome中以HTML格式播放一次 [英] Audio played once only in Google Chrome in html

查看:617
本文介绍了音频只能在Google Chrome中以HTML格式播放一次的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

下面的代码是我如何把音频放入我的网页。当我从我的从属设备收到协议时它会播放声音。

 < script> 
函数RxProtocol()
{
var a = document.getElementById(audio1);
a.play();
}

< / script>

< body>
< audio id =audio1>
< source src =audio.wavtype =audio / wav>
< source src =audio.mp3type =audio / mpeg>不支持
音频标签。
< / audio>
< / body>

假设每次收到协议时播放声音。但是,当我使用谷歌浏览器,它只是播放一次(刷新/重新加载页面后),当它收到第一个协议。之后,它在接收协议时是无声的。



其他类似IE9或Firefox的浏览器没有这个问题。你们知道为什么吗?

解决方案

尝试添加addEventListener:

 <脚本> 
函数RxProtocol()
{
var a = document.getElementById(audio1);
a.play();
}

document.addEventListener(load,RxProtocol,false);

< / script>

问候,丹尼尔


The below code is how I put audio in my webpage. It will play the sound when I received protocol from my slave device.

<script>
function RxProtocol()
 {
    var a = document.getElementById("audio1");
    a.play();
 }

</script>

<body>
<audio id="audio1">
<source src="audio.wav" type="audio/wav">
<source src="audio.mp3" type="audio/mpeg">
audio tag not supported.
</audio>
</body>

It is suppose to play the sound each time it received a protocol. But when I use google Chrome, it just play once only (after refresh/reloading the page) when it received the first protocol. After that it is silence when receive protocols.

Other browser like IE9 or firefox do not have this problem. Do you guys know why?

解决方案

Try adding addEventListener :

<script>
function RxProtocol()
 {
    var a = document.getElementById("audio1");
    a.play();
 }

document.addEventListener("load", RxProtocol, false);

</script>

Regards, Daniel

这篇关于音频只能在Google Chrome中以HTML格式播放一次的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆