【问题标题】:How to play audio file instantaneously on webpage如何在网页上即时播放音频文件
【发布时间】:2014-01-26 02:23:24
【问题描述】:

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

【问题讨论】:

标签: streaming real-time


【解决方案1】:

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

【讨论】:

  • 目前我正在以同样的方式进行操作。我正在寻找更快的替代方案
猜你喜欢
  • 2013-10-05
  • 1970-01-01
  • 1970-01-01
  • 2013-10-18
  • 1970-01-01
  • 2013-03-30
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多