This API provides the audio control features (such as volume and mute) on the TV associated device. There will be a tizen.tvaudiocontrol object that allows access to the functionality of the TV Audio Control API.
Since: 2.3
enum AudioOutputMode { "PCM", "DOLBY", "DTS", "AAC", "DOLBY_DIGITAL_PLUS" };
Remark: DOLBY_DIGITAL_PLUS is supported since Tizen 5.5
enum AudioBeepType { "UP", "DOWN", "LEFT", "RIGHT", "PAGE_LEFT", "PAGE_RIGHT", "BACK", "SELECT", "CANCEL", "WARNING", "KEYPAD", "KEYPAD_ENTER", "KEYPAD_DEL", "MOVE", "PREPARING" };
[NoInterfaceObject] interface AudioControlManagerObject { readonly attribute AudioControlManager tvaudiocontrol; };
Tizen implements AudioControlManagerObject;
There will be a tizen.tvaudiocontrol object that allows the access to the Audio Control API.
[NoInterfaceObject] interface AudioControlManager { void setMute(boolean mute) raises(WebAPIException); boolean isMute() raises(WebAPIException); void setVolume(unsigned short volume) raises(WebAPIException); void setVolumeUp() raises(WebAPIException); void setVolumeDown() raises(WebAPIException); unsigned short getVolume() raises(WebAPIException); void setVolumeChangeListener(VolumeChangeCallback callback) raises(WebAPIException); void unsetVolumeChangeListener() raises(WebAPIException); AudioOutputMode getOutputMode() raises(WebAPIException); void playSound(AudioBeepType type) raises(WebAPIException); };
setMute
void setMute(boolean mute);
Note that turning on mute mode does not change volume level but it simply disables any sound. Turning off the mute will enable sound with the volume level. If setVolumeUp or setVolumeDown functions are used, then mute is disabled.
Privilege level: public
Privilege: http://tizen.org/privilege/tv.audio
Warning: http://tizen.org/privilege/tv.audio (public level) has been deprecated since 5.0.
Parameters:
Exceptions:
with error type SecurityError, if the application does not have the privilege to call this method. This type of error is deprecated since Tizen 5.0.
with error type UnknownError in any other error case.
Code example:
// Turn on the silent mode tizen.tvaudiocontrol.setMute(true);
// Turn off the silent mode tizen.tvaudiocontrol.setMute(false);
isMute
boolean isMute();
Return value:
// Mute to turn off the sound tizen.tvaudiocontrol.setMute(true); // Check if it is mute or not if (tizen.tvaudiocontrol.isMute()) { console.log("At this moment, the sound output of this device is turned off."); } else { alert("It's not possible!"); }
// Checks if increasing the volume makes the silent mode turned off. // Mute to turn off the sound tizen.tvaudiocontrol.setMute(true); // By increasing the volume level, the mute state is changed to be off. tizen.tvaudiocontrol.setVolumeUp(); // Check if it is mute or not if (tizen.tvaudiocontrol.isMute()) { alert("It's not possible! (API bug)"); } else { console.log("setVolumeUp() turns off the silent mode."); }
setVolume
void setVolume(unsigned short volume);
The value of volume is allowed from 0 to 100. If an invalid value is passed, InvalidValuesError will occur.
with error type InvalidValuesError, if any of the input parameters contain an invalid value.
// Sets the volume tizen.tvaudiocontrol.setVolume(10); try { tizen.tvaudiocontrol.setVolume(-1); } catch (e) { if (e.name === "InvalidValuesError") { alert("The passed value value should be in the range of 0 to 100."); } }
setVolumeUp
void setVolumeUp();
// Sets the volume tizen.tvaudiocontrol.setVolume(99); tizen.tvaudiocontrol.setVolumeUp(); // Check if the current volume is 100 or not. if (tizen.tvaudiocontrol.getVolume() === 100) { alert("setVolumeUp() is successfully called."); } tizen.tvaudiocontrol.setVolumeUp(); // Check if the volume level has been changed or not at the maximum volume level. if (tizen.tvaudiocontrol.getVolume() === 100) { alert("setVolumeUp() is successfully called."); }
setVolumeDown
void setVolumeDown();
If it is called when the volume level is 0, it will be ignored because the minimum volume level is 0. If mute is enabled, then execution of this functions will disable it.
// Sets the volume tizen.tvaudiocontrol.setVolume(1); tizen.tvaudiocontrol.setVolumeDown(); // Check if the current volume is 0 or not. if (tizen.tvaudiocontrol.getVolume() === 0) { alert("setVolumeDown() is successfully called."); } tizen.tvaudiocontrol.setVolumeDown(); // Check if the volume level has been changed or not at the minimum volume level. if (tizen.tvaudiocontrol.getVolume() === 0) { alert("setVolumeDown() is successfully called."); }
getVolume
unsigned short getVolume();
setVolumeChangeListener
void setVolumeChangeListener(VolumeChangeCallback callback);
Note that this method overwrites the previously registered listener.
with error type TypeMismatchError, if any input attribute is not compatible with the expected type for this attribute.
var expectedVolumeLevel = 50; function onVolumeChanged(volume) { if (volume === expectedVolumeLevel) { console.log("Succeeded! The volume level has been changed to "+ volume+". "); } else { alert("Failed. The volume level has been changed to "+ volume+" . We expect 50."); } } tizen.tvaudiocontrol.setVolume(0); tizen.tvaudiocontrol.setVolumeChangeListener(onVolumeChanged); tizen.tvaudiocontrol.setVolume(expectedVolumeLevel);
unsetVolumeChangeListener
void unsetVolumeChangeListener();
var expectedVolumeLevel = 50; function onVolumeChanged(volume) { alert("This function must not be called."); } tizen.tvaudiocontrol.setVolume(0); tizen.tvaudiocontrol.setVolumeChangeListener(onVolumeChanged); tizen.tvaudiocontrol.unsetVolumeChangeListener(); tizen.tvaudiocontrol.setVolume(expectedVolumeLevel);
getOutputMode
AudioOutputMode getOutputMode();
with error type UnknownError in an unspecified error case.
playSound
void playSound(AudioBeepType type);
with error type TypeMismatchError, if the input parameter is not compatible with the expected type.
[Callback = FunctionOnly, NoInterfaceObject] interface VolumeChangeCallback { void onchanged(unsigned short volume); };
onchanged
void onchanged(unsigned short volume);
To guarantee the running of this application on a device with a TV audio control support, define the following requirements in the config file:
For more information, see Application Filtering.
module TVAudioControl { enum AudioOutputMode { "PCM", "DOLBY", "DTS", "AAC", "DOLBY_DIGITAL_PLUS" }; enum AudioBeepType { "UP", "DOWN", "LEFT", "RIGHT", "PAGE_LEFT", "PAGE_RIGHT", "BACK", "SELECT", "CANCEL", "WARNING", "KEYPAD", "KEYPAD_ENTER", "KEYPAD_DEL", "MOVE", "PREPARING" }; [NoInterfaceObject] interface AudioControlManagerObject { readonly attribute AudioControlManager tvaudiocontrol; }; Tizen implements AudioControlManagerObject; [NoInterfaceObject] interface AudioControlManager { void setMute(boolean mute) raises(WebAPIException); boolean isMute() raises(WebAPIException); void setVolume(unsigned short volume) raises(WebAPIException); void setVolumeUp() raises(WebAPIException); void setVolumeDown() raises(WebAPIException); unsigned short getVolume() raises(WebAPIException); void setVolumeChangeListener(VolumeChangeCallback callback) raises(WebAPIException); void unsetVolumeChangeListener() raises(WebAPIException); AudioOutputMode getOutputMode() raises(WebAPIException); void playSound(AudioBeepType type) raises(WebAPIException); }; [Callback = FunctionOnly, NoInterfaceObject] interface VolumeChangeCallback { void onchanged(unsigned short volume); }; };