开发者

Playing audio with HTML5

开发者 https://www.devze.com 2022-12-20 22:03 出处:网络
I would like to support playing audio on a web page with HT开发者_如何学编程ML5. Currently I support IE with an embedded media player. The Javascript on the page interacts with the media player contro

I would like to support playing audio on a web page with HT开发者_如何学编程ML5. Currently I support IE with an embedded media player. The Javascript on the page interacts with the media player control to start, stop, skip, change volume etc.

I would like to have the same control over the audio with HTML5. What kind of interface is available to the audio object?


The simplest case would be to place an audio tag in the code with the src pointing to your audio file. Once you get the element from JavaScript you will have a bunch of methods available.

Example:

var audio_file1 = document.getElementById('audio_tag_id');
audio_file1.play();

If still want to deal with fallback cases and show your current player in browsers that still don't support the audio tag (like IE) follow the steps in this tutorial: http://www.html5rocks.com/samples/audio/quick/


See the spec for the interface (but don't expect complete implementations in browsers yet)

0

精彩评论

暂无评论...
验证码 换一张
取 消