The TV Manager API allows an application to manage the TV device.

Introduction

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).

Use Cases

The TV Manager API is aimed to cover the following use cases:

Interfaces UML diagram

TV Manager API interfaces UML diagram

Examples

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.

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]].

Navigator Interface

readonly attribute TVManager tv
MUST return the object that exposes the interface to the TV service.

TVManager Interface

The TVManager interface represents a bunch of properties and a set of operations that can be used to manage the TV device.

Promise getTuners ()
This method makes a request to retrieve all the TV tuners that are available in the TV device. It returns a new Promise that will be used to notify the caller about the result of the operation, which is an array of TVTuner elements.

Steps

The getTuners method when invoked MUST run the following steps:

  1. Let promise be a new Promise object and resolver be its associated resolver.
  2. Return promise to the caller.
  3. Make a request to the TV device to retrieve all the TV tuners that are available in the TV device.
  4. If an error occurs invoke resolver's reject algorithm with error as the value argument.
  5. When the request has been successfully completed:
    1. Let tuners be the array of the retrieved TVTuner elements.
    2. Invoke resolver's fulfill algorithm with tuners as the value argument.

TVTuner Interface

The TVTuner interface represents a bunch of properties and a set of operations related to the TV tuner.

sequence<TVSourceType> getSupportedSourceTypes ()
MUST return the types of the supported TV sources.
Promise getSources ()
This method makes a request to retrieve all the TV sources that are available in the TV tuner. It returns a new 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.
Promise setCurrentSource ()
This method makes a request to configure the current TV source of the TV tuner by the sourceType parameter. It returns a new Promise that will be used to notify the caller about the result of the operation.
TVSourceType sourceType
Specifies the TV source type for configuring the current TV source.
readonly attribute DOMString id
MUST return the ID of the TV tuner.
readonly attribute TVSource? currentSource
MUST return the currently configured TV source. MUST return null if the TV source is not configured.
readonly attribute MediaStream? stream
MUST return a 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.
attribute EventHandler oncurrentsourcechanged
Handles the oncurrentsourcechanged event of type TVCurrentSourceChangedEvent, fired when the method setCurrentSource is invoked to configure the current TV source.

Steps

The getSources method when invoked MUST run the following steps:

  1. Let promise be a new Promise object and resolver be its associated resolver.
  2. Return promise to the caller.
  3. Make a request to the TV tuner to retrieve all the TV sources that are available in the TV tuner.
  4. If an error occurs invoke resolver's reject algorithm with error as the value argument.
  5. When the request has been successfully completed:
    1. Let sources be the array of the retrieved TVSource elements.
    2. Invoke resolver's fulfill algorithm with channels as the value argument.

The setCurrentSource method when invoked MUST run the following steps:

  1. Let promise be a new Promise object and resolver be its associated resolver.
  2. Return promise to the caller.
  3. Make a request to the TV tuner to configure the current TV source according to the sourceType parameter.
  4. If an error occurs invoke resolver's reject algorithm with error as the value argument.
  5. When the request has been successfully completed:
    1. Invoke resolver's fulfill algorithm without assigning a value to the value argument.

Event handlers

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.

TVSource Interface

The TVSource interface represents a bunch of properties and a set of operations related to the TV source.

Promise getChannels ()
This method makes a request to retrieve all the TV channels that are available in the TV source. It returns a new 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.
Promise setCurrentChannel ()
This method makes a request to tune the currently streamed TV channel by the 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.
DOMString channelNumber
Specifies the TV channel number for tuning the currently streamed TV channel.
Promise startScanning ()
This method makes a request to start scanning all the TV channels that are available in the TV source by the 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.
optional TVStartScanningOptions options
Specifies the options for scanning the TV channels. The 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 stopScanning ()
This method makes a request to stop scanning the TV channels for the TV source. It returns a new Promise that will be used to notify the caller about the result of the operation.
readonly attribute TVTuner tuner
MUST return the TV tuner which the TV source belongs to.
readonly attribute TVSourceType type
MUST return the type of the TV source.
readonly attribute boolean isScanning
MUST indicate whether the TV source is scanning the TV channels or not.
readonly attribute TVChannel? currentChannel
MUST return the TV channel that is currently streamed by the TV tuner which owns the TV source. MUST return null if the TV tuner is not streaming any data.
attribute EventHandler oncurrentchannelchanged
Handles the oncurrentchannelchanged event of type TVCurrentChannelChangedEvent, fired when the method setCurrentChannel is invoked to tune the currently streamed TV channel.
attribute EventHandler oneitbroadcasted
Handles the oneitbroadcasted event of type TVEITBroadcastedEvent, fired when the Event Information Table (EIT) is broadcasted by the TV source.
attribute EventHandler onscanningstatechanged
Handles the 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.

