Web Audio API: seek, play-/buffer-progress

不想你离开。 提交于 2019-12-10 22:16:07

问题


When you play audio using the audio element in Chrome you get annoying clicks and cracks. At least under my 64bit Linux installation, even after I formatted and installed a new Fedora version. (Firefox and Opera are fine, even IE9 in a VirtualBox Windows 7.)

But demos using the Web Audio API instead of the audio element have perfect sound. So I was wondering if I could use the Web Audio API like the audio element? But there are some things you seem not to be able to do with this API. Or am I missing something? The things I couldn't find where:

  • starting to play a file before it is completely loaded
  • getting buffer progress updates (depends on the previous point)
  • getting play progress updates
  • seeking

Is there a way to do this with the Web Audio API?

This is where I would use it: http://tinyurl.com/magnatune-player


回答1:


I think you should still use <audio> for streaming at the very least. You can treat it as a MediaElementAudioSourceNode in web audio if you'd like:

var mediaSourceNode = context.createMediaElementSource(audioElement);

AFAIK, there is no way to stream web audio directly. In fact, the web audio api suggests that you don't:

4.9. The AudioBuffer Interface

This interface represents a memory-resident audio asset (for one-shot sounds and other short audio clips). Its format is non-interleaved IEEE 32-bit linear PCM with a nominal range of -1 -> +1. It can contain one or more channels. Typically, it would be expected that the length of the PCM data would be fairly short (usually somewhat less than a minute). For longer sounds, such as music soundtracks, streaming should be used with the audio element and MediaElementAudioSourceNode.




回答2:


Unless you used a MediaElementAudioSourceNode (which I would assume suffer from the same issues you're having since it's just using an <audio> tag) AFAIK the answers to your questions are:

  • starting to play a file before it is completely loaded: No.
  • getting buffer progress updates (depends on the previous point): Possibly (You could check for progress events on the XHR)
  • getting play progress updates: No.
  • seeking: No.



回答3:


In the meantime Chrome fixed the audio playback issues. So I don't need any workarounds anymore.



来源:https://stackoverflow.com/questions/10785354/web-audio-api-seek-play-buffer-progress

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!