[英]Audio on Chrome for mobile isn't working using Jquery
I tried to play some sound (wav, ogg) using HTML5 with JavaScript on Chrome for mobile, but it's not working. 我尝试在移动版Chrome上使用带有JavaScript的HTML5播放一些声音(wav,ogg),但无法正常工作。 I even tried a "fake" click, but nothing happened. 我什至尝试了“假”点击,但没有任何反应。
$(document).on("click", "#audio", function(){
var a = $('#audio');
if(a.length !== 0){
a.get(0).play();
}
});
$('#audio').click();
or 要么
var audio = new Audio("file.ogg");
audio.play();
HTML 的HTML
<audio controls="controls" id="audio" class="hidden">
<source src="file.wav"></source>
</audio>
Thank you. 谢谢。
I'd try something like this: 我会尝试这样的事情:
$('some-button').on('click', function(){
$('audio')[0].play();
});
In other words - use a button to receive the click and then find the audio
element and make it start playing. 换句话说-使用按钮来接收点击声,然后找到audio
元素并使其开始播放。
There is a small, somewhat specialized example here: 这里有一个很小的,有些专业的示例:
http://jsbin.com/arecoq/84 http://jsbin.com/arecoq/84
Note that the music is licensed under Creative Commons BY-CC-SA, see further info here . 请注意,音乐是根据知识共享BY-CC-SA许可的,请在此处查看更多信息 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.