Please note, this is a STATIC archive of website developer.mozilla.org from 03 Nov 2016, cach3.com does not collect or store any user information, there is no "phishing" involved.

Revision 963291 of HTMLAudioElement

  • Revision slug: Web/API/HTMLAudioElement
  • Revision title: HTMLAudioElement
  • Revision id: 963291
  • Created:
  • Creator: JustusAdam
  • Is current revision? Yes
  • Comment

Revision Content

{{APIRef("HTML DOM")}}
 

The HTMLAudioElement interface provides access to the properties of {{HTMLElement("audio")}} elements, as well as methods to manipulate them. It derives from the {{domxref("HTMLMediaElement")}} interface.

Properties

No specific property; inherits properties from its parent, {{domxref("HTMLMediaElement")}}, and from {{domxref("HTMLElement")}}.

Methods

Inherits methods from its parent, {{domxref("HTMLMediaElement")}}, and from {{domxref("HTMLElement")}}.

Constructor

Syntax

mySound = new Audio([URLString]);

Description

Constructor for audio elements. The preload property of the returned object is set to auto and the src property is set to the argument value. The browser begins asynchronously selecting the resource before returning the object.

Note: An Audio element constructed with new Audio() won't be garbage collected so long as playback is in progress. It will continue playing and be audible until stop() is called or playback finishes.

Parameters

URLString (expected type: {{domxref("DOMString")}}; optional)
The src property of the constructed HTMLAudioElement.

Regular methods

Name & Arguments Return Description
mozCurrentSampleOffset() {{non-standard_inline}} unsigned long long Indicates the current offset of the audio stream that was created by a call to mozWriteAudio(). This offset is specified as the number of samples since the beginning of the stream.

mozSetup(in PRUint32 channels, in PRUint32 rate) {{non-standard_inline}}

void Sets up the audio stream for writing. You specify as parameters the number of channels (1 for mono or 2 for stereo), then the sampling rate (44100 for 44.1kHz, for example).
mozWriteAudio(in jsval data) {{non-standard_inline}} unsigned long Writes audio into the stream at the current offset. Returns the number of bytes actually written to the stream.

Specifications

Specification Status Comment
{{SpecName('HTML WHATWG', "the-video-element.html#the-audio-element", "HTMLAudioElement")}} {{Spec2('HTML WHATWG')}} No change from {{SpecName('HTML5 W3C')}}
{{SpecName('HTML5 W3C', "embedded-content-0.html#the-audio-element", "HTMLAudioElement")}} {{Spec2('HTML5 W3C')}} Initial definition.

Browser compatibility

{{CompatibilityTable}}

Feature Chrome Firefox (Gecko) Internet Explorer Opera Safari (WebKit)
Basic support {{CompatVersionUnknown}} {{CompatGeckoDesktop(1.9.1)}} {{CompatVersionUnknown}} {{CompatVersionUnknown}} {{CompatVersionUnknown}}
mozSetup(), mozCurrentSampleOffset(), mozWriteAudio() {{non-standard_inline}} {{CompatNo}} {{CompatGeckoDesktop(2.0)}} {{CompatNo}} {{CompatNo}} {{CompatNo}}
Feature Android Firefox Mobile (Gecko) IE Phone Opera Mobile Safari Mobile
Basic support {{CompatVersionUnknown}} {{CompatGeckoMobile(1.9.1)}} {{CompatVersionUnknown}} {{CompatVersionUnknown}} {{CompatVersionUnknown}}
mozSetup(), mozCurrentSampleOffset(), mozWriteAudio() {{non-standard_inline}} {{CompatNo}} {{CompatGeckoMobile(2.0)}} {{CompatNo}} {{CompatNo}} {{CompatNo}}

See also

  • HTML element implementing this interface: {{HTMLElement("audio")}}.

Revision Source

<div>
<div>{{APIRef("HTML DOM")}}</div>
</div>

<div>&nbsp;</div>

<p>The <strong><code>HTMLAudioElement</code></strong> interface provides access to the properties of {{HTMLElement("audio")}} elements, as well as methods to manipulate them. It derives from the {{domxref("HTMLMediaElement")}} interface.</p>

<h2 id="Properties" name="Properties">Properties</h2>

<p><em>No specific property; inherits properties from its parent, {{domxref("HTMLMediaElement")}}, and from {{domxref("HTMLElement")}}.</em></p>

<h2 id="Methods" name="Methods">Methods</h2>

<p><em>Inherits methods from its parent, {{domxref("HTMLMediaElement")}}, and from {{domxref("HTMLElement")}}.</em></p>

<h3 id="Constructor">Constructor</h3>

<h4 id="Syntax">Syntax</h4>

<pre class="syntaxbox">
mySound = new Audio([<em>URLString</em>]);
</pre>

<h4 id="Description">Description</h4>

<p>Constructor for audio elements. The <code>preload</code> property of the returned object is set to <code>auto</code> and the <code>src</code> property is set to the argument value. The browser begins <em>asynchronously</em> selecting the resource before returning the object.</p>

