MediaController API

The Media Controller API provides functions for communication between the media controller server and the media controller client.

It helps to transfer the information like playback info, shuffle/repeat mode and metadata from media controller server to client. Allows to control server state by sending commands from client.

For more information on the Media Controller features, see Media Controller Guide.

Since: 5.0

Table of Contents


Summary of Interfaces and Methods

Interface Method
MediaControllerObject
MediaControllerManager
MediaControllerServer
void updatePlaybackPosition (unsigned long long position)
void updateShuffleMode (boolean mode)
void updateRepeatMode (boolean mode)
void removeCommandListener (long watchId)
MediaControllerClient
void findServers (MediaControllerServerInfoArraySuccessCallback successCallback, optional ErrorCallback? errorCallback)
MediaControllerServerInfo
void sendPlaybackState (MediaControllerPlaybackState state, optional SuccessCallback? successCallback, optional ErrorCallback? errorCallback)
void sendPlaybackPosition (unsigned long long position, optional SuccessCallback? successCallback, optional ErrorCallback? errorCallback)
void sendShuffleMode (boolean mode, optional SuccessCallback? successCallback, optional ErrorCallback? errorCallback)
void sendRepeatMode (boolean mode, optional SuccessCallback? successCallback, optional ErrorCallback? errorCallback)
void sendCommand (DOMString command, object data, MediaControllerSendCommandSuccessCallback successCallback, optional ErrorCallback? errorCallback)
MediaControllerPlaybackInfo
MediaControllerMetadata
MediaControllerServerInfoArraySuccessCallback
MediaControllerSendCommandSuccessCallback
void onsuccess (object? data)
MediaControllerReceiveCommandCallback
object? onsuccess (ApplicationId clientAppName, DOMString command, object data)
MediaControllerServerStatusChangeCallback
MediaControllerPlaybackInfoChangeCallback
void onplaybackchanged (MediaControllerPlaybackState state, unsigned long long position)
void onshufflemodechanged (boolean mode)
void onrepeatmodechanged (boolean mode)
MediaControllerChangeRequestPlaybackInfoCallback
void onplaybackpositionrequest (unsigned long long position)
void onshufflemoderequest (boolean mode)
void onrepeatmoderequest (boolean mode)

1. Type Definitions

1.1. MediaControllerServerState

The media controller server state.
  enum MediaControllerServerState { "ACTIVE", "INACTIVE" };

Since: 5.0

  • ACTIVE - Corresponds to active server state.
  • INACTIVE - Corresponds to inactive server state.

1.2. MediaControllerPlaybackState

Defines media playback state.
  enum MediaControllerPlaybackState { "PLAY", "PAUSE", "STOP", "NEXT", "PREV", "FORWARD", "REWIND" };

Since: 5.0

  • PLAY - Corresponds to the "playing" media controller playback state.
  • PAUSE - Corresponds to the "paused" media controller playback state.
  • STOP - Corresponds to the "stopped" media controller playback state.
  • NEXT - Corresponds to the "moving to next" media controller playback state.
  • PREV - Corresponds to the "moving to previous" media controller playback state.
  • FORWARD - Corresponds to the "forwarding" media controller playback state.
  • REWIND - Corresponds to the "rewinding" media controller playback state.

2. Interfaces

2.1. MediaControllerObject

This interface defines what is instantiated by the Tizen object from the Tizen platform.
  [NoInterfaceObject] interface MediaControllerObject {
    readonly attribute MediaControllerManager mediacontroller;
  };
  Tizen implements MediaControllerObject;

Since: 5.0

There is a tizen.mediacontroller object that allows access to the Media Controller API.

Attributes

  • readonly MediaControllerManager mediacontroller
    Object representing a media controller manager.

    Since: 5.0

2.2. MediaControllerManager

This interface provides access to the MediaControllerObject object.
  [NoInterfaceObject] interface MediaControllerManager {
    MediaControllerClient getClient() raises(WebAPIException);
    MediaControllerServer createServer() raises(WebAPIException);
  };

Since: 5.0

Methods

getClient
Gets the client object. If not exist, client will be automatically created.

Since: 5.0

Privilege level: public

Privilege: http://tizen.org/privilege/mediacontroller.client

Return value:

    MediaControllerClient: The MediaController Client object.

Exceptions:

  • WebAPIException
    • with error type NotSupportedError, if this feature is not supported.

    • with error type SecurityError, if the application does not have the privilege to call this method.

    • with error type UnknownError, if any other error occurs.

Code example:

try
{
  var mcClient = tizen.mediacontroller.getClient();
}
catch (err)
{
  console.log(err.name + ": " + err.message);
}
createServer
Creates the Server object which holds playback state, meta data and is controlled by Client.
MediaControllerServer createServer();

Since: 5.0

Privilege level: public

Privilege: http://tizen.org/privilege/mediacontroller.server

