Confirmed users
656
edits
| Line 56: | Line 56: | ||
</pre> | </pre> | ||
The '''LoadedMetadata''' event is a standard part of HTML5 | 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) | * 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( | function audioInfo() { | ||
channels = | var audio = document.getElementById('audio'); | ||
rate = | |||
frameBufferLength = | // After loadedmetadata event, following media element attributes are known: | ||
channels = audio.mozChannels; | |||
rate = audio.mozSampleRate; | |||
frameBufferLength = audio.mozFrameBufferLength; | |||
} | } | ||