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

Detailed explanation of examples of HTML audio

零下一度
Release: 2017-05-15 13:43:56
Original
1494 people have browsed it

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

The 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">
Copy after login

Problem:

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 element

The 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>
Copy after login

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>
Copy after login

Problem:

The

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

最好的 HTML 解决方法

下面的例子使用了两个不同的音频格式。HTML5

实例

Copy after login

问题:

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

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

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

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

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

实例

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

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

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

【相关推荐】

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template