Audio Data API Review Version: Difference between revisions

Jump to navigation Jump to search
Line 56: Line 56:
</pre>
</pre>


The '''LoadedMetadata''' event is a standard part of HTML5, and has been extended to provide more detailed information about the audio streamSpecifically, developers can obtain the '''number of channels''', '''sample rate per second''', and '''default size of the framebuffer''' that will be used in audiowritten events.  This event is fired once as the media resource is first loaded, and is useful for interpreting or writing the audio data.
The '''LoadedMetadata''' event is a standard part of HTML5.  It now indicates that a media element (audio or video) has useful metadata loaded, which can be accessed using three new attributes:


The '''AudioWritten''' event provides two pieces of data.  The first is a framebuffer (i.e., an array) containing sample data (i.e., floats) for the current frame.  The second is the time for these samples measured from the start in milliseconds.
* mozChannels
* mozSampleRate
* mozFrameBufferLength
 
Prior to the '''LoadedMetadata''' event, these attributes will return 0 (zero), indicating that they are not known, or there is no audio.  These attributes indicate the '''number of channels''', audio '''sample rate per second''', and the '''default size of the framebuffer''' that will be used in '''AudioWritten''' events.  This event is fired once as the media resource is first loaded, and is useful for interpreting or writing the audio data.
 
The '''AudioWritten''' event provides two pieces of data.  The first is a framebuffer (i.e., an array) containing decoded audio sample data (i.e., floats).  The second is the time for these samples measured from the start in seconds.


The following is an example of how both events might be used:
The following is an example of how both events might be used:
Line 68: Line 74:
     samples;
     samples;


function audioInfo(event) {
function audioInfo() {
   channels          = event.mozChannels;
  var audio = document.getElementById('audio');
   rate              = event.mozSampleRate;
 
   frameBufferLength = event.mozFrameBufferLength;
  // After loadedmetadata event, following media element attributes are known:
   channels          = audio.mozChannels;
   rate              = audio.mozSampleRate;
   frameBufferLength = audio.mozFrameBufferLength;
}
}


Confirmed users
656

edits

Navigation menu