Return value:

    MediaControllerServer: The MediaController Server object.

Exceptions:

  • WebAPIException
    • with error type NotSupportedError, if this feature is not supported.

    • with error type SecurityError, if the application does not have the privilege to call this method.

    • with error type UnknownError, if any other error occurs.

Code example:

try
{
  var mcServer = tizen.mediacontroller.createServer();
}
catch (err)
{
  console.log(err.name + ": " + err.message);
}

2.3. MediaControllerServer

Provides functions for sending the server information to the client.
  [NoInterfaceObject] interface MediaControllerServer {
    readonly attribute MediaControllerPlaybackInfo playbackInfo;
    void updatePlaybackState(MediaControllerPlaybackState state) raises(WebAPIException);
    void updatePlaybackPosition(unsigned long long position) raises(WebAPIException);
    void updateShuffleMode(boolean mode) raises(WebAPIException);
    void updateRepeatMode(boolean mode) raises(WebAPIException);
    void updateMetadata(MediaControllerMetadata metadata) raises(WebAPIException);
    long addChangeRequestPlaybackInfoListener(MediaControllerChangeRequestPlaybackInfoCallback listener) raises(WebAPIException);
    void removeChangeRequestPlaybackInfoListener(long watchId) raises(WebAPIException);
    long addCommandListener(MediaControllerReceiveCommandCallback listener) raises(WebAPIException);
    void removeCommandListener(long watchId) raises(WebAPIException);
  };

Since: 5.0

Allows the application to send the playback state and metadata to other application and be controlled by other application(client) remotely.

Attributes

  • readonly MediaControllerPlaybackInfo playbackInfo
    Current playback info.

    Since: 5.0

    Remark: Object holds state which is automatically updated by update methods.

Methods

updatePlaybackState
Updates playback state and send notification to the listening clients. See MediaControllerServerInfo.addPlaybackInfoChangeListener to check how to receive playback info changes from server on client side.
void updatePlaybackState(MediaControllerPlaybackState state);

Since: 5.0

Parameters:

  • state: Playback state.

Exceptions:

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

    • with error type UnknownError, if any other error occurs.

Code example:

var mcServer = tizen.mediacontroller.createServer();

mcServer.updatePlaybackState("PLAY");
console.log("Current playback state is: " + mcServer.playbackInfo.state);

Output example:

Current playback state is: PLAY
updatePlaybackPosition
Updates playback position and send notification to the listening clients.
void updatePlaybackPosition(unsigned long long position);

Since: 5.0

Parameters:

  • position: Playback position.

Exceptions:

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

    • with error type UnknownError, if any other error occurs.

Code example:

var mcServer = tizen.mediacontroller.createServer();

mcServer.updatePlaybackPosition(164);
console.log("Current playback position is: " + mcServer.playbackInfo.position);

Output example:

Current playback position is: 164
updateShuffleMode
Updates shuffle mode and send notification to the listening clients.
void updateShuffleMode(boolean mode);

Since: 5.0

Parameters:

  • mode: Shuffle mode.

Exceptions:

  • WebAPIException
    • with error type UnknownError, if any error occurs.

Code example:

var mcServer = tizen.mediacontroller.createServer();

mcServer.updateShuffleMode(true);
console.log("Current shuffle mode is: " + mcServer.playbackInfo.shuffleMode);

Output example:

Current shuffle mode is: true
updateRepeatMode
Updates repeat mode and send notification to the listening clients.
void updateRepeatMode(boolean mode);

Since: 5.0

Parameters:

  • mode: Repeat mode.

Exceptions:

  • WebAPIException
    • with error type UnknownError, if any error occurs.

Code example:

var mcServer = tizen.mediacontroller.createServer();

mcServer.updateRepeatMode(true);
console.log("Current repeat mode is: " + mcServer.playbackInfo.repeatMode);
updateMetadata
Updates metadata and send notification to the listening clients.
void updateMetadata(MediaControllerMetadata metadata);

Since: 5.0

Parameters:

  • metadata: Metadata object.

Exceptions:

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

    • with error type UnknownError, if any other error occurs.

Code example:

var mcServer = tizen.mediacontroller.createServer();
var metadata = mcServer.playbackInfo.metadata;

metadata.artist = "Artist Name";
mcServer.updateMetadata(metadata);

console.log("Current metadata is: " + JSON.stringify(mcServer.playbackInfo.metadata));

Output example:

Current metadata is: {"title":"","artist":"Artist Name","album":"","author":"","genre":"",
"duration":"","date":"","copyright":"","description":"","trackNum":"","picture":""}
addChangeRequestPlaybackInfoListener
Adds the listener for a media playback info requests from client. See MediaControllerServerInfo to check how to send playback info change requests from client.
long addChangeRequestPlaybackInfoListener(MediaControllerChangeRequestPlaybackInfoCallback listener);

Since: 5.0

