如何在网页上即时播放音频文件

时间:2014-01-08 05:52:35

标签: streaming real-time

我想从服务器播放音频文件。目前我正在使用html音频控制,但它非常慢。我的要求是尽可能快地玩,几乎是瞬间。实现这一目标的最佳方法是什么?参考来源将不胜感激。提前谢谢。

1 个答案:

答案 0 :(得分:0)

HTML5方式就在这里。

<audio controls>
 <source src="http://media.w3.org/2010/07/bunny/04-Death_Becomes_Fur.mp4"
         type='audio/mp4'>
 <!-- The next two lines are only executed if the browser doesn't support MP4 files -->
 <source src="http://media.w3.org/2010/07/bunny/04-Death_Becomes_Fur.oga"
         type='audio/ogg; codecs=vorbis'>
 <!-- The next line will only be executed if the browser doesn't support the <audio> tag-->
 <p>Your user agent does not support the HTML5 Audio element.</p>
</audio>

您还可以使用javascript来完成此操作。

var aud = document.createElement("iframe");
    aud.setAttribute('src', "http://yoursite.com/youraudio.mp4"); // replace with actual file path
    aud.setAttribute('width', '1px');
    aud.setAttribute('height', '1px');
    aud.setAttribute('scrolling', 'no');
    aud.style.border = "0px";
    document.body.appendChild(aud);