TV Manager API enables the development of web-based applications to acquire the information from service providers as well as to manage the native TV hardwares (i.e. tuners).
The TV Manager API is aimed to cover the following use cases:
If an application has the privilege to use the TV Manager API, it can use a bunch of basic methods defined in the TVManager to manage the TV device.
The following example shows how to get all the available TV tuners on the TV device, and how to set the current source and listen to events for source changes.
// Retrieve all the available TV tuners. navigator.tv.getTuners().then(function onsuccess(tuners) { // Just use the first TV tuner. var tuner = tuners[0]; // Set the 'oncurrentsourcechanged' event handler. tuner.oncurrentsourcechanged = function oncurrentsourcechanged(event) { alert("The current TV source has changed."); }; // Get the supported TV source types for the TV tuner. var sourceTypes = tuner.getSupportedSourceTypes(); // Just use the first TV source type. tuner.setCurrentSource(sourceTypes[0]).then(function onsuccess() { alert("Succeeded to set the TV source."); }, function onerror(error) { alert(error); }); }, function onerror(error) { alert(error); });
The following example shows how to scan and get all the available TV channels from a configured TV source of the TV tuner.
// Assuming a tuner has already been picked and its current source is // set, variable |currentSource| is used for following illustration. if (currentSource.isScanning) { return; } // Set the 'onscanningstatechanged' event handler. currentSource.onscanningstatechanged = function onscanningstatechanged(event) { var state = event.state; switch (state) { case "cleared": alert("All the TV channels are cleared for rescanning."); break; case "scanned": alert("A new TV channel is scanned: " + event.channel.name); break; case "completed": alert("The scanning process is completed."); // Retrieve all the available TV channels from the configured // TV source of the TV tuner. currentSource.getChannels().then(function onsuccess(channels) { alert("Succeeded to scan and get all the TV channels."); }, function onerror(error) { alert(error); }); break; case "stopped": alert("The scanning process is stopped."); break; default: break; } }; // Ask the configured TV source to scan TV channels. currentSource.startScanning({ isRescanned: true }).then(function onsuccess() { alert("The scanning process starts."); }, function onerror(error) { alert(error); });
The following example shows how to get all the available TV programs from the TV channel.
// Assuming a tuner has already been picked and its current source is // set, variable |currentSource| is used for following illustration. // Set the 'oneitbroadcasted' event handler. currentSource.oneitbroadcasted = function oneitbroadcasted(event) { var newPrograms = event.programs; // Add or update correspondent programs in |curProgramsOfChannels| // based on their |eventId|. }; // Retrieve all the available TV channels from the configured TV // source of the TV tuner. currentSource.getChannels().then(function onsuccess(channels) { channels.forEach(function getProgramsByChannel(channel) { var channelNumber = channel.number; // Retrieve all the available TV programs from the TV channel. channel.getPrograms().then(function onsuccess(programs) { curProgramsOfChannels[channelNumber] = programs; }, function onerror(error) { alert(error); }); }); }, function onerror(error) { alert(error); });
The following example shows how to play the streaming data of a TV
tuner by assigning the MediaStream
to a
HTMLMediaElement
.
<!DOCTYPE html> <html> <head> <script> // Retrieve all the currently available TV tuners first. navigator.tv.getTuners().then(function onsuccess(tuners) { if (tuners.length == 0) { return; } // Just use the first TV tuner. var tuner = tuners[0]; var video = document.getElementById("video-player"); video.srcObject = tuner.stream; }, function onerror(error) { alert(error); }); </script> </head> <body> <p><video id="video-player" autoplay></video></p> </body> </html>
The following example shows how to switch the TV channel with the channel number, and listen to events for channel changes.
// Assuming a tuner has already been picked and its current source is // set, variable |currentSource| is used for following illustration. // Retrieve all the available TV channels from the configured TV // source of the TV tuner. currentSource.getChannels().then(function onsuccess(channels) { if (channels.length == 0) { return; } // Just use the first TV channel. var channel = channels[0]; var channelNumber = channel.number; currentSource.oncurrentchannelchanged = function oncurrentchannelchanged(event) { alert("The current channel has changed."); }; // Switch the TV channel based on the TV channel number. currentSource.setCurrentChannel(channelNumber).then(function onsuccess() { alert("Succeeded to switch the TV channel."); }, function onerror(error) { alert(error); }); }, function onerror(error) { alert(error); });
This specification defines conformance criteria that apply to a single product: the user agent that implements the interfaces that it contains.
Implementations that use ECMAScript to implement the APIs defined in this specification MUST implement them in a manner consistent with the ECMAScript Bindings defined in the Web IDL specification [[!WEBIDL]], as this specification uses that specification and terminology.
The EventHandler interface represents a callback used for event handlers as defined in [[!HTML5]].
The concepts queue a task and fire an event are defined in [[!HTML5]].
The terms event handler and event handler event types are defined in [[!HTML5]].
The Promise interface, the concepts of a resolver, a resolver's fulfill algorithm and a resolver's reject algorithm are defined in [[ECMAScript]].
The MediaStream interface is defined in [[MediaCapture-Streams]].
The MediaRecorder interface is defined in [[MediaStream-Recording]].
The video and HTMLMediaElement elements are defined in [[!HTML5]].
The TVManager interface represents a bunch of properties and a set of operations that can be used to manage the TV device.
Promise
that will be used to notify the caller about the result of the
operation, which is an array of TVTuner elements.
The getTuners
method when invoked MUST run
the following steps:
Promise
object and
resolver be its associated resolver
.
value
argument.
value
argument.
The TVTuner interface represents a bunch of properties and a set of operations related to the TV tuner.
Promise
that will be used to notify the caller about the result of the
operation, which is an array of TVSource elements that belong
to the TV tuner.
sourceType
parameter. It returns a
new Promise
that will be used to notify the caller
about the result of the operation.
MediaStream
object that is
currently streamed by the TV tuner, which can be played by the
video
element by
assigning
the MediaStream
to the
HTMLMediaElement
and can be recorded by the
MediaRecorder
.
MUST return null if the TV tuner is not streaming any data,
which happens when the streaming signal is broken or due to any
other reasons that the TV tuner fails to stream the data.
oncurrentsourcechanged
event of type
TVCurrentSourceChangedEvent, fired when the method
setCurrentSource
is invoked to configure the
current TV source.
The getSources
method when invoked MUST run
the following steps:
Promise
object and
resolver be its associated resolver
.
value
argument.
value
argument.
The setCurrentSource
method when invoked MUST
run the following steps:
Promise
object and
resolver be its associated resolver
.
sourceType
parameter.
value
argument.
value
argument.
The following are the event handlers (and their corresponding event types) that MUST be supported as attributes by the TVTuner object.
Event handler | Event name | Event type | Short description |
---|---|---|---|
oncurrentsourcechanged |
currentsourcechanged |
TVCurrentSourceChangedEvent |
Handles the information of the current TV source that is
configured by the method setCurrentSource .
|
The TVSource interface represents a bunch of properties and a set of operations related to the TV source.
Promise
that will be used to notify the caller about the result of the
operation, which is an array of TVChannel elements that
belong to the TV source. Note that the Promise
may be
rejected with an InvalidStateError
if this method gets
called during channel scanning.
channelNumber
parameter. It returns a
new Promise
that will be used to notify the caller
about the result of the operation. Note that the Promise
may be rejected with an InvalidStateError
if this
method gets called during channel scanning.
options
parameter. It returns a new Promise
that will be used
to notify the caller about the result of the operation. Note that
this method has to be called first so that the method
getChannels
can retrieve the channels that have
successfully been scanned by the TV source.
isRescanned
option in the options
parameter specifies whether or not the process of scanning the
TV channels has to clear the currently scanned TV channels
before scanning; if it is not passed, this method will rescan
all the TV channels as if it is passed as true
.
Promise
that will be used
to notify the caller about the result of the operation.
oncurrentchannelchanged
event of type
TVCurrentChannelChangedEvent, fired when the method
setCurrentChannel
is invoked to tune the
currently streamed TV channel.
oneitbroadcasted
event of type
TVEITBroadcastedEvent, fired when the Event Information Table
(EIT) is broadcasted by the TV source.
onscanningstatechanged
event of type
TVScanningStateChangedEvent, fired when the state of scanning
the TV channels is changed by the TV source. E.g., it can be fired
when the method startScanning
or the method
stopScanning
starts or stops scanning the TV
channels.
The getChannels
method when invoked MUST run
the following steps:
Promise
object and
resolver be its associated resolver
.
value
argument.
value
argument.
The setCurrentChannel
method when invoked MUST
run the following steps:
Promise
object and
resolver be its associated resolver
.
channelNumber
parameter.
value
argument.
value
argument.
The startScanning
method when invoked MUST
run the following steps:
Promise
object and
resolver be its associated resolver
.
options
parameter. If
the isRescanned
option in the options
parameter is not passed or it is passed as true
, the
user agent has to
clear the currently scanned TV channels before scanning; if it is
passed as false
, the
user agent will
simply scan additional TV channels which haven't been scanned yet.
value
argument.
value
argument.
The stopScanning
method when invoked MUST run
the following steps:
Promise
object and
resolver be its associated resolver
.
value
argument.
value
argument.
The following are the event handlers (and their corresponding event types) that MUST be supported as attributes by the TVSource object.
Event handler | Event name | Event type | Short description |
---|---|---|---|
oncurrentchannelchanged |
currentchannelchanged |
TVCurrentChannelChangedEvent |
Handles the information of the currently streamed TV channel
that is tuned by the method
setCurrentChannel .
|
oneitbroadcasted |
eitbroadcasted |
TVEITBroadcastedEvent |
Handles the information of the available TV programs in the EIT that is broadcasted by the TV source. |
onscanningstatechanged |
scanningstatechanged |
TVScanningStateChangedEvent |
Handles the information of the state of scanning the TV channels, which is changed by the TV source. |
The TVChannel interface represents a bunch of properties and a set of operations related to the TV channel.
options
parameter.
It returns a new Promise
that will be used to notify
the caller about the result of the operation, which is an array of
TVProgram elements that belong to the TV channel.
Promise
that will be used to notify the caller about the result of the
operation, which is a TVProgram element that belongs to the
TV channel.
networkId
corresponds to an operator. On cable and terrestrial, where
different radio frequencies might be used in different regions,
operators typically use one networkId
per such region.
"CNN"
,
"NHK"
... etc.
"12-1"
, "12-2"
,
"12-2"
... etc.
The getPrograms
method when invoked
MUST run the following steps:
Promise
object and
resolver be its associated resolver
.
options
parameter.
value
argument.
value
argument.
The getCurrentProgram
method when invoked
MUST run the following steps:
Promise
object and
resolver be its associated resolver
.
value
argument.
value
argument.
The TVProgram interface represents a bunch of properties and a set of operations related to the TV program.
The TVStartScanningOptions dictionary contains the information for scanning the TV channels.
The TVGetProgramsOptions dictionary contains the information for retrieving the TV programs.
The TVCurrentSourceChangedEvent interface represents the event
related to the current TV source that is configured by the method
setCurrentSource
.
The TVEITBroadcastedEvent interface represents the event related to the available TV programs in the EIT that is broadcasted by the TV source.
TVProgram
instances. The cached value for this array
needs to go into an internal slot for the object, and it should be
cached there until the next time that the underlying array changes
when the cached value will be updated.
The TVScanningStateChangedEvent interface represents the event related to the state of scanning the TV channels, which is changed by the TV source.
state
is not specified as
"scanned"
.
The TVCurrentChannelChangedEvent interface represents the event
related to the currently streamed TV channel that is tuned by the method
setCurrentChannel
.
The attribute type
in the TVSource can have the
following values:
The attribute type
in a TVChannel can have the
following values:
The attribute state
in the
TVScanningStateChangedEvent can have the following values:
To be constructed.