Parameters:

  • listener: Change request listener to add.

Return value:

    long: The identifier used to clear the watch subscription.

Exceptions:

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

    • with error type UnknownError, if any other error occurs.

Code example:

var watcherId = 0;  /* Watcher identifier. */
var mcServer = tizen.mediacontroller.createServer();

var playbackRequestListener =
{
  onplaybackstaterequest: function(state)
  {
    console.log("Playback state requested to: " + state);
  },
  onplaybackpositionrequest: function(position)
  {
    console.log("Playback position requested to: " + position);
  },
  onshufflemoderequest: function(mode)
  {
    console.log("Shuffle mode requested to: " + mode);
  },
  onrepeatmoderequest: function(mode)
  {
    console.log("Repeat mode requested to: " + mode);
  }
};

/* Registers to receive playback info change requests from client. */
watcherId = mcServer.addChangeRequestPlaybackInfoListener(playbackRequestListener);
removeChangeRequestPlaybackInfoListener
Removes the listener, so stop receiving playback state requests from clients.
void removeChangeRequestPlaybackInfoListener(long watchId);

Since: 5.0

Calling this function has no effect if there is no listener with given id.

Parameters:

  • watchId: Subscription identifier.

Exceptions:

  • WebAPIException
    • with error type UnknownError, if any error occurs.

Code example:

var watcherId = 0;  /* Watcher identifier. */
var mcServer = tizen.mediacontroller.createServer();

var playbackRequestListener =
{
  onplaybackstaterequest: function(state)
  {
    console.log("Playback state requested to: " + state);
  },
  onplaybackpositionrequest: function(position)
  {
    console.log("Playback position requested to: " + position);
  },
  onshufflemoderequest: function(mode)
  {
    console.log("Shuffle mode requested to: " + mode);
  },
  onrepeatmoderequest: function(mode)
  {
    console.log("Repeat mode requested to: " + mode);
  }
};

/* Registers to receive playback info change requests. */
watcherId = mcServer.addChangeRequestPlaybackInfoListener(playbackRequestListener);

/* Cancels the watch operation. */
mcServer.removeChangeRequestPlaybackInfoListener(watcherId);
addCommandListener
Adds the listener for receiving custom commands from client. See MediaControllerServerInfo to check how to send custom commands from client.
long addCommandListener(MediaControllerReceiveCommandCallback listener);

Since: 5.0

Parameters:

  • listener: Custom commands listener to add.

Return value:

    long: The identifier used to clear the watch subscription.

Exceptions:

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

    • with error type UnknownError, if any other error occurs.

Code example:

var watcherId = 0;  /* Watcher identifier. */
var mcServer = tizen.mediacontroller.createServer();

var commandReceiveListener = function(clientName, command, data)
{
  console.log("Command " + command + " received from: " + clientName + " with data: " +
              JSON.stringify(data));

  var reply = {myReply: "someValue"};

  return reply;
};

/* Registers to receive custom commands from client. */
watcherId = mcServer.addCommandListener(commandReceiveListener);
removeCommandListener
Removes the listener, so stop receiving custom commands from clients.
void removeCommandListener(long watchId);

Since: 5.0

Calling this function has no effect if there is no listener with given id.

Parameters:

  • watchId: Subscription identifier.

Exceptions:

  • WebAPIException
    • with error type UnknownError, if any error occurs.

Code example:

var watcherId = 0;  /* Watcher identifier. */
var mcServer = tizen.mediacontroller.createServer();

var commandReceiveListener = function(clientName, command, data)
{
  console.log("Command " + command + " received from: " + clientName + " with data: " +
              JSON.stringify(data));

  var reply = {myReply: "someValue"};

  return reply;
};

/* Registers to receive custom commands from client. */
watcherId = mcServer.addCommandListener(commandReceiveListener);

/* Cancels the watch operation. */
mcServer.removeCommandListener(watcherId);

2.4. MediaControllerClient

The media controller client API and functions related with handling media control. Functions include operations to get the latest status of the media controller servers.
  [NoInterfaceObject] interface MediaControllerClient {
    void findServers(MediaControllerServerInfoArraySuccessCallback successCallback, optional ErrorCallback? errorCallback)
                     raises(WebAPIException);
    MediaControllerServerInfo? getLatestServerInfo() raises(WebAPIException);
  };

Since: 5.0

Methods

findServers
Retrieves all activated media controller servers.
void findServers(MediaControllerServerInfoArraySuccessCallback successCallback, optional ErrorCallback? errorCallback);

Since: 5.0

Parameters:

  • successCallback: The method to invoke when all of the registered media controller servers have been found.
  • errorCallback [optional] [nullable]: The method to invoke on failure of retrieving servers list.

Exceptions:

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

    • with error type UnknownError, if any other error occurs.

Code example:

var mcClient;
try
{
  mcClient = tizen.mediacontroller.getClient();
}
catch (err)
{
  console.log(err.name + " error: " + err.message);
}

