使用javascript播放mp3文件 [英] Play mp3 file using javascript
问题描述
哪些是最好的和跨浏览器的方式通过javascript播放mp3(非常短)文件?
我尝试了不同的方法,但总是有一个问题...
编辑1: b $ b
我不需要一个完整的播放器,我只需要一个函数,我可以调用每次发生的事情
编辑2:
好的,我必须更好地解释我的问题。服务器是在LAN中连接的智能手机,但不总是连接到互联网。我想使用mp3,因为文件重量只有3kb(而不是60kb的wav),但如果播放这个文件的机制太重(一个播放器或jquery.js)我认为最好使用wav文件。
其他建议?
使用:
new Audio('your / url / here')play()
此文档( HTMLAudioElement
),请注意,大多数控件都是由 HTMLMediaElement
。
Which is the best and cross-browser way to play a mp3 (very short) file via javascript? I tried different ways but there's always a problem...
EDIT 1:
I don't need a "full" player, I just need a function than I can call everytime something happens
EDIT 2:
Ok, I've to explain better my problem. The server is a smartphone connected in a LAN, but not always to the internet. I want to use mp3 because the file weighs only 3kb (instead of 60kb of wav), but if the mechanism to play this file is too "heavy" (a player or jquery.js) I think is better to use the wav file. Other suggestions?
Use this:
new Audio('your/url/here').play()
The documentation for the this (HTMLAudioElement
) can be found at MDN, note that most of the controls are inherited by HTMLMediaElement
.
这篇关于使用javascript播放mp3文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!