[HTML] 如何用html播放mp3文件?

html-css014

[HTML] 如何用html播放mp3文件?,第1张

你看,播放MP3可以直接用html标签embed

具体用法:

<embed autoplay="false" src="音乐文件名字.mp3" width="200" height="45" />

autoplay可选参数:true,false,其中true代表自动播放,false代表手动播放。

src就是MP3的路径。

width和height代表播放器的宽度和高度。

希望能帮到你。

需要准备的材料分别有:电脑、浏览器、html编辑器。

1、首先,打开html编辑器,新建html文件,例如:index.html。

2、在index.html中的<body>标签中,输入html代码:

<audio autoplay="autoplay" loop=""><source src="11704.mp3"></audio>。

3、浏览器运行index.html页面,此时一进入页面就自动播放了背景音乐。

据个人了解

网页中的音乐播放代码有以下几种:

第一种:页面代码中的<head></head>之间加入<bgsound src="音乐url" loop="-1">这段代码。 loop指音乐循环的次数,可设置为任意正整数,若设为“-1”的话,音乐将永远循环。

第二种:

在网页代码中的<style></style>标签之间加入一个“Embed”标签,其最简形式就像这样:

<embed src="音乐url" autostart="true" loop="true" width="80" height="20">

不同的是,在这里我们可以设置更多内容,相信内容请看w3scholl手册!

第三种:

使用超链接

例如:<a href="horse.mp3">Play the sound</a>

<script src="http://mediaplayer.yahoo.com/latest"></script>

第四种:

使用 HTML5 <audio>元素

<audio>元素是一个 HTML5 元素,在 HTML 4 中是非法的,但在所有浏览器中都有效。

例子:

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