Html 带有 HTML5 音频标签的自定义 1 键播放器
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3472459/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Custom 1-button player with HTML5 audio tag
提问by Kaji
Working with the <audio>
tag in some web development I've been doing lately, and one thing I'm trying to do is use it to build a word list and provide a pronunciation sample next to each word on the list. Setting this up isn't hard at all, however this sort of application hardly requires the full set of controls; just a play button.
<audio>
在我最近一直在做的一些 Web 开发中使用标签,我正在尝试做的一件事是使用它来构建一个单词列表并在列表中的每个单词旁边提供一个发音示例。设置它一点也不难,但是这种应用程序几乎不需要全套控件;只是一个播放按钮。
The controls
element of the <audio>
tag doesn't seem to be that well documented at all, however; all I can find on it is "always put 'on' here, unless you want to build your own player". I don't want to build my own player, however, I just want a simple, 1-button play interface with nothing else, ideally without requiring JavaScript or Flash.
然而controls
,<audio>
标签的元素似乎根本没有被很好地记录下来;我所能找到的只是“总是把'放在'这里,除非你想建立自己的播放器”。我不想构建自己的播放器,但是,我只想要一个简单的一键式播放界面,没有其他任何东西,理想情况下不需要 JavaScript 或 Flash。
回答by Anurag
It's fairly simple. You just need to call the play method on the audio
DOM object when something is clicked. The something could be an image, text, link, or whatever suits.
这相当简单。您只需要在audio
单击某些内容时调用DOM 对象上的 play 方法。东西可以是图像、文本、链接或任何适合的东西。
Here's one possible way:
这是一种可能的方法:
<a onclick="this.firstChild.play()"><audio src=".."></audio></a>