function successCallback(list)
{
  for (var s in list)
  {
    console.log("Found server: " + list[s].name + ", state: " + list[s].state);
  }
}

function errorCallback(err)
{
  console.log(err.name + " error: " + err.message);
}

mcClient.findServers(successCallback, errorCallback);

Output example:

Found server: og8WN4XlLg.BasicUIStudio, state: ACTIVE
getLatestServerInfo
Gets the latest activated media controller server info.
MediaControllerServerInfo? getLatestServerInfo();

Since: 5.0

Remark: If there is no activated media controller server, null value is returned.

Return value:

    MediaControllerServerInfo [nullable]: Server info or null.

Exceptions:

  • WebAPIException
    • with error type UnknownError, if any error occurs.

Code example:

/* Access latest server info. */
var mcClient = tizen.mediacontroller.getClient();
var mcServerInfo = mcClient.getLatestServerInfo();
console.log(
    "Latest server name is: " + mcServerInfo.name + ", server state: " + mcServerInfo.state);

Output example:

Latest server name is: 2cpQcelP8a.HelloTizen, server state: INACTIVE

2.5. MediaControllerServerInfo

This interface provides media controller server state and playback info. Provides methods to send commands to server and listen for server status change.
  [NoInterfaceObject] interface MediaControllerServerInfo {
    readonly attribute ApplicationId name;
    readonly attribute MediaControllerServerState state;
    readonly attribute MediaControllerPlaybackInfo playbackInfo raises(WebAPIException);
    void sendPlaybackState(MediaControllerPlaybackState state, optional SuccessCallback? successCallback,
                           optional ErrorCallback? errorCallback) raises(WebAPIException);
    void sendPlaybackPosition(unsigned long long position, optional SuccessCallback? successCallback,
                              optional ErrorCallback? errorCallback) raises(WebAPIException);
    void sendShuffleMode(boolean mode, optional SuccessCallback? successCallback, optional ErrorCallback? errorCallback)
                         raises(WebAPIException);
    void sendRepeatMode(boolean mode, optional SuccessCallback? successCallback, optional ErrorCallback? errorCallback)
                        raises(WebAPIException);
    void sendCommand(DOMString command, object data, MediaControllerSendCommandSuccessCallback successCallback,
                     optional ErrorCallback? errorCallback) raises(WebAPIException);
    long addServerStatusChangeListener(MediaControllerServerStatusChangeCallback listener) raises(WebAPIException);
    void removeServerStatusChangeListener(long watchId) raises(WebAPIException);
    long addPlaybackInfoChangeListener(MediaControllerPlaybackInfoChangeCallback listener) raises(WebAPIException);
    void removePlaybackInfoChangeListener(long watchId) raises(WebAPIException);
  };

Since: 5.0

Attributes

  • readonly ApplicationId name
    The appId of the media controller server.

    Since: 5.0

  • readonly MediaControllerServerState state
    State of the media controller server.

    Since: 5.0

  • readonly MediaControllerPlaybackInfo playbackInfo
    Current playback info.

    Since: 5.0

    Exceptions:

    • WebAPIException
      • with error type UnknownError, if any error occurs.

Methods

sendPlaybackState
Allows to change playback state of media controller server.
void sendPlaybackState(MediaControllerPlaybackState state, optional SuccessCallback? successCallback,
                       optional ErrorCallback? errorCallback);

Since: 5.0

Parameters:

  • state: Playback state.
  • successCallback [optional] [nullable]: The method to invoke when playback state was changed.
  • errorCallback [optional] [nullable]: The method to invoke on operation failure.

Exceptions:

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

    • with error type UnknownError, if any other error occurs.

Code example:

var mcClient = tizen.mediacontroller.getClient();
var mcServerInfo = mcClient.getLatestServerInfo();

mcServerInfo.sendPlaybackState("STOP",
    function()
    {
      console.log("Playback has stopped");
    },
    function(e)
    {
      console.log("Unable to change playback state: " + e.message);
    });

Output example:

Playback has stopped
sendPlaybackPosition
Allows to change playback position of media controller server.
void sendPlaybackPosition(unsigned long long position, optional SuccessCallback? successCallback,
                          optional ErrorCallback? errorCallback);

Since: 5.0

Parameters:

  • position: Playback position.
  • successCallback [optional] [nullable]: The method to invoke when playback position was changed.
  • errorCallback [optional] [nullable]: The method to invoke on operation failure.

Exceptions:

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

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

    • with error type UnknownError, if any other error occurs.

Code example:

var mcClient = tizen.mediacontroller.getClient();
var mcServerInfo = mcClient.getLatestServerInfo();

mcServerInfo.sendPlaybackPosition(164,
    function()
    {
      console.log("Playback position changed");
    },
    function(e)
    {
      console.log("Unable to change playback position: " + e.message);
    });

