在我的网站上播放 mp3 [英] Playing mp3 on my website

查看:60
本文介绍了在我的网站上播放 mp3的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我想知道在我的网站上播放 mp3 的最佳方式是什么...

So I was wondering what the best way to play an mp3 on my website would be...

我有点希望它像 iTunes 方法一样运行和显示 - 一个简单的播放和停止按钮.像这样:

I kind of want it to function and appear like the itunes method - a simple play and stop button. like this:

我该怎么做?我真的不想嵌入播放器.

How should I do this? I don't really want to embed a player.

感谢您的帮助!添加到书签

Thanks for the help! Add to Bookmarks

推荐答案

最简单的方法是使用:

<embed height="50px" width="100px" src="song.mp3" /> 

但在大多数情况下,这也会显示可见的玩家.

But this will also show a visible player in most cases.

另一种方法是使用 HTML5 中的音频标签(旧浏览器不支持):

Another way to do this is using the audio tag from HTML5 (not supported in older browsers):

<audio id="audio">
    <source src="song.ogg" type="audio/ogg" />
    <source src="song.mp3" type="audio/mp3" />
</audio>

(此处使用 2 个源,因为大多数浏览器要么支持 ogg 要么支持 mp3.但通常不会同时支持)

(Using 2 sources here because most browsers either support ogg or mp3. But usually not both)

显示的标签将在您的页面上生成一个可控(不可见)的音频元素.然后,您可以使用 JavaScript 来控制带有自定义按钮的音频元素,例如:

The tag shown will generate a controllable (invisible) audio element on your page. You could then use JavaScript to control the audio element with a custom button for example:

<button onClick="document.getElementById('audio').play()">Play</button>
<button onClick="document.getElementById('audio').pause()">Pause</button>

这篇关于在我的网站上播放 mp3的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