在HTML中播放音频 [英] Playing Audio in HTML
问题描述
我想在HTML中发挥的MP3音频文件。我不希望显示像音量等控制整个播放器
我只是需要一个播放/暂停按钮,我设计,而不是一些播放器的核心设计,像雅虎播放器或Google之一。
I want to play a mp3 audio file in HTML. I don't want to display the whole player with controls like Volume etc. I just need a play/pause button, Designed by me, not the core design of some player, like yahoo player, or google one.
例如音频将自动播放。当点击一个按钮(可能的图像),它会暂停,并再次点击该图像时,音频将再次发挥。
For example the audio will be autoplay. When a button (probably an image) is clicked it will pause, and when that image is clicked again, the audio will play again.
有相当一些例子在这里: http://www.w3schools.com/html/html_sounds .asp的
There are quite few examples here : http://www.w3schools.com/html/html_sounds.asp
我可以控制任何一个从JS code播放/停止?
Can I control any of them to play/stop from JS code ?
推荐答案
您可以使用HTML5的音频标记。您可以指定播放自己的控件。
You can use the html5 audio tag. You can specify your own controls for playback.
<audio preload="auto" autobuffer>
<source src="elvis.mp3" />
<source src="elvis.wav" /> <!-- fallback if no mp3 support in browser -->
</audio>
这是一个jQuery的解决方案。
This is a jQuery solution.
http://jsfiddle.net/QPW27/109/
这是你的非jQuery的解决方案将是什么样子。
This is what your non-jQuery solution would look like.
var foo = document.getElementById('player');
foo.pause(); //just bind play/pause to some onclick events on your page
foo.play();
不同的浏览器支持不同的音频格式。您可以指定虽然备用音频版本。这个网站有浏览器支持的一个很好的图一>为2011年7月的
这篇关于在HTML中播放音频的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!