0

我尝试在 Chrome for mobile 上使用 HTML5 和 JavaScript 播放一些声音(wav、ogg),但它不起作用。我什至尝试了“假”点击,但什么也没发生。

$(document).on("click", "#audio", function(){
    var a = $('#audio');
    if(a.length !== 0){
        a.get(0).play();
    }
});
$('#audio').click();

或者

var audio = new Audio("file.ogg");
audio.play();

HTML

<audio controls="controls" id="audio" class="hidden">
   <source src="file.wav"></source>
</audio>

谢谢你。

4

1 回答 1

0

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.

There is a small, somewhat specialized example here:

http://jsbin.com/arecoq/84

Note that the music is licensed under Creative Commons BY-CC-SA, see further info here.

于 2013-05-02T18:14:52.923 回答