Pergunta

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

Foi útil?

Solução 3

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

Outras dicas

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.

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.
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top