Home  >  Article  >  Web Front-end  >  Detailed explanation of examples of HTML audio

Detailed explanation of examples of HTML audio

零下一度
零下一度Original
2017-05-15 13:43:561436browse

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 922c72e1afaae8549a35684b67043089 tag or the d8e2720730be5ddc9c2a3782839e8eb6 tag.

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 d8e2720730be5ddc9c2a3782839e8eb6 element

Thed8e2720730be5ddc9c2a3782839e8eb6 tag defines a container for external (non-HTML) content. (This is a HTML5 tag, which is illegal in HTML4, but valid in all browsers).

The following code snippet displays an MP3 file embedded in a web page:

Example

<embed height="50" width="100" src="horse.mp3">

Problem:

d8e2720730be5ddc9c2a3782839e8eb6 tag in HTML 4 it is invalid. The page fails HTML 4 validation.

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 273238ce9338fbb04bee6997e5552b95 element

The6c2beb9195a89728dfa3a8d1dbf2ef62 tag can also define a container for external (non-HTML) content.

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 b97864c2e0ef2353a16c4d64c7734e92 element

The HTML5 b97864c2e0ef2353a16c4d64c7734e92 element is an HTML5 element that is illegal in HTML 4, but is valid in all browsers.

The b97864c2e0ef2353a16c4d64c7734e92 element works in all modern browsers.

Below we will use the b97864c2e0ef2353a16c4d64c7734e92 tag to describe MP3 files (valid in Internet Explorer, Chrome and Safari), Also adds an OGG type file (valid in Firefox and Opera browsers). If it fails, it will display an error text message:

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 b97864c2e0ef2353a16c4d64c7734e92 tag is invalid in HTML 4. Your page fails HTML 4 validation.

You must convert the audio file to a different format. The

b97864c2e0ef2353a16c4d64c7734e92 element does not work in older browsers.

最好的 HTML 解决方法

下面的例子使用了两个不同的音频格式。HTML5 b97864c2e0ef2353a16c4d64c7734e92 元素会尝试以 mp3 或 ogg 来播放音频。如果失败,代码将回退尝试 d8e2720730be5ddc9c2a3782839e8eb6 元素。

实例

问题:

您必须把音频转换为不同的格式。

d8e2720730be5ddc9c2a3782839e8eb6 元素无法回退来显示错误消息。

雅虎媒体播放器 - 一个简单的添加音频到你网站上的方式

使用雅虎播放器是免费的。如需使用它,您需要把这段 JavaScript 插入网页底部:

雅虎播放器可以播放MP3以及其他各种格式。你只需添加一行代码到你的页面或 博客中就可以轻松地将您的HTML页面制作成 专业的播放列表:

实例

<a href="horse.mp3">Play Sound</a>
<script src="www.php.cn/latest"></script>

如果你要使用它,您需要把这段 JavaScript 插入网页底部:

<script src="www.php.cn/latest"></script>

【相关推荐】

1. 特别推荐“php程序员工具箱”V0.1版本下载

2. 免费html在线视频教程

3. php.cn原创html5视频教程

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn