2014-01-08 41 views
0

我想从服务器播放音频文件。目前我正在使用html音频控制,但它非常慢。我的要求是尽可能快地发挥,几乎是瞬间。什么才是实现这个目标的最好方法?参考源将不胜感激。提前致谢。如何在网页上即时播放音频文件

+1

入住这http://stackoverflow.com/questions/13624048/what-is-the-best-way-to-stream-a-audio-file-to-website-users-listners – vijaykumar

回答

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); 
+0

目前我我正在以同样的方式做。我正在寻找更快的选择 – BhendiGawaar