Output example:

Playback position changed
sendShuffleMode
Allows to change shuffle mode of media controller server.
void sendShuffleMode(boolean mode, optional SuccessCallback? successCallback, optional ErrorCallback? errorCallback);

Since: 5.0

Parameters:

  • mode: Shuffle mode.
  • successCallback [optional] [nullable]: The method to invoke when shuffle mode was changed.
  • errorCallback [optional] [nullable]: The method to invoke on operation failure.

Exceptions:

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

    • with error type UnknownError, if any other error occurs.

Code example:

var mcClient = tizen.mediacontroller.getClient();
var mcServerInfo = mcClient.getLatestServerInfo();

mcServerInfo.sendShuffleMode(true,
    function()
    {
      console.log("Shuffle mode changed");
    },
    function(e)
    {
      console.log("Unable to change shuffle mode: " + e.message);
    });

Output example:

Shuffle mode changed
sendRepeatMode
Allows to change repeat mode of media controller server.
void sendRepeatMode(boolean mode, optional SuccessCallback? successCallback, optional ErrorCallback? errorCallback);

Since: 5.0

Parameters:

  • mode: Repeat mode.
  • successCallback [optional] [nullable]: The method to invoke when repeat mode was changed.
  • errorCallback [optional] [nullable]: The method to invoke on operation failure.

Exceptions:

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

    • with error type UnknownError, if any other error occurs.

Code example:

var mcClient = tizen.mediacontroller.getClient();
var mcServerInfo = mcClient.getLatestServerInfo();

mcServerInfo.sendRepeatMode(false,
    function()
    {
      console.log("Repeat mode changed");
    },
    function(e)
    {
      console.log("Unable to change repeat mode: " + e.message);
    });
sendCommand
Allows to send custom command to media controller server.
void sendCommand(DOMString command, object data, MediaControllerSendCommandSuccessCallback successCallback,
                 optional ErrorCallback? errorCallback);

Since: 5.0

Remark: See addCommandListener() method to check how to receive and respond to custom commands.

Parameters:

  • command: Custom command name which is handled on server side.
  • data: Additional data for custom command which is send to server.
  • successCallback: The method to invoke when server responded to custom command.
  • errorCallback [optional] [nullable]: The method to invoke on operation failure.

Exceptions:

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

    • with error type UnknownError, if any other error occurs.

Code example:

var mcClient = tizen.mediacontroller.getClient();
var mcServerInfo = mcClient.getLatestServerInfo();

var exampleCustomCommandData = {myFilter: "rock"};
mcServerInfo.sendCommand("myPlaylistFilter", exampleCustomCommandData,
    function(response)
    {
      console.log("Command executed with result: " + JSON.stringify(response));
    },
    function(e)
    {
      console.log("Error executing command: " + e.message);
    });
addServerStatusChangeListener
Adds the listener for a media controller server status change.
long addServerStatusChangeListener(MediaControllerServerStatusChangeCallback listener);

Since: 5.0

Parameters:

  • listener: Status change listener to add.

Return value:

    long: The identifier used to clear the watch subscription.

Exceptions:

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

    • with error type UnknownError, if any other error occurs.

Code example:

var watcherId = 0;  /* Watcher identifier. */
var mcClient = tizen.mediacontroller.getClient();
var mcServerInfo = mcClient.getLatestServerInfo();

/* Registers to be notified when server status changes. */
watcherId = mcServerInfo.addServerStatusChangeListener(function(status)
{
  console.log(mcServerInfo.name + " server status changed to " + status);
});
removeServerStatusChangeListener
Removes the listener, so stop receiving notifications about media controller server status.
void removeServerStatusChangeListener(long watchId);

Since: 5.0

Calling this function has no effect if there is no listener with given id.

Parameters:

  • watchId: Subscription identifier.

Exceptions:

  • WebAPIException
    • with error type UnknownError, if any error occurs.

Code example:

var watcherId = 0;  /* Watcher identifier. */
var mcClient = tizen.mediacontroller.getClient();
var mcServerInfo = mcClient.getLatestServerInfo();

/* Registers to be notified when server status changes. */
watcherId = mcServerInfo.addServerStatusChangeListener(function(status)
{
  console.log(mcServerInfo.name + " server status changed to " + status);
});

/* Cancels the watch operation. */
mcServerInfo.removeServerStatusChangeListener(watcherId);
addPlaybackInfoChangeListener
Adds the listener for a media playback info changes.
long addPlaybackInfoChangeListener(MediaControllerPlaybackInfoChangeCallback listener);

Since: 5.0

Parameters:

  • listener: Status change listener to add.

Return value:

    long: The identifier used to clear the watch subscription.

Exceptions:

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

    • with error type UnknownError, if any other error occurs.

Code example:

var watcherId = 0;  /* Watcher identifier. */
var mcClient = tizen.mediacontroller.getClient();
var mcServerInfo = mcClient.getLatestServerInfo();