Steps

The getChannels method when invoked MUST run the following steps:

  1. Let promise be a new Promise object and resolver be its associated resolver.
  2. Return promise to the caller.
  3. Make a request to the TV source to retrieve all the TV channels that are available in the TV source.
  4. If an error occurs invoke resolver's reject algorithm with error as the value argument.
  5. When the request has been successfully completed:
    1. Let channels be the array of the retrieved TVChannel elements.
    2. Invoke resolver's fulfill algorithm with channels as the value argument.

The setCurrentChannel method when invoked MUST run the following steps:

  1. Let promise be a new Promise object and resolver be its associated resolver.
  2. Return promise to the caller.
  3. Make a request to the TV source to tune the currently streamed TV channel according to the channelNumber parameter.
  4. If an error occurs invoke resolver's reject algorithm with error as the value argument.
  5. When the request has been successfully completed:
    1. Invoke resolver's fulfill algorithm without assigning a value to the value argument.

The startScanning method when invoked MUST run the following steps:

  1. Let promise be a new Promise object and resolver be its associated resolver.
  2. Return promise to the caller.
  3. Make a request to the TV source to start scanning all the TV channels that are available in the TV source according to the scanning options specified in the 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.
  4. If an error occurs invoke resolver's reject algorithm with error as the value argument.
  5. When the request has been successfully completed:
    1. Invoke resolver's fulfill algorithm without assigning a value to the value argument.

The stopScanning method when invoked MUST run the following steps:

  1. Let promise be a new Promise object and resolver be its associated resolver.
  2. Return promise to the caller.
  3. Make a request to the TV source to stop scanning the TV channels.
  4. If an error occurs invoke resolver's reject algorithm with error as the value argument.
  5. When the request has been successfully completed:
    1. Invoke resolver's fulfill algorithm without assigning a value to the value argument.

Event handlers

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.

TVChannel Interface

The TVChannel interface represents a bunch of properties and a set of operations related to the TV channel.

Promise getPrograms ()
This method makes a request to retrieve all the TV programs that are available in the TV channel by the 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.
optional TVGetProgramsOptions options
Specifies the options for retrieving the TV programs. If this parameter is not passed, this method will return all the available TV programs.
Promise getCurrentProgram ()
This method makes a request to retrieve the current TV program available in the TV channel. It returns a new 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.
readonly attribute DOMString networkId
MUST return the identification of a broadcast transmission network. On satellite and IP broadband, typically one 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.
readonly attribute DOMString transportStreamId
MUST return the identification of a time-domain multiplex of several programmes carried in Transport Stream (TS) packets. One or more multiplexes can be transmitted on any given radio frequency in a DVB network.
readonly attribute DOMString serviceId
MUST return the identification of a TV, radio or data programme within a TS multiplex. The number of programmes is limited by the capacity of the underlying physical channel.
readonly attribute TVSource source
MUST return the TV source which the TV channel belongs to.
readonly attribute TVChannelType type
MUST return the type of the TV channel.
readonly attribute DOMString name
MUST return the name of the TV channel. E.g., "CNN", "NHK"... etc.
readonly attribute DOMString number
MUST return the Logical Channel Number (LCN) of the TV channel. E.g., "12-1", "12-2", "12-2"... etc.
readonly attribute boolean isEmergency
MUST indicate whether the TV channel is for the emergency purpose.
readonly attribute boolean isFree
MUST indicate whether the TV channel is free to watch.

Steps

The getPrograms method when invoked MUST run the following steps:

  1. Let promise be a new Promise object and resolver be its associated resolver.
  2. Return promise to the caller.
  3. Make a request to the TV channel to retrieve all the TV programs that are available in the TV channel according to the retrieving options specified in the options parameter.
  4. If an error occurs invoke resolver's reject algorithm with error as the value argument.
  5. When the request has been successfully completed:
    1. Let programs be the array of the retrieved TVProgram elements.
    2. Invoke resolver's fulfill algorithm with programs as the value argument.

The getCurrentProgram method when invoked MUST run the following steps:

  1. Let promise be a new Promise object and resolver be its associated resolver.
  2. Return promise to the caller.
  3. Make a request to the TV channel to retrieve all the current TV program available in the TV channel.
  4. If an error occurs invoke resolver's reject algorithm with error as the value argument.
  5. When the request has been successfully completed:
    1. Let program be the retrieved TVProgram element.
    2. Invoke resolver's fulfill algorithm with program as the value argument.

TVProgram Interface

The TVProgram interface represents a bunch of properties and a set of operations related to the TV program.

