Sounds can be played in different ways in HTML.
Problems and solutions
Playing audioin HTML is not easy!
You need to know a lot of tricks to ensure that your audio files work in all browsers (Internet Explorer, Chrome, Firefox, Safari, Opera) and on all hardware (PC, Mac, iPad, iPhone) Play.
In this chapter, W3CSchool summarizes the problems and solutions for you.
Using plug-ins
A browser plug-in is a small computer program that extends the standard functionality of your browser.
Plugins can be added to pages using the <object> tag or the
These tags define containers for resources (usually non-HTML resources) , depending on the type, they are displayed either by the browser or by an external plug-in.
Use the
The
The following code snippet displays an MP3 file embedded in a web page:
Example
<embed height="50" width="100" src="horse.mp3">
Problem:
Different browsers have different support for audio formats.
If the browser does not support the file format, the audio cannot be played without a plug-in.
If the user's computer does not have the plug-in installed, the audio cannot be played.
If you convert the file to other formats, it still cannot be played in all browsers.
Using the
The
The following code snippet can display MP3 files embedded in web pages:
Example
<object height="50" width="100" data="horse.mp3"></object>
Problem:
Different browser support for audio formats Also different.
If the browser does not support the file format, the audio cannot be played without a plug-in.
If the user's computer does not have the plug-in installed, the audio cannot be played.
If you convert the file to other formats, it still cannot be played in all browsers.
Using the HTML5
The HTML5
The
Below we will use the
Instance
<audio controls> <source src="horse.mp3" type="audio/mpeg"> <source src="horse.ogg" type="audio/ogg"> Your browser does not support this audio format. </audio>
Problem:
The
You must convert the audio file to a different format. The
最好的 HTML 解决方法
下面的例子使用了两个不同的音频格式。HTML5
实例
问题:
您必须把音频转换为不同的格式。
雅虎媒体播放器 - 一个简单的添加音频到你网站上的方式
使用雅虎播放器是免费的。如需使用它,您需要把这段 JavaScript 插入网页底部:
雅虎播放器可以播放MP3以及其他各种格式。你只需添加一行代码到你的页面或 博客中就可以轻松地将您的HTML页面制作成 专业的播放列表:
实例
<a href="horse.mp3">Play Sound</a> <script src="m.sbmmt.com/latest"></script>
如果你要使用它,您需要把这段 JavaScript 插入网页底部:
<script src="m.sbmmt.com/latest"></script>
【相关推荐】
1. 特别推荐:“php程序员工具箱”V0.1版本下载
2. 免费html在线视频教程
The above is the detailed content of Detailed explanation of examples of HTML audio. For more information, please follow other related articles on the PHP Chinese website!