var playbackListener =
{
  onplaybackchanged: function(state, position)
  {
    console.log("Current playback state: " + state);
    console.log("Current playback position: " + position);
  },
  onshufflemodechanged: function(mode)
  {
    console.log("Shuffle mode changed to: " + mode);
  },
  onrepeatmodechanged: function(mode)
  {
    console.log("Repeat mode changed to: " + mode);
  },
  onmetadatachanged: function(metadata)
  {
    console.log("Playback metadata changed: " + JSON.stringify(metadata));
  }
};

/* Registers to be notified when playback state changes. */
watcherId = mcServerInfo.addPlaybackInfoChangeListener(playbackListener);
removePlaybackInfoChangeListener
Removes the listener, so stop receiving notifications about media playback info changes.
void removePlaybackInfoChangeListener(long watchId);

Since: 5.0

Calling this function has no effect if there is no listener with given id.

Parameters:

  • watchId: Subscription identifier.

Exceptions:

  • WebAPIException
    • with error type UnknownError, if any error occurs.

Code example:

var watcherId = 0;  /* Watcher identifier. */
var mcClient = tizen.mediacontroller.getClient();
var mcServerInfo = mcClient.getLatestServerInfo();

/* receives playback state changes. */
var playbackListener =
{
  onplaybackchanged: function(state, position)
  {
    console.log("Current playback state: " + state);
    console.log("Current playback position: " + position);
  },
  onshufflemodechanged: function(mode)
  {
    console.log("Shuffle mode changed to: " + mode);
  },
  onrepeatmodechanged: function(mode)
  {
    console.log("Repeat mode changed to: " + mode);
  },
  onmetadatachanged: function(metadata)
  {
    console.log("Playback metadata changed: " + JSON.stringify(metadata));
  }
};

/* Registers to be notified when playback state changes. */
watcherId = mcServerInfo.addPlaybackInfoChangeListener(playbackListener);

/* Cancels the watch operation. */
mcServerInfo.removePlaybackInfoChangeListener(watcherId);

2.6. MediaControllerPlaybackInfo

Current playback info.
  [NoInterfaceObject] interface MediaControllerPlaybackInfo {
    readonly attribute MediaControllerPlaybackState state;
    readonly attribute unsigned long long position;
    readonly attribute boolean shuffleMode;
    readonly attribute boolean repeatMode;
    readonly attribute MediaControllerMetadata metadata;
  };

Since: 5.0

Attributes

  • readonly MediaControllerPlaybackState state
    Current playback state.

    Since: 5.0

  • readonly unsigned long long position
    Current playback position.

    Since: 5.0

  • readonly boolean shuffleMode
    Current shuffle mode.

    Since: 5.0

  • readonly boolean repeatMode
    Current repeat mode.

    Since: 5.0

  • readonly MediaControllerMetadata metadata
    Current playback metadata.

    Since: 5.0

2.7. MediaControllerMetadata

Playback metadata.
  [NoInterfaceObject] interface MediaControllerMetadata {
    attribute DOMString title;
    attribute DOMString artist;
    attribute DOMString album;
    attribute DOMString author;
    attribute DOMString genre;
    attribute DOMString duration;
    attribute DOMString date;
    attribute DOMString copyright;
    attribute DOMString description;
    attribute DOMString trackNum;
    attribute DOMString picture;
  };

Since: 5.0

Attributes

  • DOMString title
    Media title.

    Since: 5.0

  • DOMString artist
    Media artist.

    Since: 5.0

  • DOMString album
    Media album.

    Since: 5.0

  • DOMString author
    Media author.

    Since: 5.0

  • DOMString genre
    Media genre.

    Since: 5.0

  • DOMString duration
    Media duration.

    Since: 5.0

  • DOMString date
    Media date.

    Since: 5.0

  • DOMString copyright
    Media copyright.

    Since: 5.0

  • DOMString description
    Media description.

    Since: 5.0

  • DOMString trackNum
    Media track number.

    Since: 5.0

  • DOMString picture
    Media picture.

    Since: 5.0

2.8. MediaControllerServerInfoArraySuccessCallback

The MediaControllerServerInfoArraySuccessCallback interface that defines the success method for MediaControllerClient.findServers().
  [Callback=FunctionOnly, NoInterfaceObject] interface MediaControllerServerInfoArraySuccessCallback {
    void onsuccess(MediaControllerServerInfo[] servers);
  };

Since: 5.0

Methods

onsuccess
Called when all registered media controller servers found.
void onsuccess(MediaControllerServerInfo[] servers);

Since: 5.0

Parameters:

  • servers: List of registered media controller servers.

2.9. MediaControllerSendCommandSuccessCallback