sequence<DOMString> getAudioLanguages ()
MUST return the audio languages of the TV program in 3-digit language codes specified by ISO 639-2.
sequence<DOMString> getSubtitleLanguages ()
MUST return the subtitle languages of the TV program in 3-digit language codes specified by ISO 639-2.
readonly attribute DOMString eventId
MUST return the event ID of the TV program. It has to be unique only within a TV channel.
readonly attribute TVChannel channel
MUST return the TV channel which the TV program belongs to.
readonly attribute DOMString title
MUST return the title of the TV program.
readonly attribute unsigned long long startTime
MUST return the start time (in milliseconds) of the TV program.
readonly attribute unsigned long long duration
MUST return the duration (in milliseconds) of the TV program.
readonly attribute DOMString? description
MUST return the description of the TV program.
readonly attribute DOMString? rating
MUST return the rating of the TV program.

TVStartScanningOptions Dictionary

The TVStartScanningOptions dictionary contains the information for scanning the TV channels.

boolean isRescanned
Specifies whether or not the process of scanning the TV channels has to clear the currently scanned TV channels before scanning.

TVGetProgramsOptions Dictionary

The TVGetProgramsOptions dictionary contains the information for retrieving the TV programs.

unsigned long long startTime
Specifies the start time of a time period which bounds the time slots of TV programs to be retrieved.
unsigned long long duration
Specifies the duration of a time period which bounds the time slots of TV programs to be retrieved.

TVCurrentSourceChangedEvent Interface

The TVCurrentSourceChangedEvent interface represents the event related to the current TV source that is configured by the method setCurrentSource.

readonly attribute TVSource? source
MUST return the TV source that is currently configured by the TV tuner. MUST return null if the TV source is not configured.

TVEITBroadcastedEvent Interface

The TVEITBroadcastedEvent interface represents the event related to the available TV programs in the EIT that is broadcasted by the TV source.

readonly attribute object programs
MUST return the available TV programs in the EIT that is broadcasted by the TV source. Please note that it needs to be casted into a list of 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.

TVScanningStateChangedEvent Interface

The TVScanningStateChangedEvent interface represents the event related to the state of scanning the TV channels, which is changed by the TV source.

readonly attribute TVScanningState state
MUST return the state of scanning the TV channels, which is changed by the TV source.
readonly attribute TVChannel? channel
MUST return the TV channel that is scanned by the TV source. MUST return null if the state is not specified as "scanned".

TVCurrentChannelChangedEvent Interface

The TVCurrentChannelChangedEvent interface represents the event related to the currently streamed TV channel that is tuned by the method setCurrentChannel.

readonly attribute TVChannel? channel
MUST return the TV channel that is currently streamed by the TV tuner. MUST return null if the TV tuner is not streaming any data.

Enumerations

The attribute type in the TVSource can have the following values:

dvb-t
The TV source works for DVB-T (terrestrial).
dvb-t2
The TV source works for DVB-T2 (terrestrial).
dvb-c
The TV source works for DVB-C (cable).
dvb-c2
The TV source works for DVB-C2 (cable).
dvb-s
The TV source works for DVB-S (satellite).
dvb-s2
The TV source works for DVB-S2 (satellite).
dvb-h
The TV source works for DVB-H (handheld).
dvb-sh
The TV source works for DVB-SH (satellite).
atsc
The TV source works for ATSC (terrestrial/cable).
atsc-m/h
The TV source works for ATSC-M/H (mobile/handheld).
isdb-t
The TV source works for ISDB-T (terrestrial).
isdb-tb
The TV source works for ISDB-Tb (terrestrial, Brazil).
isdb-s
The TV source works for ISDB-S (satellite).
isdb-c
The TV source works for ISDB-C (cable).
1seg
The TV source works for 1seg (handheld).
dtmb
The TV source works for DTMB (terrestrial).
cmmb
The TV source works for CMMB (handheld).
t-dmb
The TV source works for T-DMB (terrestrial).
s-dmb
The TV source works for S-DMB (satellite).

The attribute type in a TVChannel can have the following values:

tv
The TV channel is broadcasted as a regular TV type.
radio
The TV channel is broadcasted as a radio type.
data
The TV channel is broadcasted as a data type.

The attribute state in the TVScanningStateChangedEvent can have the following values:

cleared
The state of scanning the TV channels is cleared by the TV source, which means all the currently scanned TV channels are cleared before scanning.
scanned
The state of scanning the TV channels is scanned, which means a TV channel is successfully scanned by the TV source.
completed
The state of scanning the TV channels is completed by the TV source.
stopped
The state of scanning the TV channels is stopped by the TV source.

Acknowledgements

To be constructed.