Html HTML5 音频显示仅播放暂停和静音按钮
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/13810085/
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
HTML5 Audio display only play pause and mute buttons
提问by user1380540
I'm wondering if there's a quick and simple way to style the HTML5 audio element to display what I want. I was wondering if you could turn certain controls on and off, but that doesn't seem to be the case.
我想知道是否有一种快速简单的方法来设置 HTML5 音频元素的样式以显示我想要的内容。我想知道您是否可以打开和关闭某些控件,但似乎并非如此。
I do not want a progress/track bar, or to display the time left. I just want a simple play/pause toggle button, and a mute/unmute toggle button.
我不想要进度/轨迹栏,也不想要显示剩余时间。我只想要一个简单的播放/暂停切换按钮和一个静音/取消静音切换按钮。
That's all! Any ideas?
就这样!有任何想法吗?
回答by Mohd. Umar
Use this code it will serve your purpose.
使用此代码它将满足您的目的。
<!DOCTYPE html>
<html>
<body>
<audio id="player" src="horse.ogg"></audio>
<div>
<button onclick="document.getElementById('player').play()">Play</button>
<button onclick="document.getElementById('player').pause()">Pause</button>
<button onclick="document.getElementById('player').muted=!document.getElementById('player').muted">Mute/ Unmute</button>
</div>
</body>
</html>
回答by Ian Devlin
You could use the Media APIand build your own set of controls with the functionality you want. I've written about this: Working with HTML5 multimedia components – Part 3: Custom controls - which shows a video example, but you can just as easily build an audio one.
您可以使用媒体 API并使用您想要的功能构建您自己的控件集。我已经写过这篇文章:使用 HTML5 多媒体组件 – 第 3 部分:自定义控件– 展示了一个视频示例,但您也可以轻松构建音频示例。