The MediaControllerSendCommandSuccessCallback interface that defines the success method for MediaControllerServerInfo.sendCommand().
  [Callback=FunctionOnly, NoInterfaceObject] interface MediaControllerSendCommandSuccessCallback {
    void onsuccess(object? data);
  };

Since: 5.0

Methods

onsuccess
Called when a response to the request is received.
void onsuccess(object? data);

Since: 5.0

Parameters:

  • data [nullable]: Response object sent by the command handler.

2.10. MediaControllerReceiveCommandCallback

The MediaControllerReceiveCommandCallback interface that defines the listener for custom communication from the client to the server.
  [Callback=FunctionOnly, NoInterfaceObject] interface MediaControllerReceiveCommandCallback {
    object? onsuccess(ApplicationId clientAppName, DOMString command, object data);
  };

Since: 5.0

Related functions:

Methods

onsuccess
Called when custom command is received by the server.
object? onsuccess(ApplicationId clientAppName, DOMString command, object data);

Since: 5.0

Parameters:

  • clientAppName: Client application id.
  • command: Custom command.
  • data: Response object.

Return value:

    object [nullable]: Data object which will be included in the reply to the author of the request.

2.11. MediaControllerServerStatusChangeCallback

The MediaControllerServerStatusChangeCallback interface that defines the listener for media controller server status changes.
  [Callback=FunctionOnly, NoInterfaceObject] interface MediaControllerServerStatusChangeCallback {
    void onsuccess(MediaControllerServerState status);
  };

Since: 5.0

Methods

onsuccess
Called when server status changed.
void onsuccess(MediaControllerServerState status);

Since: 5.0

Parameters:

  • status: Current server status.

2.12. MediaControllerPlaybackInfoChangeCallback

The MediaControllerPlaybackInfoChangeCallback interface that defines the listeners object for receiving media controller playback info changes from server.
  [Callback, NoInterfaceObject] interface MediaControllerPlaybackInfoChangeCallback {
    void onplaybackchanged(MediaControllerPlaybackState state, unsigned long long position);
    void onshufflemodechanged(boolean mode);
    void onrepeatmodechanged(boolean mode);
    void onmetadatachanged(MediaControllerMetadata metadata);
  };

Since: 5.0

Methods

onplaybackchanged
Called when playback state or position is changed.
void onplaybackchanged(MediaControllerPlaybackState state, unsigned long long position);

Since: 5.0

Parameters:

  • state: Current playback state.
  • position: Current playback position.
onshufflemodechanged
Called when shuffle mode is changed.
void onshufflemodechanged(boolean mode);

Since: 5.0

Parameters:

  • mode: Current shuffle mode.
onrepeatmodechanged
Called when repeat mode is changed.
void onrepeatmodechanged(boolean mode);

Since: 5.0

Parameters:

  • mode: Current repeat mode.
onmetadatachanged
Called when playback metadata is changed.
void onmetadatachanged(MediaControllerMetadata metadata);

Since: 5.0

Parameters:

  • metadata: Current playback metadata.

2.13. MediaControllerChangeRequestPlaybackInfoCallback

The MediaControllerChangeRequestPlaybackInfoCallback interface that defines the listeners object for receiving playback info change requests from client.
  [Callback, NoInterfaceObject] interface MediaControllerChangeRequestPlaybackInfoCallback {
    void onplaybackstaterequest(MediaControllerPlaybackState state);
    void onplaybackpositionrequest(unsigned long long position);
    void onshufflemoderequest(boolean mode);
    void onrepeatmoderequest(boolean mode);
  };

Since: 5.0

Methods

onplaybackstaterequest
Called when client requested playback state changes.
void onplaybackstaterequest(MediaControllerPlaybackState state);

Since: 5.0

Parameters:

  • state: Requested playback state.
onplaybackpositionrequest
Called when client requested playback position changes.
void onplaybackpositionrequest(unsigned long long position);

Since: 5.0

Parameters:

  • position: Requested playback position.
onshufflemoderequest
Called when client requested shuffle mode changes.
void onshufflemoderequest(boolean mode);

Since: 5.0

Parameters:

  • mode: Requested shuffle mode.
onrepeatmoderequest
Called when client requested repeat mode changes.
void onrepeatmoderequest(boolean mode);

Since: 5.0

Parameters:

  • mode: Requested repeat mode.

3. Full WebIDL

