
MediaKey API
Media keys are the keys of a Bluetooth headset which control multimedia playback.
For more information on the Media Key features, see Media Key Guide.
Since: 2.3
Table of Contents
- 1. Type Definitions
- 1.1. MediaKeyType
 
 - 2. Interfaces
- 2.1. MediaKeyManagerObject
 - 2.2. MediaKeyManager
 - 2.3. MediaKeyEventCallback
 
 - 3. Related Feature
 - 4. Full WebIDL
 
Summary of Interfaces and Methods
| Interface | Method | 
|---|---|
| MediaKeyManagerObject | |
| MediaKeyManager | 
 void setMediaKeyEventListener (MediaKeyEventCallback callback) 
void unsetMediaKeyEventListener () 
 | 
| MediaKeyEventCallback | 
 void onpressed (MediaKeyType type) 
void onreleased (MediaKeyType type) 
 | 
1. Type Definitions
1.1. MediaKeyType
  enum MediaKeyType { "MEDIA_PLAY", "MEDIA_STOP", "MEDIA_PAUSE", "MEDIA_PREVIOUS", "MEDIA_NEXT", "MEDIA_FAST_FORWARD", "MEDIA_REWIND",
    "MEDIA_PLAY_PAUSE" };
Since: 2.3
- MEDIA_PLAY - the Play media key
 - MEDIA_STOP - the Stop media key
 - MEDIA_PAUSE - the Pause media key
 - MEDIA_PREVIOUS - the Previous media key
 - MEDIA_NEXT - the Next media key
 - MEDIA_FAST_FORWARD - the Fast Forward media key
 - MEDIA_REWIND - the Rewind media key
 - MEDIA_PLAY_PAUSE - the Play/Pause media key
 
2. Interfaces
2.1. MediaKeyManagerObject
  [NoInterfaceObject] interface MediaKeyManagerObject {
    readonly attribute MediaKeyManager mediakey;
  };
Tizen implements MediaKeyManagerObject;
Since: 2.3
There is a tizen.mediakey object that allows accessing the functionality of the Media Key API.
Attributes
- 
                readonly
MediaKeyManager mediakeyObject representing a media key manager.
Since: 2.3
 
2.2. MediaKeyManager
  [NoInterfaceObject] interface MediaKeyManager {
    void setMediaKeyEventListener(MediaKeyEventCallback callback) raises(WebAPIException);
    void unsetMediaKeyEventListener() raises(WebAPIException);
  };
Since: 2.3
Methods
- 
setMediaKeyEventListener - 
Registers a listener to be called when a media key is pressed or released.
void setMediaKeyEventListener(MediaKeyEventCallback callback);
Since: 2.3
Parameters:
- callback: Callback method to be invoked when a media key has been pressed or released.
 
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.
 
Code example:
tizen.mediakey.setMediaKeyEventListener({ onpressed: function(key) { console.log("Pressed key: " + key); }, onreleased: function(key) { console.log("Released key: " + key); } }); - 
unsetMediaKeyEventListener - 
Unsubscribes from receiving notification for detecting the media key event.
void unsetMediaKeyEventListener();
Since: 2.3
Calling this function has no effect if listener is not set.
Exceptions:
- WebAPIException
with error type UnknownError in any other error case.
 
Code example:
tizen.mediakey.unsetMediaKeyEventListener();
 - WebAPIException
 
2.3. MediaKeyEventCallback
  [Callback, NoInterfaceObject] interface MediaKeyEventCallback {
    void onpressed(MediaKeyType type);
    void onreleased(MediaKeyType type);
  };
Since: 2.3
Methods
- 
onpressed - 
Called when a media key has been pressed.
void onpressed(MediaKeyType type);
Since: 2.3
Parameters:
- type: The pressed media key.
 
 - 
onreleased - 
Called when a media key has been released.
void onreleased(MediaKeyType type);
Since: 2.3
Parameters:
- type: The released media key.
 
 
3. Related Feature
To guarantee that the Media Key application runs on a device with Bluetooth feature, declare the following feature requirements in the config file:
4. Full WebIDL
module MediaKey {
  enum MediaKeyType { "MEDIA_PLAY", "MEDIA_STOP", "MEDIA_PAUSE", "MEDIA_PREVIOUS", "MEDIA_NEXT", "MEDIA_FAST_FORWARD", "MEDIA_REWIND",
    "MEDIA_PLAY_PAUSE" };
  Tizen implements MediaKeyManagerObject;
  [NoInterfaceObject] interface MediaKeyManagerObject {
    readonly attribute MediaKeyManager mediakey;
  };
  [NoInterfaceObject] interface MediaKeyManager {
    void setMediaKeyEventListener(MediaKeyEventCallback callback) raises(WebAPIException);
    void unsetMediaKeyEventListener() raises(WebAPIException);
  };
  [Callback, NoInterfaceObject] interface MediaKeyEventCallback {
    void onpressed(MediaKeyType type);
    void onreleased(MediaKeyType type);
  };
};