<p><em>Note: A</em><em>n Audio&nbsp;element constructed with <code>new Audio()</code>&nbsp;won't be garbage collected so long as playback is in progress. It will continue playing and be audible until&nbsp;<code>stop()</code>&nbsp;is&nbsp;called or playback finishes.</em></p>

<h4 id="Parameters">Parameters</h4>

<dl>
 <dt><code>URLString</code> (expected type: {{domxref("DOMString")}}; optional)</dt>
 <dd>The <code>src</code> property of the constructed <code>HTMLAudioElement</code>.</dd>
</dl>

<h3 id="Regular_methods">Regular methods</h3>

<table class="standard-table">
 <tbody>
  <tr>
   <th scope="col">Name &amp; Arguments</th>
   <th scope="col">Return</th>
   <th scope="col">Description</th>
  </tr>
  <tr>
   <td><code>mozCurrentSampleOffset()</code> {{non-standard_inline}}</td>
   <td><code>unsigned long long</code></td>
   <td>Indicates the current offset of the audio stream that was created by a call to <code>mozWriteAudio()</code>. This offset is specified as the number of samples since the beginning of the stream.</td>
  </tr>
  <tr>
   <td>
    <p><code>mozSetup(in PRUint32 channels, in PRUint32 rate)</code> {{non-standard_inline}}</p>
   </td>
   <td><code>void</code></td>
   <td>Sets up the audio stream for writing. You specify as parameters the number of channels (<code>1</code> for mono or <code>2</code> for stereo), then the sampling rate (<code>44100</code> for 44.1kHz, for example).</td>
  </tr>
  <tr>
   <td><code>mozWriteAudio(in jsval data) </code>{{non-standard_inline}}</td>
   <td><code>unsigned long</code></td>
   <td>Writes audio into the stream at the current offset. Returns the number of bytes actually written to the stream.</td>
  </tr>
 </tbody>
</table>

<h2 id="Specifications">Specifications</h2>

<table class="standard-table">
 <tbody>
  <tr>
   <th scope="col">Specification</th>
   <th scope="col">Status</th>
   <th scope="col">Comment</th>
  </tr>
  <tr>
   <td>{{SpecName('HTML WHATWG', "the-video-element.html#the-audio-element", "HTMLAudioElement")}}</td>
   <td>{{Spec2('HTML WHATWG')}}</td>
   <td>No change from {{SpecName('HTML5 W3C')}}</td>
  </tr>
  <tr>
   <td>{{SpecName('HTML5 W3C', "embedded-content-0.html#the-audio-element", "HTMLAudioElement")}}</td>
   <td>{{Spec2('HTML5 W3C')}}</td>
   <td>Initial definition.</td>
  </tr>
 </tbody>
</table>

<h2 id="Browser_compatibility">Browser compatibility</h2>

<p>{{CompatibilityTable}}</p>

<div id="compat-desktop">
<table class="compat-table">
 <tbody>
  <tr>
   <th>Feature</th>
   <th>Chrome</th>
   <th>Firefox (Gecko)</th>
   <th>Internet Explorer</th>
   <th>Opera</th>
   <th>Safari (WebKit)</th>
  </tr>
  <tr>
   <td>Basic support</td>
   <td>{{CompatVersionUnknown}}</td>
   <td>{{CompatGeckoDesktop(1.9.1)}}</td>
   <td>{{CompatVersionUnknown}}</td>
   <td>{{CompatVersionUnknown}}</td>
   <td>{{CompatVersionUnknown}}</td>
  </tr>
  <tr>
   <td><code>mozSetup()</code>, <code>mozCurrentSampleOffset()</code>, <code>mozWriteAudio()</code> {{non-standard_inline}}</td>
   <td>{{CompatNo}}</td>
   <td>{{CompatGeckoDesktop(2.0)}}</td>
   <td>{{CompatNo}}</td>
   <td>{{CompatNo}}</td>
   <td>{{CompatNo}}</td>
  </tr>
 </tbody>
</table>
</div>

<div id="compat-mobile">
<table class="compat-table">
 <tbody>
  <tr>
   <th>Feature</th>
   <th>Android</th>
   <th>Firefox Mobile (Gecko)</th>
   <th>IE Phone</th>
   <th>Opera Mobile</th>
   <th>Safari Mobile</th>
  </tr>
  <tr>
   <td>Basic support</td>
   <td>{{CompatVersionUnknown}}</td>
   <td>{{CompatGeckoMobile(1.9.1)}}</td>
   <td>{{CompatVersionUnknown}}</td>
   <td>{{CompatVersionUnknown}}</td>
   <td>{{CompatVersionUnknown}}</td>
  </tr>
  <tr>
   <td><code>mozSetup()</code>, <code>mozCurrentSampleOffset()</code>, <code>mozWriteAudio()</code> {{non-standard_inline}}</td>
   <td>{{CompatNo}}</td>
   <td>{{CompatGeckoMobile(2.0)}}</td>
   <td>{{CompatNo}}</td>
   <td>{{CompatNo}}</td>
   <td>{{CompatNo}}</td>
  </tr>
 </tbody>
</table>
</div>

<h2 id="See_also">See also</h2>

<ul>
 <li>HTML element implementing this interface: {{HTMLElement("audio")}}.</li>
</ul>
Revert to this revision