module MediaController {
  enum MediaControllerServerState { "ACTIVE", "INACTIVE" };
  enum MediaControllerPlaybackState { "PLAY", "PAUSE", "STOP", "NEXT", "PREV", "FORWARD", "REWIND" };
  Tizen implements MediaControllerObject;
  [NoInterfaceObject] interface MediaControllerObject {
    readonly attribute MediaControllerManager mediacontroller;
  };
  [NoInterfaceObject] interface MediaControllerManager {
    MediaControllerClient getClient() raises(WebAPIException);
    MediaControllerServer createServer() raises(WebAPIException);
  };
  [NoInterfaceObject] interface MediaControllerServer {
    readonly attribute MediaControllerPlaybackInfo playbackInfo;
    void updatePlaybackState(MediaControllerPlaybackState state) raises(WebAPIException);
    void updatePlaybackPosition(unsigned long long position) raises(WebAPIException);
    void updateShuffleMode(boolean mode) raises(WebAPIException);
    void updateRepeatMode(boolean mode) raises(WebAPIException);
    void updateMetadata(MediaControllerMetadata metadata) raises(WebAPIException);
    long addChangeRequestPlaybackInfoListener(MediaControllerChangeRequestPlaybackInfoCallback listener) raises(WebAPIException);
    void removeChangeRequestPlaybackInfoListener(long watchId) raises(WebAPIException);
    long addCommandListener(MediaControllerReceiveCommandCallback listener) raises(WebAPIException);
    void removeCommandListener(long watchId) raises(WebAPIException);
  };
  [NoInterfaceObject] interface MediaControllerClient {
    void findServers(MediaControllerServerInfoArraySuccessCallback successCallback, optional ErrorCallback? errorCallback)
                     raises(WebAPIException);
    MediaControllerServerInfo? getLatestServerInfo() raises(WebAPIException);
  };
  [NoInterfaceObject] interface MediaControllerServerInfo {
    readonly attribute ApplicationId name;
    readonly attribute MediaControllerServerState state;
    readonly attribute MediaControllerPlaybackInfo playbackInfo raises(WebAPIException);
    void sendPlaybackState(MediaControllerPlaybackState state, optional SuccessCallback? successCallback,
                           optional ErrorCallback? errorCallback) raises(WebAPIException);
    void sendPlaybackPosition(unsigned long long position, optional SuccessCallback? successCallback,
                              optional ErrorCallback? errorCallback) raises(WebAPIException);
    void sendShuffleMode(boolean mode, optional SuccessCallback? successCallback, optional ErrorCallback? errorCallback)
                         raises(WebAPIException);
    void sendRepeatMode(boolean mode, optional SuccessCallback? successCallback, optional ErrorCallback? errorCallback)
                        raises(WebAPIException);
    void sendCommand(DOMString command, object data, MediaControllerSendCommandSuccessCallback successCallback,
                     optional ErrorCallback? errorCallback) raises(WebAPIException);
    long addServerStatusChangeListener(MediaControllerServerStatusChangeCallback listener) raises(WebAPIException);
    void removeServerStatusChangeListener(long watchId) raises(WebAPIException);
    long addPlaybackInfoChangeListener(MediaControllerPlaybackInfoChangeCallback listener) raises(WebAPIException);
    void removePlaybackInfoChangeListener(long watchId) raises(WebAPIException);
  };
  [NoInterfaceObject] interface MediaControllerPlaybackInfo {
    readonly attribute MediaControllerPlaybackState state;
    readonly attribute unsigned long long position;
    readonly attribute boolean shuffleMode;
    readonly attribute boolean repeatMode;
    readonly attribute MediaControllerMetadata metadata;
  };
  [NoInterfaceObject] interface MediaControllerMetadata {
    attribute DOMString title;
    attribute DOMString artist;
    attribute DOMString album;
    attribute DOMString author;
    attribute DOMString genre;
    attribute DOMString duration;
    attribute DOMString date;
    attribute DOMString copyright;
    attribute DOMString description;
    attribute DOMString trackNum;
    attribute DOMString picture;
  };
  [Callback=FunctionOnly, NoInterfaceObject] interface MediaControllerServerInfoArraySuccessCallback {
    void onsuccess(MediaControllerServerInfo[] servers);
  };
  [Callback=FunctionOnly, NoInterfaceObject] interface MediaControllerSendCommandSuccessCallback {
    void onsuccess(object? data);
  };
  [Callback=FunctionOnly, NoInterfaceObject] interface MediaControllerReceiveCommandCallback {
    object? onsuccess(ApplicationId clientAppName, DOMString command, object data);
  };
  [Callback=FunctionOnly, NoInterfaceObject] interface MediaControllerServerStatusChangeCallback {
    void onsuccess(MediaControllerServerState status);
  };
  [Callback, NoInterfaceObject] interface MediaControllerPlaybackInfoChangeCallback {
    void onplaybackchanged(MediaControllerPlaybackState state, unsigned long long position);
    void onshufflemodechanged(boolean mode);
    void onrepeatmodechanged(boolean mode);
    void onmetadatachanged(MediaControllerMetadata metadata);
  };
  [Callback, NoInterfaceObject] interface MediaControllerChangeRequestPlaybackInfoCallback {
    void onplaybackstaterequest(MediaControllerPlaybackState state);
    void onplaybackpositionrequest(unsigned long long position);
    void onshufflemoderequest(boolean mode);
    void onrepeatmoderequest(boolean mode);
  };
};