---
title: FMRadio
slug: Web/API/FMRadio
translation_of: Archive/B2G_OS/API/FMRadio
---
{{ APIRef("FMRadio API")}}{{ non-standard_header() }}
{{ B2GOnlyHeader2('installed') }}
Summary
WebFM API предоставляет доступ к модулю FM радио устройства. Этот интерфейс поможет Вам включить или выключить FM радио и настроить его на нужную станцию. Это достижимо с помощью параметра {{domxref("window.navigator.mozFMRadio","navigator.mozFMRadio")}}.
Обзор API
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();
}
Параметры
- {{domxref("FMRadio.enabled")}}
- Показывает играет ли радио
- {{domxref("FMRadio.antennaAvailable")}}
- Показывает доступна ли антенна
- {{domxref("FMRadio.frequency")}}
- Текущая частота радио.
- {{domxref("FMRadio.frequencyUpperBound")}}
- Максимальная частота по которой можно найти радиостанцию
- {{domxref("FMRadio.frequencyLowerBound")}}
- Минимальная частота по которой можно найти радиостанцию
- {{domxref("FMRadio.channelWidth")}}
- Частота текущей радиостанции, в МГц.
Event handlers
- {{domxref("FMRadio.onenabled")}}
- A handler for the {{event("enabled")}} event; It is triggered when the radio has been turned on
- {{domxref("FMRadio.ondisabled")}}
- A handler for the {{event("disabled")}} event; It is triggered when the radio has been turned off
- {{domxref("FMRadio.onantennaavailablechange")}}
- A handler for the {{event("antennaavailablechange")}} event; It is triggered when an antenna is plugged or unplugged
- {{domxref("FMRadio.onfrequencychange")}}
- A handler for the {{event("frequencychange")}} event; It is triggered whenever the radio frequency is changed
Методы
- {{domxref("FMRadio.enable()")}}
- Turns on the radio on the given frequency. This function throws if called with no argument. Returns a {{domxref("DOMRequest")}} for the success or error of the operation.
- {{domxref("FMRadio.disable()")}}
- Turns the radio off. Returns a {{domxref("DOMRequest")}} which success indicates that the radio has properly been disabled
- {{domxref("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 {{domxref("DOMRequest")}} which success indicates the frequency has properly been changed.
- {{domxref("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 {{domxref("DOMRequest")}} which success indicates that the search has started. The search circles back to lower frequencies when the highest frequency has been reached.
- {{domxref("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.
- {{domxref("FMRadio.cancelSeek()")}}
- Cancels the radio seek if one was happening. Returns a {{domxref("DOMRequest")}} which success indicates that the frequency search has been cancelled.
Спецификация
Ещё нет спецификаций.
See also