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 1132579 of MediaDevices.ondevicechange

  • Revision slug: Web/API/MediaDevices/ondevicechange
  • Revision title: MediaDevices.ondevicechange
  • Revision id: 1132579
  • Created:
  • Creator: Sheppy
  • Is current revision? No
  • Comment Ha! The example was copy/paste leftovers. Removed for now; I'll add a useful sample tomorrow.

Revision Content

{{APIRef("Media Capture and Streams")}}

The MediaDevices.ondevicechange property is an {{domxref("EventHandler")}} which specifies a function to be called when the {{event("devicechange")}} event occurs on a {{domxref("MediaDevices")}} instance. This happens whenever the set of media devices available to the {{Glossary("user agent")}} and, by extension, to the web site or app. You can at any time use {{domxref("MediaDevices.enumerateDevices", "enumerateDevices()")}} to get the updated list of available devices.

Syntax

MediaDevices.ondevicechange = eventHandler;

Value

A function you provide which accepts as input a {{domxref("Event")}} object describing the {{domxref("devicehange")}} event that occurred. There is no information about the change included in the event object; to get the updated list of devices, you'll have to use {{domxref("MediaDevices.enumerateDevices", "enumerateDevices()")}}.

Example

tbd

Specifications

Specification Status Comment
{{ SpecName('Media Capture', '#event-mediastream-devicechange', 'devicechange') }} {{ Spec2('Media Capture') }} Initial specification.

Browser compatibility

{{CompatibilityTable}}
Feature Chrome Firefox (Gecko) Internet Explorer Opera Safari (WebKit)
Basic support {{CompatVersionUnknown}} {{CompatGeckoDesktop(51)}} {{CompatUnknown}} {{CompatUnknown}} {{CompatUnknown}}
Feature Android Android Webview Firefox Mobile (Gecko) IE Phone Opera Mobile Safari Mobile Chrome for Android
Basic support {{CompatUnknown}} {{CompatUnknown}} {{CompatUnknown}} {{CompatNo}} {{CompatUnknown}} {{CompatUnknown}} {{CompatVersionUnknown}}

[1] While support for the devicechange event and for {{domxref("MediaDevices.ondevicechange")}} landed in Firefox 51, but only for Mac, and disabled by default. It can be enabled by setting the preference media.ondevicechange.enabled to true. Support for this event was added for Linux and Windows—and it was enabled by default—starting in Firefox 52.

See also

  • The {{event("devicechange")}} event and its type, {{domxref("Event")}}.
  • {{domxref("MediaDevices.enumerateDevices()")}}
  • {{domxref("MediaDeviceInfo")}}

Revision Source

<p>{{APIRef("Media Capture and Streams")}}</p>

<p><span class="seoSummary">The <strong><code>MediaDevices.ondevicechange</code></strong> property is an {{domxref("EventHandler")}} which specifies a function to be called when the {{event("devicechange")}} event occurs on a {{domxref("MediaDevices")}} instance. This happens whenever the set of media devices available to the {{Glossary("user agent")}} and, by extension, to the web site or app. You can at any time use {{domxref("MediaDevices.enumerateDevices", "enumerateDevices()")}} to get the updated list of available devices.</span></p>

<h2 id="Syntax">Syntax</h2>

<pre class="syntaxbox">
<em>MediaDevices</em>.ondevicechange = <em>eventHandler</em>;
</pre>

<h3 id="Value">Value</h3>

<p>A function you provide which accepts as input a {{domxref("Event")}} object describing the {{domxref("devicehange")}} event that occurred. There is no information about the change included in the event object; to get the updated list of devices, you'll have to use {{domxref("MediaDevices.enumerateDevices", "enumerateDevices()")}}.</p>

<h2 id="Example">Example</h2>

<p>tbd</p>

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

<table class="standard-table">
 <thead>
  <tr>
   <th scope="col">Specification</th>
   <th scope="col">Status</th>
   <th scope="col">Comment</th>
  </tr>
 </thead>
 <tbody>
  <tr>
   <td>{{ SpecName('Media Capture', '#event-mediastream-devicechange', 'devicechange') }}</td>
   <td>{{ Spec2('Media Capture') }}</td>
   <td>Initial specification.</td>
  </tr>
 </tbody>
</table>

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

<div>{{CompatibilityTable}}</div>

<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(51)}}</td>
   <td>{{CompatUnknown}}</td>
   <td>{{CompatUnknown}}</td>
   <td>{{CompatUnknown}}</td>
  </tr>
 </tbody>
</table>
</div>

<div id="compat-mobile">
<table class="compat-table">
 <tbody>
  <tr>
   <th>Feature</th>
   <th>Android</th>
   <th>Android Webview</th>
   <th>Firefox Mobile (Gecko)</th>
   <th>IE Phone</th>
   <th>Opera Mobile</th>
   <th>Safari Mobile</th>
   <th>Chrome for Android</th>
  </tr>
  <tr>
   <td>Basic support</td>
   <td>{{CompatUnknown}}</td>
   <td>{{CompatUnknown}}</td>
   <td>{{CompatUnknown}}</td>
   <td>{{CompatNo}}</td>
   <td>{{CompatUnknown}}</td>
   <td>{{CompatUnknown}}</td>
   <td>{{CompatVersionUnknown}}</td>
  </tr>
 </tbody>
</table>
</div>

<p>[1] While support for the <code>devicechange</code> event and for {{domxref("MediaDevices.ondevicechange")}} landed in Firefox 51, but <em>only for Mac</em>, and disabled by default. It can be enabled by setting the preference <code>media.ondevicechange.enabled</code> to true. Support for this event was added for Linux and Windows—and it was enabled by default—starting in Firefox 52.</p>

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

<ul>
 <li>The {{event("devicechange")}} event and its type, {{domxref("Event")}}.</li>
 <li>{{domxref("MediaDevices.enumerateDevices()")}}</li>
 <li>{{domxref("MediaDeviceInfo")}}</li>
</ul>
Revert to this revision