Sound API

The Sound API provides functions to control volume level for several sound types.

You can get the maximum volume level for system, notifications, alarm, media and so on. Also, you can change or get the current volume level.

For more information on the Sound features, see Sound Guide.

Since: 2.3

Table of Contents


Summary of Interfaces and Methods

Interface Method
SoundManagerObject
SoundManager SoundModeType getSoundMode ()
void setVolume (SoundType type, double volume)
double getVolume (SoundType type)
void setSoundModeChangeListener (SoundModeChangeCallback callback)
void unsetSoundModeChangeListener ()
void setVolumeChangeListener (SoundVolumeChangeCallback callback)
void unsetVolumeChangeListener ()
SoundModeChangeCallback void onsuccess (SoundModeType mode)
SoundVolumeChangeCallback void onsuccess (SoundType type, double volume)

1. Type Definitions

1.1. SoundType

Sound type to control
    enum SoundType {
        "SYSTEM",
        "NOTIFICATION",
        "ALARM",
        "MEDIA",
        "VOICE",
        "RINGTONE"
    };

Since: 2.3

  • SYSTEM - for system sounds
  • NOTIFICATION - for notifications
  • ALARM - for alarm
  • MEDIA - for media playback
  • VOICE - for voice
  • RINGTONE - for the phone ring

Remark : VOICE type might not be supported on a device which does not support voice recognition.

1.2. SoundModeType

Sound mode type
    enum SoundModeType {
        "SOUND",
        "VIBRATE",
        "MUTE"
    };

Since: 2.3

  • SOUND - the sound mode
  • VIBRATE - the vibrate mode
  • MUTE - the mute mode

2. Interfaces

2.1. SoundManagerObject

The SoundManagerObject interface defines what is instantiated in the tizen object.
    [NoInterfaceObject] interface SoundManagerObject {
         readonly attribute SoundManager sound;
    };
    Tizen implements SoundManagerObject;

Since: 2.3

There is a tizen.sound object that allows accessing the functionality of the Sound API.

2.2. SoundManager

The SoundManager interface provides the functionalities to control the volume level.
    [NoInterfaceObject] interface SoundManager {

        SoundModeType getSoundMode() raises(WebAPIException);

        void setVolume(SoundType type, double volume) raises(WebAPIException);

        double getVolume(SoundType type) raises(WebAPIException);


        void setSoundModeChangeListener(SoundModeChangeCallback callback) raises(WebAPIException);

        void unsetSoundModeChangeListener() raises(WebAPIException);

        void setVolumeChangeListener(SoundVolumeChangeCallback callback) raises(WebAPIException);

        void unsetVolumeChangeListener() raises(WebAPIException);
    };

Since: 2.3

Methods

getSoundMode
Gets the current sound mode.
SoundModeType getSoundMode();
             

Since: 2.3

Return value:

SoundModeType The current sound mode

Exceptions:

  • WebAPIException
    • with error type UnknownError in any error case.

setVolume
Sets the volume level for a specified sound type.
void setVolume(SoundType type, double volume);
             

Since: 2.3

Privilege level: public

Privilege: http://tizen.org/privilege/volume.set

Parameters:

  • type: The sound type
  • volume: The volume level to set
    The level ranges from 0 to 1.

Exceptions:

  • WebAPIException
    • with error type NotSupportedError, if the given type is not supported. (e.g. when VOICE type is given on a Tizen wearable device).

    • with error type TypeMismatchError, if the input parameter is not compatible with the expected type.

    • with error type InvalidValuesError, if any of the input parameters contain an invalid value.

    • with error type UnknownError in any other error case.

getVolume
Gets the current volume level for a specified sound type.
double getVolume(SoundType type);
             

Since: 2.3

Parameters:

  • type: The sound type

Return value:

double The current volume level

Exceptions:

  • WebAPIException
    • with error type NotSupportedError, if the given type is not supported.

    • with error type TypeMismatchError, if the input parameter is not compatible with the expected type.

    • with error type UnknownError in any other error case.

setSoundModeChangeListener
Registers a listener to be called when the sound mode is changed.
void setSoundModeChangeListener(SoundModeChangeCallback callback);
             

Since: 2.3

Parameters:

  • callback: Callback method to be invoked when the sound mode is changed

Exceptions:

  • WebAPIException
    • with error type TypeMismatchError, if the input parameter is not compatible with the expected type.

    • with error type UnknownError in any other error case.

unsetSoundModeChangeListener
Unsubscribes from receiving notification about the sound mode change.
void unsetSoundModeChangeListener();
             

Since: 2.3

Exceptions:

  • WebAPIException
    • with error type UnknownError in any error case.

setVolumeChangeListener
Registers a listener to be called when the volume level is changed.
void setVolumeChangeListener(SoundVolumeChangeCallback callback);
             

Since: 2.3

Parameters:

  • callback: Callback method to be invoked when the volume level is changed

Exceptions:

  • WebAPIException
    • with error type TypeMismatchError, if the input parameter is not compatible with the expected type.

    • with error type UnknownError in any other error case.

unsetVolumeChangeListener
Unsubscribes from receiving notification when the volume level is changed.
void unsetVolumeChangeListener();
             

Since: 2.3

Exceptions:

  • WebAPIException
    • with error type UnknownError in any other error case.

2.3. SoundModeChangeCallback

The SoundModeChangeCallback interface specifies a mode change callback for getting notified about the sound mode changes.
    [Callback=FunctionOnly, NoInterfaceObject]
    interface SoundModeChangeCallback {
        void onsuccess(SoundModeType mode);
    };

Since: 2.3

Methods

onsuccess
Called when the sound mode has changed.
void onsuccess(SoundModeType mode);
             

Since: 2.3

Parameters:

  • mode: Sound mode

2.4. SoundVolumeChangeCallback

The SoundVolumeChangeCallback interface specifies a volume change callback for getting notified about the volume changes.
    [Callback=FunctionOnly, NoInterfaceObject]
    interface SoundVolumeChangeCallback {
        void onsuccess(SoundType type, double volume);
    };

Since: 2.3

Methods

onsuccess
Called when the volume level has changed.
void onsuccess(SoundType type, double volume);
             

Since: 2.3

Parameters:

  • type: Sound type
  • volume: New volume level

3. Full WebIDL

module Sound {
    enum SoundType {
        "SYSTEM",
        "NOTIFICATION",
        "ALARM",
        "MEDIA",
        "VOICE",
        "RINGTONE"
    };

    enum SoundModeType {
        "SOUND",
        "VIBRATE",
        "MUTE"
    };

    [NoInterfaceObject] interface SoundManagerObject {
         readonly attribute SoundManager sound;
    };
    Tizen implements SoundManagerObject;

    [NoInterfaceObject] interface SoundManager {

        SoundModeType getSoundMode() raises(WebAPIException);

        void setVolume(SoundType type, double volume) raises(WebAPIException);

        double getVolume(SoundType type) raises(WebAPIException);


        void setSoundModeChangeListener(SoundModeChangeCallback callback) raises(WebAPIException);

        void unsetSoundModeChangeListener() raises(WebAPIException);

        void setVolumeChangeListener(SoundVolumeChangeCallback callback) raises(WebAPIException);

        void unsetVolumeChangeListener() raises(WebAPIException);
    };

    [Callback=FunctionOnly, NoInterfaceObject]
    interface SoundModeChangeCallback {
        void onsuccess(SoundModeType mode);
    };

    [Callback=FunctionOnly, NoInterfaceObject]
    interface SoundVolumeChangeCallback {
        void onsuccess(SoundType type, double volume);
    };
};