The TV Manager API interfaces provide a bunch of properties and a set of operations to allow Web applications to acquire the information of TV sources, TV channels and TV programs as well as to manage the native TV hardwares (i.e., TV tuners) or the TV Web services.
The TV Manager API is aimed to cover the following user 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 TV tuners that are currently available on the TV device and how to listen to the events for the TV tuner changes.
// An array which saves all the currently available TV tuners.
var curTuners = [];
// Set the 'ontunerchanged' event handler.
navigator.mozTV.ontunerchanged = function ontunerchanged(event) {
var operation = event.operation;
var changedTuner = event.tuner;
switch (operation) {
case "added":
curTuners.push(changedTuner);
break;
case "removed":
curTuners.some(function findTuner(tuner, index) {
if (tuner.id == changedTuner.id) {
curTuners.splice(index, 1);
return true;
}
return false;
});
break;
default:
break;
}
};
// Retrieve all the currently available TV tuners.
navigator.mozTV.getTuners().then(function onsuccess(tuners) {
curTuners = tuners;
tuners.forEach(function setEventHandler(tuner) {
// Set the 'oncurrentsourcechanged' event handler.
tuner.oncurrentsourcechanged = function oncurrentsourcechanged(event) {
alert("The current TV source of TV tuner: " + tuner.id +
" is configured to: " + event.source.type);
};
});
}, function onerror(error) {
alert(error);
});
The following example shows how to get all the TV channels that are currently available in the currently configured TV source of a TV tuner and how to listen to the events for the TV channel changes.
// A matrix which maps the TV tuner to its corresponding array of TV
// channels based on the currently configured TV source.
// E.g., { "tunerId1": [...], "tunerId2": [...] }.
var curChannelsOfTuners = {};
// Retrieve all the currently available TV tuners in the TV device.
navigator.mozTV.getTuners().then(function onsuccess(tuners) {
tuners.forEach(function getChannelsByTuner(tuner) {
var tunerId = tuner.id;
var currentSource = tuner.currentSource;
if (!currentSource) {
return;
}
// Set the 'onscanningstatechanged' event handler.
currentSource.onscanningstatechanged = function onscanningstatechanged(event) {
var state = event.state;
var scannedChannel = event.channel;
switch (state) {
case "cleared":
if (curChannelsOfTuners[tunerId]) {
delete curChannelsOfTuners[tunerId];
}
break;
case "scanned":
var channels = curChannelsOfTuners[tunerId];
if (channels) {
channels.push(scannedChannel);
} else {
curChannelsOfTuners[tunerId] = [scannedChannel];
}
break;
default:
break;
}
};
// Retrieve all the currently available TV channels in the
// currently configured TV source of the TV tuner.
currentSource.getChannels().then(function onsuccess(channels) {
curChannelsOfTuners[tunerId] = channels;
channels.forEach(function setEventHandler(channel) {
// Set the 'onprotectionstatechanged' event handler.
channel.onprotectionstatechanged = function onprotectionstatechanged(event) {
alert("The current protection state of TV channel: " + channel.name +
" is configured to: " + event.isProtected);
};
});
}, function onerror(error) {
alert(error);
});
});
}, function onerror(error) {
alert(error);
});
The following example shows how to get all the TV programs that are currently available in the TV channel and how to listen to the events for the TV program changes.
// A matrix which maps the TV channel to its corresponding array of TV
// programs. E.g., { "channelNumber1": [...], "channelNumber2": [...] }.
var curProgramsOfChannels = {};
// Retrieve all the currently available TV tuners in the TV device.
navigator.mozTV.getTuners().then(function onsuccess(tuners) {
if (tuners.length == 0) {
return;
}
// Just use the first TV tuner.
var tuner = tuners[0];
var currentSource = tuner.currentSource;
if (!currentSource) {
return;
}
// Set the 'oneitbroadcasted' event handler.
currentSource.oneitbroadcasted = function oneitbroadcasted(event) {
var newPrograms = event.programs;
// Flush the EPG because a new EIT is broadcasted by the TV source.
curProgramsOfChannels = {};
newPrograms.forEach(function addProgram(program) {
var channelNumber = program.channel.number;
var programs = curProgramsOfChannels[channelNumber];
if (programs) {
programs.push(program);
} else {
curProgramsOfChannels[channelNumber] = [program];
}
});
};
// Retrieve all the currently available TV channels in the currently
// 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 currently available TV programs in 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 MediaStream
of a TV source by assigning the MediaStream to a
HTMLMediaElement.
<!DOCTYPE html>
<html>
<head>
<script>
// Retrieve all the currently available TV tuners first.
navigator.mozTV.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 scan and get all the TV channels that are available in the currently configured TV source of the TV tuner.
// Retrieve all the currently available TV tuners in the TV device.
navigator.mozTV.getTuners().then(function onsuccess(tuners) {
if (tuners.length == 0) {
return;
}
// Just use the first TV tuner.
var tuner = tuners[0];
var currentSource = tuner.currentSource;
if (!currentSource) {
return;
}
// Set the 'onscanningstatechanged' event handler.
currentSource.onscanningstatechanged = function onscanningstatechanged(event) {
var state = event.state;
var scannedChannel = event.channel;
switch (state) {
case "cleared":
alert("All the TV channels are cleared for rescanning.");
break;
case "scanned":
alert("A new TV channel is scanned: " + scannedChannel.name);
break;
case "completed":
alert("The scanning process is completed.");
break;
case "stopped":
alert("The scanning process is stopped.");
break;
default:
break;
}
};
if (currentSource.isScanning) {
return;
}
// Ask the currently configured TV source to scan the TV channels.
currentSource.startScanning({
isRescanned: true
}).then(function onsuccess() {
// Retrieve all the currently available TV channels in the
// currently 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);
});
}, function onerror(error) {
alert(error);
});
});
The following example shows how to tune the TV channel by the TV channel number.
// Retrieve all the currently available TV tuners.
navigator.mozTV.getTuners().then(function onsuccess(tuners) {
if (tuners.length == 0) {
return;
}
// Just use the first TV tuner.
var tuner = tuners[0];
var currentSource = tuner.currentSource;
if (!currentSource) {
return;
}
// Retrieve all the currently available TV channels in the currently
// 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.
// Tune the currently streamed TV channel based on the TV channel
// number.
currentSource.setCurrentChannel(channelNumber).then(function onsuccess() {
alert("Succeeded to tune the currently streamed TV channel.");
}, function onerror(error) {
alert(error);
});
}, function onerror(error) {
alert(error);
});
}, function onerror(error) {
alert(error);
});
The following example shows how to unlock the TV parental control.
// Retrieve all the currently available TV tuners.
navigator.mozTV.getTuners().then(function onsuccess(tuners) {
if (tuners.length == 0) {
return;
}
// Just use the first TV tuner.
var tuner = tuners[0];
var currentSource = tuner.currentSource;
if (!currentSource) {
return;
}
// This event handler will be triggered when the TV channel is tuned.
currentSource.oncurrentchannelchanged = function oncurrentchannelchanged(event) {
var changedCurrentChannel = event.channel;
if (navigator.mozTV.isParentalControlLocked &&
changedCurrentChannel.isProtected) {
// If the TV parental control is locked and the currently tuned
// TV channel is protected, the |tuner.stream|'s media tracks
// will be disabled (i.e. black screen). The UA can then pop up
// a prompt to ask the user to enter the password to unlock it.
alert("Parental control is locked. Please enter the password.");
// Unlock the TV parental control which will be applied system-wisely.
navigator.mozTV.unlockParentalControl().then(function onsuccess() {
alert("Parental control is unlocked until the next reboot.");
}, function onerror(error) {
alert(error);
});
}
};
// Retrieve all the currently available TV channels in the currently
// 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;
// Tune the currently streamed TV channel based on the TV channel
// number.
currentSource.setCurrentChannel(channelNumber).then(function onsuccess() {
alert("Succeeded to tune the currently streamed TV channel.");
}, function onerror(error) {
alert(error);
});
}, 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 [[DOM4]].
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.
Promise that will be
used to notify the caller about the result of the operation.
onparentalcontrolchanged event of type
TVParentalControlChangedEvent, fired when the method
unlockParentalControl is invoked to unlock the
TV parental control.
ontunerchanged event of type
TVTunerChangedEvent, fired when the TV device detects a TV
tuner is added/removed.
The getTuners method when invoked MUST run
the following steps:
Promise object and
resolver be its associated resolver.
value argument.
value argument.
The unlockParentalControl 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 TVManager object.
| Event handler | Event name | Event type | Short description |
|---|---|---|---|
ontunerchanged |
tunerchanged |
TVTunerChangedEvent |
Handles the information of the TV tuner that is added/removed by the TV device. |
onparentalcontrolchanged |
parentalcontrolchanged |
TVParentalControlChangedEvent |
Handles the information of the changed state of the TV parental control. |
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 to the
HTMLMediaElement (details) 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.
channelNumber parameter. It returns a
new Promise that will be used to notify the caller
about the result of the operation.
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.
isProtected parameter.
It returns a new Promise that will be used to notify
the caller about the result of the operation.
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.
oncurrentprogramchanged event of type
TVCurrentProgramChangedEvent, fired when the currently
broadcasted TV program is changed by the TV channel.
onprotectionstatechanged event of type
TVProtectionStateChangedEvent, fired when the method
setProtectionState is invoked to configure the
current protection state of the TV channel.
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 setProtectionState method when invoked
MUST run the following steps:
Promise object and
resolver be its associated resolver.
isProtected
parameter.
value argument.
value argument.
The following are the event handlers (and their corresponding event types) that MUST be supported as attributes by the TVChannel object.
| Event handler | Event name | Event type | Short description |
|---|---|---|---|
oncurrentprogramchanged |
currentprogramchanged |
TVCurrentProgramChangedEvent |
Handles the information of the currently broadcasted TV program that is changed by the TV channel. |
onprotectionstatechanged |
protectionstatechanged |
TVProtectionStateChangedEvent |
Handles the information of the current protection state of the
TV channel that is configured by the method
setProtectionState.
|
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.
1, the
method will return the TV program that is currently broadcasted by
the TV channel at this moment; if it is passed as 2,
the method will return the current and the next TV programs.
numberOfPrograms
option is passed as 0 or not passed.
numberOfPrograms
option is passed as 0 or not passed.
The TVParentalControlChangedEvent interface represents the event related to the state change of the TV parental control.
The TVTunerChangedEvent interface represents the event related to the TV tuner that is added/removed by the TV device.
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.
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 TVCurrentProgramChangedEvent interface represents the event related to the currently broadcasted TV program that is changed by the TV channel.
The TVProtectionStateChangedEvent interface represents the event
related to the current protection state of the TV channel that is
configured by the method setProtectionState.
The attribute type in the TVSource can have the
following values:
The attribute type in a TVChannel can have the
following values:
The attribute operation in the TVTunerChangedEvent
can have the following values:
The attribute state in the
TVScanningStateChangedEvent can have the following values:
To be constructed.