html5网页想要加一个音乐播放器可以怎么做?

html-css019

html5网页想要加一个音乐播放器可以怎么做?,第1张

可以使用html5的audio标签来添加音乐播放器

<audio controls>

type:指定文件类型  

<source src="horse.ogg" type="audio/ogg">

   <source src="horse.mp3" type="audio/mpeg">

</audio>

对应的参数属性如下图:

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

具体用法:

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

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

src就是MP3的路径。

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

希望能帮到你。

据个人了解

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

第一种:页面代码中的<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>