We're looking for a user researcher to understand the needs of developers and designers. Is this you or someone you know? Check out the post: https://mzl.la/2IGzdXS

B2G OS

AudioChannelManager.onheadphoneschange

The onheadphoneschange event handler of the AudioChannelManager interface fires when the device's headphones are plugged in or unplugged.

Syntax

navigator.mozAudioChannelManager.onheadphoneschange = function() { ... };

Example

In the following simple example, we use the navigator.mozAudioChannelManager property to access the app's AudioChannelManager object, first to do some rudimentary feature detection, and then to create an anonymous function that runs when the onheadphoneschange event handler fires. In this function, we test to see if AudioChannelManager.headphones returns true, then give the user a notification to tell them the result.

if (navigator.mozAudioChannelManager) {
  navigator.mozAudioChannelManager.onheadphoneschange = function() {
    if(navigator.mozAudioChannelManager.headphones == true) {
      var notification = new Notification('Headphones plugged in!');
    } else {
      var notification = new Notification('Headphones unplugged!');
    }
  }
}

Note: For a complete working example, see our audio-channels-demo. Try running this on your Firefox OS device as an installed app (install it using App Manager/WebIDE) and then see what happens when you play the music and then put the app in the background, with the channel set to normal, then content. You should also try plugging in and unplugging some headphones.

Specifications

The AudioChannels API has no official spec at the moment; see https://wiki.mozilla.org/WebAPI/AudioChannels for implementation details, WebIDL, etc.

Browser compatibility

Supported in Firefox OS 1.0.1.

See also

Document Tags and Contributors

Contributors to this page: fscholz, chrisdavidmills
Last updated by: fscholz,