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.

This API is available on Firefox or Firefox OS for installed or higher privileged applications.

Summary

The WebFM API provides access to the device FM radio. This interface lets you turn the FM radio on and off and tune it to different stations. It is accessible through the navigator.mozFMRadio property.

API Overview

interface FMRadio : EventTarget {
   readonly attribute boolean enabled;
   readonly attribute boolean antennaAvailable;
   readonly attribute double frequency;
   readonly attribute double frequencyUpperBound;
   readonly attribute double frequencyLowerBound;
   readonly attribute double channelWidth;

   attribute Function onantennaavailablechange;
   attribute Function onfrequencychange;
   attribute Function onenabled;
   attribute Function ondisabled;

   DOMRequest enable(double frequency);
   DOMRequest disable();
   DOMRequest setFrequency(double frequency);
   DOMRequest seekUp();
   DOMRequest seekDown();
   DOMRequest cancelSeek();
}

Properties

FMRadio.enabled
Indicates whether the radio is playing
FMRadio.antennaAvailable
Indicate if an antenna is plugged and available
FMRadio.frequency
Current radio frequency.
FMRadio.frequencyUpperBound
Maximum frequency up to which the seek method searches for radio stations
FMRadio.frequencyLowerBound
Minimum frequency down to which the seek method searches for radio stations
FMRadio.channelWidth
The channel width of the ranges of frequency, in MHz.

Event handlers

FMRadio.onenabled
A handler for the enabled event; It is triggered when the radio has been turned on
FMRadio.ondisabled
A handler for the disabled event; It is triggered when the radio has been turned off
FMRadio.onantennaavailablechange
A handler for the antennaavailablechange event; It is triggered when an antenna is plugged or unplugged
FMRadio.onfrequencychange
A handler for the frequencychange event; It is triggered whenever the radio frequency is changed

Methods

FMRadio.enable()
Turns on the radio on the given frequency. This function throws if called with no argument. Returns a DOMRequest for the success or error of the operation.
FMRadio.disable()
Turns the radio off. Returns a DOMRequest which success indicates that the radio has properly been disabled
FMRadio.setFrequency()
Asynchronously changes the radio frequency. The value has to be between frequencyLowerBound and frequencyUpperBound. Trying to set outside the bounds results in an error.
Returns a DOMRequest which success indicates the frequency has properly been changed.
FMRadio.seekUp()
Asks the radio to find a new frequency (usually greater than the current one). If one is successfully found, a frequencychange event is fired. Returns a DOMRequest which success indicates that the search has started. The search circles back to lower frequencies when the highest frequency has been reached.
FMRadio.seekDown()
Same as above, but searching in frequencies lower than the current one. The search cirlces back to higher frequencies when the lowest frequency has been reached.
FMRadio.cancelSeek()
Cancels the radio seek if one was happening. Returns a DOMRequest which success indicates that the frequency search has been cancelled.

Specification

Not part of any specification.

See also

Document Tags and Contributors

 Last updated by: chrisdavidmills,