Media Controller
You can establish communication between a media control server and a media control client. You can send commands from the client to the server, and the client can request updated metadata and playback information from the server.
The main media controller features include the following:
-
Updating and retrieving the playlist
You can create a playlist on the server side, and then retrieve that information on the client side.
-
Updating and retrieving information
You can update the playback information on the server side, and then retrieve that information on the client side.
The media control server provides current information about the registered application that you can send to the client.
When the client requests the information, the media control server updates the state information of an active application before transferring the data. If the application is not running when the client request arrives, the media control server transfers the latest information.
-
Sending and processing commands
You can send a command on the client side, and then process the command on the server side.
-
Setting and getting playback capability
You can set the playback capability on the server side, and then get that capability on the client side.
-
Media control metadata properties
You can set the metadata on the server side, and then get that metadata on the client side.
Prerequisites
To enable your application to use the media controller functionality, follow these steps:
- The application has to request permission by adding the following privilege to the
tizen-manifest.xml
file:
-
To use the Tizen.Multimedia.Remoting.MediaController class:
XMLCopy<privileges> <privilege>http://tizen.org/privilege/mediacontroller.client</privilege> </privileges>
-
To use the Tizen.Multimedia.Remoting.MediaControlServer class:
XMLCopy<privileges> <privilege>http://tizen.org/privilege/mediacontroller.server</privilege> </privileges>
-
To use the methods and properties of the Tizen.Multimedia.Remoting.MediaController, Tizen.Multimedia.Remoting.MediaControllerManager, and Tizen.Multimedia.Remoting.MediaControlServer classes, include the Tizen.Multimedia.Remoting namespace in your application:
C#Copyusing Tizen.Multimedia.Remoting;
-
Start the media control server using the
Start()
methods of the Tizen.Multimedia.Remoting.MediaControlServer class:C#CopyMediaControlServer.Start();
-
Create a new instance of the Tizen.Multimedia.Remoting.MediaControllerManager class and retrieve the currently active controllers and select one:
C#Copyvar mediaControllerManager = new MediaControllerManager(); var mediaController = mediaControllerManager.GetActiveControllers().First();
-
When server is no longer needed, stop the media control server using the
Stop()
method of the Tizen.Multimedia.Remoting.MediaControlServer class:C#CopyMediaControlServer.Stop();
Create and retrieve the playlist
To create a playlist from the server side and retrieve it on the client side, follow these steps:
-
To create a playlist from the server side, create a new instance of the Tizen.Multimedia.Remoting.MediaControlPlaylist class:
C#Copyvar playlist = new MediaControlPlaylist("MyFavorite");
You can also create playlist with metadata using the following code:
C#Copyvar playlist = new MediaControlPlaylist("MyFavorite", new Dictionary<string, MediaControlMetadata>() { {"Song1", new MediaControlMetadata() {Author = "Someone"} }, {"Song2", new MediaControlMetadata()} } );
-
To retrieve the playlist and metadata information on the client side, use the following code:
C#CopymediaController.PlaylistUpdated += (s, e) => { Log.Info("MC", $"Updated mode : {e.Mode}, Name : {e.Name}, Title : {e.Playlist.GetMetadata("IDX1").Title}"); };
Update and retrieve information
To update the playback information on the server side and to retrieve it on the client side, follow these steps:
-
To update the playback information on the server side, use
SetPlaybackState()
,SetInfoOfCurrentPlayingMedia()
methods of the Tizen.Multimedia.Remoting.MediaControlServer class:C#CopyMediaControlServer.SetPlaybackState(MediaControlPlaybackState.Playing, currentPosition); MediaControlServer.SetInfoOfCurrentPlayingMedia("MyFavorite", "IDX1");
-
To retrieve the playback information on the client side, use
GetPlaybackState()
, orGetPlaybackPosition()
methods of the Tizen.Multimedia.Remoting.MediaController class:C#CopyLog.info("MC", $"Playback state is {mediaController.GetPlaybackState()}, index is {mediacontroller.GetIndexOfCurrentPlayingMedia()}");
Send and process commands
To send a command from the client and to process it on the server side, follow these steps:
-
To send a command on the client side, use the
RequestAsync()
method of the Tizen.Multimedia.Remoting.MediaController class:C#CopymediaController.RequestAsync(new PlaybackCommand(MediaControlPlaybackCommand.Play));
-
To process the received command on the server side, add an event handler to the
PlaybackActionCommandReceived
event of the Tizen.Multimedia.Remoting.MediaControlServer class:C#CopyMediaControlServer.PlaybackActionCommandReceived += (s, e) => { Log.Info("MC", $"e.Command.Action : {e.Command.Action}"); MediaControlServer.Response(e.Command, (int)ErrorCode.None); }
To send a search command from the client and to process it on the server side, follow these steps:
-
To send a search command on the client side, use the
RequestAsync()
method of the Tizen.Multimedia.Remoting.MediaController class:C#Copyvar searchCondition = new MediaControlSearchCondition(MediaControlContentType.Image, MediaControlSearchCategory.Artist, "GD", null); mediaController.RequestAsync(new SearchCommand(searchCondition));
-
To process the received search command on the server side, add an event handler to the
SearchCommandReceived
event of the Tizen.Multimedia.Remoting.MediaControlServer class:C#CopyMediaControlServer.SearchCommandReceived += (s, e) => { foreach (var condition in e.Command.Conditions) { Log.Info("MC", $"{condition.Category}, {condition.ContentType}, {condition.Keyword}"); } MediaControlServer.Response(e.Command, (int)ErrorCode.None); };
To send a custom command from the server and to process it on the client side, follow these steps:
-
To send a search command on the server side, use the
RequestAsync()
method of the Tizen.Multimedia.Remoting.MediaControlServer class:C#CopyMediaControlServer.RequestAsync(new CustomCommand("CustomAction"));
-
To process the received custom command on the client side, add an event handler to the
CustomCommandReceived
event of the Tizen.Multimedia.Remoting.MediaController class:C#CopymediaController.CustomCommandReceived += (s, e) => { Log.Info("MC", $"{ e.Command.Action}"); mediaController.Response(e.Command, (int)ErrorCode.None); };
Set and get playback capability
To get playback capability from the client and to set it on the server side, follow these steps:
-
To set playback capability on the server side, use the
SetPlaybackCapability()
method of the Tizen.Multimedia.Remoting.MediaControlServer class:C#CopyMediaControlServer.SetPlaybackCapability(MediaControlPlaybackCommand.FastForward, MediaControlCapabilitySupport.NotSupported);
-
To get playback capability on the client side, use the
GetPlaybackCapability()
method of the Tizen.Multimedia.Remoting.MediaController class:C#Copyvar playCommandCapability = mediaController.GetPlaybackCapability(MediaControlPlaybackCommand.Play);
Set and get media control metadata
To get metadata from the client and to set it on the server side, follow these steps:
-
To set metadata on the server side, use the
SetMetadata()
method of the Tizen.Multimedia.Remoting.MediaControlServer class:C#CopyMediaControlServer.SetMetadata(new MediaControlMetadata { Title = "Song1", Artist = "Someone" });
-
To get metadata on the client side, use the
GetMetadata()
method of the Tizen.Multimedia.Remoting.MediaController class:C#Copyvar metadata = mediaController.GetMetadata();
The following table lists all the media control metadata properties the client can request from the server:
Table: Media control metadata properties
Property | Description |
---|---|
Title |
Title of the latest content in the media control server |
Artist |
Artist of the latest content in the media control server |
Album |
Album name of the latest content in the media control server |
Author |
Author of the latest content in the media control server |
Genre |
Genre of the latest content in the media control server |
Duration |
Duration of the latest content in the media control server |
Date |
Date of the latest content in the media control server |
Copyright |
Copyright of the latest content in the media control server |
Description |
Description of the latest content in the media control server |
TrackNumber |
Track number of the latest content in the media control server |
AlbumArtPath |
Album art of the latest content in the media control server |
Season |
Season information of the latest content in the media control server |
Episode |
Episode information of the latest content in the media control server |
Resolution |
Resolution of the latest content in the media control server |
Related information
- Dependencies
- Tizen 4.0 and Higher