AudioContext()
+ createMediaElementSource()
+ createAnalyser()
/ getByteFrequencyData()
method test(Published November 28th, 2013. Updated 11/30.)
Related: createScriptProcessor() method test.
Objective: Retrieve audio channel data during playback using the Web Audio API, with a standard Audio()
object as the media source. It is expected that the media source approach avoids complexity and performance considerations (sequential loading, memory, decoding) associated with the alternate XHR + "arraybuffer" response approach - particularly when using longer sounds. (Related article.)
Expected: Audio channel data should be available via the getByteFrequencyData
method of an AnalyserNode
instance, when using createMediaElementSource()
and specifying an Audio()
object.
Observed (summary): Audio channel data is 0 under Safari 7 and iOS 7 during playback. Firefox chokes on initial playback, does not respect <audio>
volume control and incorrectly reflects playback position (bugzilla #944924.)
Warning: Firefox and/or iOS might play incredibly loud digital noise, ignoring system volume settings, during seek or playback. Don't wear headphones directly on ears to be safe.
Refer to console for JS debug output, event attachment messages etc.
Opening Chrome DevTools / console does not cause audio data / analysis to fail like in the createScriptProcessor() method test.
Related Chrome bug where wait for window.onload()
is required for visualization to work: crbug.com/112368.
Firefox 25 on WinXP + Firefox Aurora 27.0a2 on OS X: Initial playback (via autoplay = true;
) sometimes freezes with UI at 0:01. Clicking within UI to seek causes playback to resume. <audio>
shows the playback head fixed at end of UI (sound duration) during playback. Clicking to seek within the <audio>
element works for the audio, but the time/position UI either freezes at the seeked-to position or jumps to the end. Subsequent pause/play actions further confuse the position UI. (Bugzilla #944924.)
Cross-domain restrictions appear to apply to Firefox, but no CORS-related warnings were shown in the console. In testing, Chrome was able to play a cross-domain sound with channel data, sans-CORS headers.
Firefox Aurora does not play sound when loading this page (and the audio) from the local file system, via file:// - in Chrome, this works and sound plays as expected.
Firefox does not respect volume attribute of original <audio>
element, whether initial value set via JS or by user clicking volume control in UI during playback. (Chrome respects both.)
Safari, iPhone 5S with iOS 7.0.4: getByteFrequencyData()
returns an array of zeroes.
Safari 7.0 (9537.71), OS X 10.9: getByteFrequencyData()
returns an array of zeroes (webkit #125031.)