11.52. HTML Audio

发布时间 : 2025-10-25 13:33:10 UTC      

Page Views: 10 views

Sound can be played in different ways in HTML.

11.52.1. Problems and solutions

Playing audio in HTML is not easy!

You need to be familiar with a lot of techniques to ensure that your audio files can be played in all browsers (Internet Explorer, Chrome, Firefox, Safari, Opera) and on all hardware (PC, Mac, iPad, iPhone).

In this chapter, the rookie tutorial summarizes the problems and solutions for you.

11.52.2. Use plug-ins

The browser plug-in is a minicomputer program that extends the standard functionality of the browser.

Plug-ins can be used label or tags are added to the page.

These tags define containers for resources (usually non-HTML resources), and depending on the type, they are displayed both by the browser and by external plug-ins.

11.52.3. Use element

tags define containers for external (non-HTML) content. This is a HTML5 tag that is illegal in HTML4 but valid in all browsers.

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

Example

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

11.52.4. Question:

  • tags are not valid in HTML 4. The page cannot be validated by HTML 4.

  • 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.

  • Audio cannot be played if the user’s computer does not have a plug-in installed.

  • If you convert the file to another format, it still cannot be played in all browsers.

11.52.5. Use element

tag> tags can also define containers for external (non-HTML) content.

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

Example

<object height="50" width="100" data="horse.mp3">object>      

11.52.6. Question:

  • 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.

  • Audio cannot be played if the user’s computer does not have a plug-in installed.

  • If you convert the file to another format, it still cannot be played in all browsers.

11.52.7. Use HTML5