From: hsgwon Date: Wed, 19 Sep 2018 08:18:25 +0000 (+0900) Subject: [MediaController] Add new APIs for event, capabilities and search. (#468) X-Git-Tag: 5.0.0.14562~31 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=951d037d36f9070466a50c854d0553cae1bd8348;p=platform%2Fcore%2Fcsapi%2Ftizenfx.git [MediaController] Add new APIs for event, capabilities and search. (#468) * [MediaController] Add new APIs for event, capabilities and search. --- diff --git a/src/Tizen.Multimedia.Remoting/Interop/Interop.Libraries.cs b/src/Tizen.Multimedia.Remoting/Interop/Interop.Libraries.cs index d479daa..35c3f8d 100644 --- a/src/Tizen.Multimedia.Remoting/Interop/Interop.Libraries.cs +++ b/src/Tizen.Multimedia.Remoting/Interop/Interop.Libraries.cs @@ -22,4 +22,3 @@ internal static partial class Interop public const string MediaController = "libcapi-media-controller.so.0"; } } - diff --git a/src/Tizen.Multimedia.Remoting/Interop/Interop.MediaControllerClient.cs b/src/Tizen.Multimedia.Remoting/Interop/Interop.MediaControllerClient.cs index becaf42..73e70de 100644 --- a/src/Tizen.Multimedia.Remoting/Interop/Interop.MediaControllerClient.cs +++ b/src/Tizen.Multimedia.Remoting/Interop/Interop.MediaControllerClient.cs @@ -44,6 +44,9 @@ internal static partial class Interop internal delegate void CommandCompletedCallback(string serverName, string requestId, MediaControllerError result, IntPtr bundleHandle, IntPtr userData); + [UnmanagedFunctionPointer(CallingConvention.Cdecl)] + internal delegate void CustomCommandReceivedCallback(string serverName, string requestId, string customEvent, IntPtr bundleHandle, IntPtr userData); + [DllImport(Libraries.MediaController, EntryPoint = "mc_client_create")] internal static extern MediaControllerError Create(out MediaControllerClientHandle handle); @@ -86,6 +89,13 @@ internal static partial class Interop [DllImport(Libraries.MediaController, EntryPoint = "mc_client_unset_cmd_reply_received_cb")] internal static extern MediaControllerError UnsetCommandCompletedCb(MediaControllerClientHandle handle); + [DllImport(Libraries.MediaController, EntryPoint = "mc_client_set_custom_event_received_cb")] + internal static extern MediaControllerError SetCustomEventCb(MediaControllerClientHandle handle, + CustomCommandReceivedCallback callback, IntPtr userData = default(IntPtr)); + + [DllImport(Libraries.MediaController, EntryPoint = "mc_client_unset_custom_event_received_cb")] + internal static extern MediaControllerError UnsetCustomEventCb(MediaControllerClientHandle handle); + [DllImport(Libraries.MediaController, EntryPoint = "mc_client_get_playback_state")] internal static extern MediaControllerError GetPlaybackState(IntPtr playback, out MediaControllerNativePlaybackState state); @@ -144,9 +154,106 @@ internal static partial class Interop string serverName, string playlistName, string index, MediaControllerNativePlaybackAction mode, ulong position, out string requestId); + [DllImport(Libraries.MediaController, EntryPoint = "mc_client_send_search_cmd")] + internal static extern MediaControllerError SendSearchCommand(MediaControllerClientHandle handle, + string serverName, IntPtr searchHandle, out string requestId); + + [DllImport(Libraries.MediaController, EntryPoint = "mc_client_send_event_reply")] + internal static extern MediaControllerError SendCustomEventReply(MediaControllerClientHandle handle, + string serverName, string requestId, int result, IntPtr bundleHandle); + [DllImport(Libraries.MediaController, EntryPoint = "mc_client_send_event_reply")] + internal static extern MediaControllerError SendCustomEventReplyBundle(MediaControllerClientHandle handle, + string serverName, string requestId, int result, SafeBundleHandle bundleHandle); + + [DllImport(Libraries.MediaController, EntryPoint = "mc_client_foreach_server")] internal static extern MediaControllerError ForeachActivatedServer(MediaControllerClientHandle handle, ActivatedServerCallback callback, IntPtr userData); + + [DllImport(Libraries.MediaController, EntryPoint = "mc_client_get_age_rating")] + internal static extern MediaControllerError GetAgeRating(IntPtr playbackHandle, out int rating); + + #region Capability + [UnmanagedFunctionPointer(CallingConvention.Cdecl)] + internal delegate void PlaybackCapabilityUpdatedCallback(string serverName, IntPtr capaHandle, + IntPtr userData = default(IntPtr)); + + [UnmanagedFunctionPointer(CallingConvention.Cdecl)] + internal delegate void ShuffleCapabilityUpdatedCallback(string serverName, MediaControlCapabilitySupport support, + IntPtr userData = default(IntPtr)); + + [UnmanagedFunctionPointer(CallingConvention.Cdecl)] + internal delegate void RepeatCapabilityUpdatedCallback(string serverName, MediaControlCapabilitySupport support, + IntPtr userData = default(IntPtr)); + + + [DllImport(Libraries.MediaController, EntryPoint = "mc_client_get_playback_content_type")] + internal static extern MediaControllerError GetPlaybackContentType(IntPtr playbackHandle, + out MediaControlContentType type); + + [DllImport(Libraries.MediaController, EntryPoint = "mc_client_get_server_icon")] + internal static extern MediaControllerError GetServerIcon(MediaControllerClientHandle clientHandle, + string serverName, out string uri); + + [DllImport(Libraries.MediaController, EntryPoint = "mc_client_get_server_playback_ability")] + internal static extern MediaControllerError GetPlaybackCapabilityHandle(MediaControllerClientHandle clientHandle, + string serverName, out IntPtr capaHandle); + + [DllImport(Libraries.MediaController, EntryPoint = "mc_client_get_server_shuffle_ability_support")] + internal static extern MediaControllerError GetShuffleCapability(MediaControllerClientHandle clientHandle, + string serverName, out MediaControlCapabilitySupport type); + + [DllImport(Libraries.MediaController, EntryPoint = "mc_client_get_server_repeat_ability_support")] + internal static extern MediaControllerError GetRepeatCapability(MediaControllerClientHandle clientHandle, + string serverName, out MediaControlCapabilitySupport type); + + [DllImport(Libraries.MediaController, EntryPoint = "mc_client_set_playback_ability_updated_cb")] + internal static extern MediaControllerError SetPlaybackCapabilityUpdatedCb(MediaControllerClientHandle clientHandle, + PlaybackCapabilityUpdatedCallback callback, IntPtr userData = default(IntPtr)); + + [DllImport(Libraries.MediaController, EntryPoint = "mc_client_unset_playback_ability_updated_cb")] + internal static extern MediaControllerError UnsetPlaybackCapabilityUpdatedCb(MediaControllerClientHandle clientHandle); + + [DllImport(Libraries.MediaController, EntryPoint = "mc_client_set_shuffle_ability_updated_cb")] + internal static extern MediaControllerError SetShuffleCapabilityUpdatedCb(MediaControllerClientHandle clientHandle, + ShuffleCapabilityUpdatedCallback callback, IntPtr userData = default(IntPtr)); + + [DllImport(Libraries.MediaController, EntryPoint = "mc_client_unset_shuffle_ability_updated_cb")] + internal static extern MediaControllerError UnsetShuffleCapabilityUpdatedCb(MediaControllerClientHandle clientHandle); + + [DllImport(Libraries.MediaController, EntryPoint = "mc_client_set_repeat_ability_updated_cb")] + internal static extern MediaControllerError SetRepeatCapabilityUpdatedCb(MediaControllerClientHandle clientHandle, + RepeatCapabilityUpdatedCallback callback, IntPtr userData = default(IntPtr)); + + [DllImport(Libraries.MediaController, EntryPoint = "mc_client_unset_repeat_ability_updated_cb")] + internal static extern MediaControllerError UnsetRepeatCapabilityUpdatedCb(MediaControllerClientHandle clientHandle); + + [DllImport(Libraries.MediaController, EntryPoint = "mc_playback_ability_clone")] + internal static extern MediaControllerError CloneCapability(IntPtr capaSrcHandle, out IntPtr capaDstHandle); + + [DllImport(Libraries.MediaController, EntryPoint = "mc_playback_ability_destroy")] + internal static extern MediaControllerError DestroyCapability(IntPtr capaHandle); + + [DllImport(Libraries.MediaController, EntryPoint = "mc_playback_action_is_supported")] + internal static extern MediaControllerError IsCapabilitySupported(IntPtr capaHandle, + MediaControllerNativePlaybackAction action, out MediaControlCapabilitySupport support); + #endregion Capability + + #region Search + [DllImport(Libraries.MediaController, EntryPoint = "mc_search_create")] + internal static extern MediaControllerError CreateSearchHandle(out IntPtr searchHandle); + + [DllImport(Libraries.MediaController, EntryPoint = "mc_search_set_condition")] + internal static extern MediaControllerError SetSearchCondition(IntPtr searchHandle, + MediaControlContentType type, MediaControlSearchCategory category, string keyword, IntPtr bundle); + + [DllImport(Libraries.MediaController, EntryPoint = "mc_search_set_condition")] + internal static extern MediaControllerError SetSearchConditionBundle(IntPtr searchHandle, + MediaControlContentType type, MediaControlSearchCategory category, string keyword, SafeBundleHandle bundle); + + [DllImport(Libraries.MediaController, EntryPoint = "mc_search_destroy")] + internal static extern MediaControllerError DestroySearchHandle(IntPtr searchHandle); + #endregion Search } internal class MediaControllerClientHandle : SafeHandle diff --git a/src/Tizen.Multimedia.Remoting/Interop/Interop.MediaControllerPlaylist.cs b/src/Tizen.Multimedia.Remoting/Interop/Interop.MediaControllerPlaylist.cs index 1d37ca5..8877da3 100644 --- a/src/Tizen.Multimedia.Remoting/Interop/Interop.MediaControllerPlaylist.cs +++ b/src/Tizen.Multimedia.Remoting/Interop/Interop.MediaControllerPlaylist.cs @@ -99,15 +99,15 @@ internal static partial class Interop string serverName, PlaylistCallback callback, IntPtr userData); [DllImport(Libraries.MediaController, EntryPoint = "mc_client_get_playlist_item_index")] - private static extern MediaControllerError GetPlaylistIndex(IntPtr handle, out IntPtr index); + private static extern MediaControllerError GetPlaylistIndex(IntPtr playbackHandle, out IntPtr index); - internal static string GetPlaylistIndex(IntPtr handle) + internal static string GetPlaylistIndex(IntPtr playbackHandle) { IntPtr valuePtr = IntPtr.Zero; try { - GetPlaylistIndex(handle, out valuePtr).ThrowIfError($"Failed to get playlist."); + GetPlaylistIndex(playbackHandle, out valuePtr).ThrowIfError($"Failed to get playlist."); return Marshal.PtrToStringAnsi(valuePtr); } finally @@ -116,6 +116,26 @@ internal static partial class Interop } } + [DllImport(Libraries.MediaController, EntryPoint = "mc_client_get_playlist_item_info")] + internal static extern MediaControllerError GetPlaylistInfo(IntPtr playbackHandle, out IntPtr playlistName, out IntPtr index); + + internal static string GetPlaylistInfo(IntPtr playbackHandle) + { + IntPtr playlistName = IntPtr.Zero; + IntPtr index = IntPtr.Zero; + + try + { + GetPlaylistInfo(playbackHandle, out playlistName, out index).ThrowIfError($"Failed to get playlist info."); + return Marshal.PtrToStringAnsi(playlistName); + } + finally + { + Tizen.Multimedia.LibcSupport.Free(playlistName); + Tizen.Multimedia.LibcSupport.Free(index); + } + } + [DllImport(Libraries.MediaController, EntryPoint = "mc_playlist_get_name")] private static extern MediaControllerError GetPlaylistName(IntPtr handle, out IntPtr name); diff --git a/src/Tizen.Multimedia.Remoting/Interop/Interop.MediaControllerServer.cs b/src/Tizen.Multimedia.Remoting/Interop/Interop.MediaControllerServer.cs index ce0fe1c..ee4a97b 100644 --- a/src/Tizen.Multimedia.Remoting/Interop/Interop.MediaControllerServer.cs +++ b/src/Tizen.Multimedia.Remoting/Interop/Interop.MediaControllerServer.cs @@ -53,7 +53,22 @@ internal static partial class Interop string requestId, string customCommand, IntPtr bundleHandle, IntPtr userData); [UnmanagedFunctionPointer(CallingConvention.Cdecl)] - internal delegate void PlaylistCallback(IntPtr handle, IntPtr userData); + internal delegate bool PlaylistCallback(IntPtr handle, IntPtr userData); + + [UnmanagedFunctionPointer(CallingConvention.Cdecl)] + internal delegate bool ActivatedClientCallback(string clientName, IntPtr userData); + + [UnmanagedFunctionPointer(CallingConvention.Cdecl)] + internal delegate void CommandCompletedCallback(string clientName, string requestId, MediaControllerError result, IntPtr bundleHandle, + IntPtr userData = default(IntPtr)); + + [UnmanagedFunctionPointer(CallingConvention.Cdecl)] + internal delegate void SearchCommandReceivedCallback(string clientName, string requestId, IntPtr searchHandle, + IntPtr userData = default(IntPtr)); + + [UnmanagedFunctionPointer(CallingConvention.Cdecl)] + internal delegate bool SearchItemCallback(MediaControlContentType type, MediaControlSearchCategory category, + string keyword, IntPtr bundleHandle, IntPtr userData = default(IntPtr)); [DllImport(Libraries.MediaController, EntryPoint = "mc_server_create")] @@ -135,6 +150,13 @@ internal static partial class Interop [DllImport(Libraries.MediaController, EntryPoint = "mc_server_unset_custom_cmd_received_cb")] internal static extern MediaControllerError UnsetCustomCommandReceivedCb(IntPtr handle); + [DllImport(Libraries.MediaController, EntryPoint = "mc_server_set_search_cmd_received_cb")] + internal static extern MediaControllerError SetSearchCommandReceivedCb(IntPtr handle, + SearchCommandReceivedCallback callback, IntPtr userData = default(IntPtr)); + + [DllImport(Libraries.MediaController, EntryPoint = "mc_server_unset_search_cmd_received_cb")] + internal static extern MediaControllerError UnsetSearchCommandReceivedCb(IntPtr handle); + [DllImport(Libraries.MediaController, EntryPoint = "mc_server_send_cmd_reply")] internal static extern MediaControllerError SendCommandReplyBundle(IntPtr handle, string appId, string requestID, int result, SafeBundleHandle bundleHandle); @@ -174,5 +196,65 @@ internal static partial class Interop // Playlist API. but this need to server handle so have to be here. [DllImport(Libraries.MediaController, EntryPoint = "mc_server_get_playlist")] internal static extern MediaControllerError GetPlaylistHandle(IntPtr handle, string name, out IntPtr playbackHandle); + + [DllImport(Libraries.MediaController, EntryPoint = "mc_server_foreach_client")] + internal static extern MediaControllerError ForeachActivatedClient(IntPtr handle, ActivatedClientCallback callback, + IntPtr userData = default(IntPtr)); + + [DllImport(Libraries.MediaController, EntryPoint = "mc_server_send_custom_event")] + internal static extern MediaControllerError SendCustomEvent(IntPtr handle, string appId, string customEvent, + IntPtr bundle, out string requestId); + + [DllImport(Libraries.MediaController, EntryPoint = "mc_server_send_custom_event")] + internal static extern MediaControllerError SendCustomEventBundle(IntPtr handle, string appId, string customEvent, + SafeBundleHandle bundle, out string requestId); + + [DllImport(Libraries.MediaController, EntryPoint = "mc_server_set_event_reply_received_cb")] + internal static extern MediaControllerError SetEventReceivedCb(IntPtr handle, CommandCompletedCallback callback, + IntPtr userData = default(IntPtr)); + + [DllImport(Libraries.MediaController, EntryPoint = "mc_server_unset_event_reply_received_cb")] + internal static extern MediaControllerError UnsetEventReceivedCb(IntPtr handle); + + [DllImport(Libraries.MediaController, EntryPoint = "mc_server_set_content_age_rating")] + internal static extern MediaControllerError SetAgeRating(IntPtr handle, int rating); + + + #region Capability + [DllImport(Libraries.MediaController, EntryPoint = "mc_server_set_playback_content_type")] + internal static extern MediaControllerError SetPlaybackContentType(IntPtr serverHandle, + MediaControlContentType type); + + [DllImport(Libraries.MediaController, EntryPoint = "mc_server_set_icon")] + internal static extern MediaControllerError SetIconPath(IntPtr serverHandle, string uri); + + [DllImport(Libraries.MediaController, EntryPoint = "mc_server_set_playback_ability")] + internal static extern MediaControllerError SetPlaybackCapability(IntPtr serverHandle, + MediaControllerNativePlaybackAction action, MediaControlCapabilitySupport support); + + [DllImport(Libraries.MediaController, EntryPoint = "mc_server_update_playback_ability")] + internal static extern MediaControllerError SaveAndNotifyPlaybackCapabilityUpdated(IntPtr serverHandle); + + [DllImport(Libraries.MediaController, EntryPoint = "mc_server_set_shuffle_ability")] + internal static extern MediaControllerError SetShuffleModeCapability(IntPtr serverHandle, + MediaControlCapabilitySupport support); + + [DllImport(Libraries.MediaController, EntryPoint = "mc_server_set_repeat_ability")] + internal static extern MediaControllerError SetRepeatModeCapability(IntPtr serverHandle, + MediaControlCapabilitySupport support); + #endregion Capability + + #region Search + [DllImport(Libraries.MediaController, EntryPoint = "mc_search_foreach")] + internal static extern MediaControllerError ForeachSearchCondition(IntPtr serverHandle, + SearchItemCallback callback, IntPtr userData = default(IntPtr)); + + [DllImport(Libraries.MediaController, EntryPoint = "mc_search_clone")] + internal static extern MediaControllerError CloneSearchHandle(IntPtr srcHandle, out IntPtr dstHandle); + + [DllImport(Libraries.MediaController, EntryPoint = "mc_search_destroy")] + internal static extern MediaControllerError DestroySearchHandle(IntPtr searchHandle); + + #endregion Search } } diff --git a/src/Tizen.Multimedia.Remoting/MediaController/CommandCompletedEventArgs.cs b/src/Tizen.Multimedia.Remoting/MediaController/CommandCompletedEventArgs.cs index a78351d..0741fd0 100644 --- a/src/Tizen.Multimedia.Remoting/MediaController/CommandCompletedEventArgs.cs +++ b/src/Tizen.Multimedia.Remoting/MediaController/CommandCompletedEventArgs.cs @@ -20,7 +20,8 @@ using Tizen.Applications; namespace Tizen.Multimedia.Remoting { /// - /// Provides data for the event. + /// Provides data for the or + /// event. /// /// 5 internal class CommandCompletedEventArgs : EventArgs diff --git a/src/Tizen.Multimedia.Remoting/MediaController/CustomCommandReceivedEventArgs.cs b/src/Tizen.Multimedia.Remoting/MediaController/CustomCommandReceivedEventArgs.cs index 9c65aba..e18594f 100644 --- a/src/Tizen.Multimedia.Remoting/MediaController/CustomCommandReceivedEventArgs.cs +++ b/src/Tizen.Multimedia.Remoting/MediaController/CustomCommandReceivedEventArgs.cs @@ -15,12 +15,12 @@ */ using System; -using Tizen.Applications; namespace Tizen.Multimedia.Remoting { /// - /// Provides data for the event. + /// Provides data for the or + /// event. /// /// 5 public class CustomCommandReceivedEventArgs : EventArgs diff --git a/src/Tizen.Multimedia.Remoting/MediaController/MediaControlCommand.cs b/src/Tizen.Multimedia.Remoting/MediaController/MediaControlCommand.cs index 769d00b..9f7d88d 100644 --- a/src/Tizen.Multimedia.Remoting/MediaController/MediaControlCommand.cs +++ b/src/Tizen.Multimedia.Remoting/MediaController/MediaControlCommand.cs @@ -16,6 +16,7 @@ using Tizen.Applications; using System; +using System.Collections.Generic; using NativeClient = Interop.MediaControllerClient; using NativeServer = Interop.MediaControllerServer; using NativeClientHandle = Interop.MediaControllerClientHandle; @@ -30,58 +31,110 @@ namespace Tizen.Multimedia.Remoting { private string _requestId; - internal NativeClientHandle _clientHandle; - - private string _clientId; - /// - /// The server id. + /// The id for command receiver. /// /// 5 - protected string _serverId; + protected string ReceiverId { get; private set; } /// /// Initializes a base class. /// + /// 5 protected Command() { } - internal abstract string Request(); - - internal void Response(IntPtr handle, int result, Bundle bundle) - { - if (bundle != null) - { - NativeServer.SendCommandReplyBundle(handle, _clientId, _requestId, result, bundle.SafeBundleHandle) - .ThrowIfError("Failed to response command."); - } - else - { - NativeServer.SendCommandReply(handle, _clientId, _requestId, result, IntPtr.Zero) - .ThrowIfError("Failed to response command."); - } - } - /// /// Sets the server information. /// - /// The client handle. - /// The server Id that receives command. - internal void SetServerInfo(NativeClientHandle clientrHandle, string serverId) + /// The receiver Id that receives command. + internal void SetRequestInformation(string receiverId) { - _serverId = serverId; - _clientHandle = clientrHandle; + ReceiverId = receiverId; } /// /// Sets the client information. /// - /// The client Id that will be received response. + /// The receiver Id that receives response for command. /// The request Id for each command. - internal void SetClientInfo(string clientId, string requestId) + internal void SetResponseInformation(string receiverId, string requestId) { - _clientId = clientId; + ReceiverId = receiverId; _requestId = requestId; } + + /// + /// Requests command to server. + /// + /// The request id for each command. + internal abstract string Request(NativeClientHandle clientHandle); + + /// + /// Requests command to client. + /// + /// + /// The request id for each command. + internal virtual string Request(IntPtr serverHandle) => throw new NotImplementedException(); + + /// + /// Represents a method that is called when an response command completes. + /// + /// 5 + protected virtual void OnResponseCompleted() { } + + /// + /// Responses command to the client. + /// + /// The server handle. + /// The result of each command. + /// The extra data. + internal void Response(IntPtr serverHandle, int result, Bundle bundle) + { + try + { + if (bundle != null) + { + NativeServer.SendCommandReplyBundle(serverHandle, ReceiverId, _requestId, result, bundle.SafeBundleHandle) + .ThrowIfError("Failed to response command."); + } + else + { + NativeServer.SendCommandReply(serverHandle, ReceiverId, _requestId, result, IntPtr.Zero) + .ThrowIfError("Failed to response command."); + } + } + finally + { + OnResponseCompleted(); + } + } + + /// + /// Responses command to the server. + /// + /// The client handle. + /// The result of each command. + /// The extra data. + internal void Response(NativeClientHandle clientHandle, int result, Bundle bundle) + { + try + { + if (bundle != null) + { + NativeClient.SendCustomEventReplyBundle(clientHandle, ReceiverId, _requestId, result, bundle.SafeBundleHandle) + .ThrowIfError("Failed to response event."); + } + else + { + NativeClient.SendCustomEventReply(clientHandle, ReceiverId, _requestId, result, IntPtr.Zero) + .ThrowIfError("Failed to repose event."); + } + } + finally + { + OnResponseCompleted(); + } + } } @@ -106,11 +159,11 @@ namespace Tizen.Multimedia.Remoting /// 5 public MediaControlPlaybackCommand Action { get; } - internal override string Request() + internal override string Request(NativeClientHandle clientHandle) { ValidationUtil.ValidateEnum(typeof(MediaControlPlaybackCommand), Action, nameof(MediaControlPlaybackCommand)); - NativeClient.SendPlaybackActionCommand(_clientHandle, _serverId, Action.ToNative(), out string requestId) + NativeClient.SendPlaybackActionCommand(clientHandle, ReceiverId, Action.ToNative(), out string requestId) .ThrowIfError("Failed to send playback command."); return requestId; @@ -138,9 +191,9 @@ namespace Tizen.Multimedia.Remoting /// 5 public ulong Position { get; } - internal override string Request() + internal override string Request(NativeClientHandle clientHandle) { - NativeClient.SendPlaybackPositionCommand(_clientHandle, _serverId, Position, out string requestId) + NativeClient.SendPlaybackPositionCommand(clientHandle, ReceiverId, Position, out string requestId) .ThrowIfError("Failed to send playback position command."); return requestId; @@ -167,8 +220,8 @@ namespace Tizen.Multimedia.Remoting public PlaylistCommand(MediaControlPlaybackCommand action, string playlistName, string index, ulong position) { Action = action; - Index = index ?? throw new ArgumentNullException("Playlist index is not set."); - Name = playlistName ?? throw new ArgumentNullException("Playlist name is not set."); + Index = index ?? throw new ArgumentNullException(nameof(index)); + Name = playlistName ?? throw new ArgumentNullException(nameof(playlistName)); Position = position; } @@ -180,7 +233,7 @@ namespace Tizen.Multimedia.Remoting /// The index of the media in the playlist. /// cannot be converted to number. /// - /// or is not set. + /// or is null. /// /// 5 public PlaylistCommand(MediaControlPlaybackCommand action, string playlistName, string index) @@ -212,11 +265,11 @@ namespace Tizen.Multimedia.Remoting /// 5 public string Name { get; } - internal override string Request() + internal override string Request(NativeClientHandle clientHandle) { ValidationUtil.ValidateEnum(typeof(MediaControlPlaybackCommand), Action, nameof(MediaControlPlaybackCommand)); - NativeClient.SendPlaylistCommand(_clientHandle, _serverId, Name, Index, Action.ToNative(), + NativeClient.SendPlaylistCommand(clientHandle, ReceiverId, Name, Index, Action.ToNative(), Position, out string requestId).ThrowIfError("Failed to send playlist command."); return requestId; @@ -244,11 +297,11 @@ namespace Tizen.Multimedia.Remoting /// public bool Enabled { get; } - internal override string Request() + internal override string Request(NativeClientHandle clientHandle) { var mode = Enabled ? MediaControllerNativeShuffleMode.On : MediaControllerNativeShuffleMode.Off; - NativeClient.SendShuffleModeCommand(_clientHandle, _serverId, mode, out string requestId). + NativeClient.SendShuffleModeCommand(clientHandle, ReceiverId, mode, out string requestId). ThrowIfError("Failed to send playback shuffle command."); return requestId; @@ -277,11 +330,11 @@ namespace Tizen.Multimedia.Remoting /// 5 public MediaControlRepeatMode Mode { get; } - internal override string Request() + internal override string Request(NativeClientHandle clientHandle) { ValidationUtil.ValidateEnum(typeof(MediaControlRepeatMode), Mode, nameof(MediaControlRepeatMode)); - NativeClient.SendRepeatModeCommand(_clientHandle, _serverId, Mode.ToNative(), out string requestId). + NativeClient.SendRepeatModeCommand(clientHandle, ReceiverId, Mode.ToNative(), out string requestId). ThrowIfError("Failed to send playback repeat command."); return requestId; @@ -291,6 +344,7 @@ namespace Tizen.Multimedia.Remoting /// /// Provides a means to to send custom commands. /// + /// This command can be used by both client and server to send predefined command or data. /// 5 public sealed class CustomCommand : Command { @@ -301,7 +355,7 @@ namespace Tizen.Multimedia.Remoting /// 5 public CustomCommand(string action) { - Action = action ?? throw new ArgumentNullException("Custom command is not set."); + Action = action ?? throw new ArgumentNullException(nameof(action)); } /// @@ -328,22 +382,199 @@ namespace Tizen.Multimedia.Remoting /// 5 public Bundle Bundle { get; } - internal override string Request() + internal override string Request(NativeClientHandle clientHandle) { string requestId = null; if (Bundle != null) { - NativeClient.SendCustomCommandBundle(_clientHandle, _serverId, Action, Bundle.SafeBundleHandle, out requestId). + NativeClient.SendCustomCommandBundle(clientHandle, ReceiverId, Action, Bundle.SafeBundleHandle, out requestId). ThrowIfError("Failed to send custom command."); } else { - NativeClient.SendCustomCommand(_clientHandle, _serverId, Action, IntPtr.Zero, out requestId). + NativeClient.SendCustomCommand(clientHandle, ReceiverId, Action, IntPtr.Zero, out requestId). ThrowIfError("Failed to send custom command."); } return requestId; } + + internal override string Request(IntPtr serverHandle) + { + string requestId = null; + + if (Bundle != null) + { + NativeServer.SendCustomEventBundle(serverHandle, ReceiverId, Action, Bundle.SafeBundleHandle, out requestId) + .ThrowIfError("Failed to send costom event."); + } + else + { + NativeServer.SendCustomEvent(serverHandle, ReceiverId, Action, IntPtr.Zero, out requestId) + .ThrowIfError("Failed to send costom event."); + } + + return requestId; + } + } + + /// + /// Provides a means to to send search commands. + /// + /// 5 + public sealed class SearchCommand : Command + { + private readonly IntPtr _searchHandle; + + /// + /// Initializes a new instance of the class. + /// + /// User can search maximum 20 items once. + /// is not set. + /// + /// is greater than maximum value(20).
+ /// -or-
+ /// is less than 1. + ///
+ /// An internal error occurs. + /// The set of . + /// 5 + public SearchCommand(List conditions) + { + if (conditions == null) + { + throw new ArgumentNullException(nameof(conditions)); + } + if (conditions.Count <= 0 || conditions.Count > 20) + { + var errMessage = $"Invalid number of search conditions. : {conditions.Count}. " + + $"Valid range is 1 ~ 20."; + throw new ArgumentException(errMessage); + } + + NativeClient.CreateSearchHandle(out _searchHandle).ThrowIfError("Failed to create search handle."); + + try + { + foreach (var condition in conditions) + { + if (condition.Bundle != null) + { + NativeClient.SetSearchConditionBundle(_searchHandle, condition.ContentType, condition.Category, + condition.Keyword, condition.Bundle.SafeBundleHandle). + ThrowIfError("Failed to set search condition."); + } + else + { + NativeClient.SetSearchCondition(_searchHandle, condition.ContentType, condition.Category, + condition.Keyword, IntPtr.Zero). + ThrowIfError("Failed to set search condition."); + } + } + } + catch + { + if (_searchHandle != IntPtr.Zero) + { + NativeClient.DestroySearchHandle(_searchHandle).ThrowIfError("Failed to destroy search handle"); + } + throw; + } + } + + /// + /// Initializes a new instance of the class. + /// + /// An internal error occurs. + /// The set of . + /// 5 + public SearchCommand(MediaControlSearchCondition condition) + { + NativeClient.CreateSearchHandle(out _searchHandle).ThrowIfError("Failed to create search handle."); + + try + { + if (condition.Bundle != null) + { + NativeClient.SetSearchConditionBundle(_searchHandle, condition.ContentType, condition.Category, + condition.Keyword, condition.Bundle.SafeBundleHandle). + ThrowIfError("Failed to set search condition."); + } + else + { + NativeClient.SetSearchCondition(_searchHandle, condition.ContentType, condition.Category, + condition.Keyword, IntPtr.Zero). + ThrowIfError("Failed to set search condition."); + } + } + catch + { + if (_searchHandle != IntPtr.Zero) + { + NativeClient.DestroySearchHandle(_searchHandle).ThrowIfError("Failed to destroy search handle"); + } + throw; + } + } + + internal SearchCommand(List conditions, IntPtr searchHandle) + { + _searchHandle = searchHandle; + + try + { + foreach (var condition in conditions) + { + if (condition.Bundle != null) + { + NativeClient.SetSearchConditionBundle(_searchHandle, condition.ContentType, condition.Category, + condition.Keyword, condition.Bundle.SafeBundleHandle). + ThrowIfError("Failed to set search condition."); + } + else + { + NativeClient.SetSearchCondition(_searchHandle, condition.ContentType, condition.Category, + condition.Keyword, IntPtr.Zero). + ThrowIfError("Failed to set search condition."); + } + } + } + catch + { + if (_searchHandle != IntPtr.Zero) + { + NativeClient.DestroySearchHandle(_searchHandle).ThrowIfError("Failed to destroy search handle"); + } + throw; + } + } + + internal override string Request(NativeClientHandle clientHandle) + { + NativeClient.SendSearchCommand(clientHandle, ReceiverId, _searchHandle, out string requestId). + ThrowIfError("Failed to send search command."); + + if (_searchHandle != IntPtr.Zero) + { + NativeClient.DestroySearchHandle(_searchHandle).ThrowIfError("Failed to destroy search handle"); + } + + return requestId; + } + + /// + /// Represents a method that is called when an response command completes. + /// + /// 5 + protected override void OnResponseCompleted() + { + base.OnResponseCompleted(); + + if (_searchHandle != IntPtr.Zero) + { + NativeClient.DestroySearchHandle(_searchHandle).ThrowIfError("Failed to destroy search handle"); + } + } } } \ No newline at end of file diff --git a/src/Tizen.Multimedia.Remoting/MediaController/EnumExtensions.cs b/src/Tizen.Multimedia.Remoting/MediaController/MediaControlEnums.cs similarity index 57% rename from src/Tizen.Multimedia.Remoting/MediaController/EnumExtensions.cs rename to src/Tizen.Multimedia.Remoting/MediaController/MediaControlEnums.cs index 2d9fc59..241dd12 100644 --- a/src/Tizen.Multimedia.Remoting/MediaController/EnumExtensions.cs +++ b/src/Tizen.Multimedia.Remoting/MediaController/MediaControlEnums.cs @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved + * Copyright (c) 2018 Samsung Electronics Co., Ltd All Rights Reserved * * Licensed under the Apache License, Version 2.0 (the License); * you may not use this file except in compliance with the License. @@ -19,6 +19,234 @@ using System.Diagnostics; namespace Tizen.Multimedia.Remoting { + /// + /// Specifies the playlist mode. + /// + /// 5 + public enum MediaControlPlaylistMode + { + /// + /// Playlist is created or update. + /// + Updated, + + /// + /// Playlist is removed. + /// + Removed, + } + + /// + /// Specifies the repeat mode. + /// + /// 4 + public enum MediaControlRepeatMode + { + /// + /// Off. + /// + Off, + + /// + /// On. + /// + On, + + /// + /// One media. + /// + /// 5 + OneMedia + } + + /// + /// Specifies playback commands. + /// + /// 4 + public enum MediaControlPlaybackCommand + { + /// + /// Play. + /// + Play, + + /// + /// Pause. + /// + Pause, + + /// + /// Stop. + /// + Stop, + + /// + /// Skip to next. + /// + Next, + + /// + /// Skip to previous. + /// + Previous, + + /// + /// Fast forward. + /// + FastForward, + + /// + /// Rewind. + /// + Rewind, + + /// + /// Toggle play/pause. + /// + /// 5 + Toggle, + } + + /// + /// Specifies playback states. + /// + /// 4 + public enum MediaControlPlaybackState + { + /// + /// Unknown; no state is set. + /// + None, + + /// + /// Playing. + /// + Playing, + + /// + /// Paused. + /// + Paused, + + /// + /// Stopped. + /// + Stopped, + + /// + /// Fast forwarding. + /// + FastForwarding, + + /// + /// Rewinding. + /// + Rewinding, + + /// + /// Skipping to the next item. + /// + /// 5 + MovingToNext, + + /// + /// Skipping to the previous item. + /// + /// 5 + MovingToPrevious, + } + + /// + /// Specifies the support type of media control capability. + /// + /// 5 + public enum MediaControlCapabilitySupport + { + /// + /// Supported. + /// + Supported, + + /// + /// Not supported. + /// + NotSupported, + + /// + /// There's no support info in server. + /// + NotDecided + } + + /// + /// Specifies the content type. + /// + /// 5 + public enum MediaControlContentType + { + /// + /// Image type. + /// + Image, + + /// + /// Video type. + /// + Video, + + /// + /// Music type. + /// + Music, + + /// + /// Other type. + /// + Other, + + /// + /// There's no content type info in server. + /// + NotDecided + } + + /// + /// Specifies the search category. + /// + /// 5 + public enum MediaControlSearchCategory + { + /// + /// Search by all category. + /// + All, + + /// + /// Search by content title. + /// + Title, + + /// + /// Search by content artist. + /// + Artist, + + /// + /// Search by content album. + /// + Album, + + /// + /// Search by content genre. + /// + Genre, + + /// + /// Search by TPO(Time Place Occasion). + /// + Tpo + } + internal static class EnumExtensions { internal static MediaControlPlaybackState ToPublic(this MediaControllerNativePlaybackState nativeState) @@ -92,14 +320,6 @@ namespace Tizen.Multimedia.Remoting return MediaControllerNativePlaybackAction.Play; } - internal static MediaControllerNativeRepeatMode ToNative(this MediaControlRepeatMode mode) - { - Debug.Assert(Enum.IsDefined(typeof(MediaControlRepeatMode), mode)); - - return mode == MediaControlRepeatMode.Off ? MediaControllerNativeRepeatMode.On : - (mode == MediaControlRepeatMode.On ? MediaControllerNativeRepeatMode.Off : MediaControllerNativeRepeatMode.OneMedia); - } - internal static MediaControlRepeatMode ToPublic(this MediaControllerNativeRepeatMode mode) { Debug.Assert(Enum.IsDefined(typeof(MediaControllerNativeRepeatMode), mode)); @@ -107,5 +327,13 @@ namespace Tizen.Multimedia.Remoting return mode == MediaControllerNativeRepeatMode.Off ? MediaControlRepeatMode.On : (mode == MediaControllerNativeRepeatMode.On ? MediaControlRepeatMode.Off : MediaControlRepeatMode.OneMedia); } + + internal static MediaControllerNativeRepeatMode ToNative(this MediaControlRepeatMode mode) + { + Debug.Assert(Enum.IsDefined(typeof(MediaControlRepeatMode), mode)); + + return mode == MediaControlRepeatMode.Off ? MediaControllerNativeRepeatMode.On : + (mode == MediaControlRepeatMode.On ? MediaControllerNativeRepeatMode.Off : MediaControllerNativeRepeatMode.OneMedia); + } } } \ No newline at end of file diff --git a/src/Tizen.Multimedia.Remoting/MediaController/MediaControlPlaybackCommand.cs b/src/Tizen.Multimedia.Remoting/MediaController/MediaControlPlaybackCommand.cs deleted file mode 100644 index 1a924d4..0000000 --- a/src/Tizen.Multimedia.Remoting/MediaController/MediaControlPlaybackCommand.cs +++ /dev/null @@ -1,66 +0,0 @@ -/* - * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved - * - * Licensed under the Apache License, Version 2.0 (the License); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an AS IS BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -namespace Tizen.Multimedia.Remoting -{ - /// - /// Specifies playback commands. - /// - /// 4 - public enum MediaControlPlaybackCommand - { - /// - /// Play. - /// - Play, - - /// - /// Pause. - /// - Pause, - - /// - /// Stop. - /// - Stop, - - /// - /// Skip to next. - /// - Next, - - /// - /// Skip to previous. - /// - Previous, - - /// - /// Fast forward. - /// - FastForward, - - /// - /// Rewind. - /// - Rewind, - - /// - /// Toggle play/pause. - /// - /// 5 - Toggle, - } -} \ No newline at end of file diff --git a/src/Tizen.Multimedia.Remoting/MediaController/MediaControlPlaylist.cs b/src/Tizen.Multimedia.Remoting/MediaController/MediaControlPlaylist.cs index 163a249..5cc1af6 100644 --- a/src/Tizen.Multimedia.Remoting/MediaController/MediaControlPlaylist.cs +++ b/src/Tizen.Multimedia.Remoting/MediaController/MediaControlPlaylist.cs @@ -29,7 +29,7 @@ namespace Tizen.Multimedia.Remoting public class MediaControlPlaylist : IDisposable { private IntPtr _handle; - private Dictionary _metadata = null; + private Dictionary _metadata = new Dictionary(); /// /// Initializes a new instance of the class by server side. diff --git a/src/Tizen.Multimedia.Remoting/MediaController/MediaControlSearchCondition.cs b/src/Tizen.Multimedia.Remoting/MediaController/MediaControlSearchCondition.cs new file mode 100644 index 0000000..4ed37ba --- /dev/null +++ b/src/Tizen.Multimedia.Remoting/MediaController/MediaControlSearchCondition.cs @@ -0,0 +1,84 @@ +/* + * Copyright (c) 2018 Samsung Electronics Co., Ltd All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the License); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an AS IS BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +using System; +using System.Collections.Generic; +using Tizen.Applications; +using NativeClient = Interop.MediaControllerClient; +using NativeServer = Interop.MediaControllerServer; +using NativePlaylist = Interop.MediaControllerPlaylist; + +namespace Tizen.Multimedia.Remoting +{ + /// + /// Represents the search conditions. + /// + /// 5 + public class MediaControlSearchCondition + { + /// + /// Initializes a new instance of the class. + /// + /// 5 + public MediaControlSearchCondition(MediaControlContentType type, MediaControlSearchCategory category, + string keyword, Bundle bundle) + : this (type, keyword, bundle) + { + ValidationUtil.ValidateEnum(typeof(MediaControlSearchCategory), category, nameof(category)); + + Category = category; + } + + /// + /// Initializes a new instance of the class. + /// + /// The will be set internally by . + /// 5 + public MediaControlSearchCondition(MediaControlContentType type, string keyword, Bundle bundle) + { + ValidationUtil.ValidateEnum(typeof(MediaControlContentType), type, nameof(type)); + + Category = MediaControlSearchCategory.All; + ContentType = type; + Keyword = keyword ?? throw new ArgumentNullException(nameof(keyword)); + Bundle = bundle; + } + + /// + /// Gets the search content type. + /// + /// 5 + public MediaControlContentType ContentType { get; } + + /// + /// Gets the search category. + /// + /// 5 + public MediaControlSearchCategory Category { get; } + + /// + /// Gets the search keyword. + /// + /// 5 + public string Keyword { get; } + + /// + /// Gets the extra data. + /// + /// 5 + public Bundle Bundle { get; } + } +} \ No newline at end of file diff --git a/src/Tizen.Multimedia.Remoting/MediaController/MediaControlServer.Events.cs b/src/Tizen.Multimedia.Remoting/MediaController/MediaControlServer.Events.cs index 951ad77..8b8b689 100644 --- a/src/Tizen.Multimedia.Remoting/MediaController/MediaControlServer.Events.cs +++ b/src/Tizen.Multimedia.Remoting/MediaController/MediaControlServer.Events.cs @@ -16,6 +16,7 @@ using Tizen.Applications; using System; +using System.Collections.Generic; using Native = Interop.MediaControllerServer; namespace Tizen.Multimedia.Remoting @@ -29,6 +30,8 @@ namespace Tizen.Multimedia.Remoting private static Native.ShuffleModeCommandReceivedCallback _shuffleModeCommandCallback; private static Native.RepeatModeCommandReceivedCallback _repeatModeCommandCallback; private static Native.CustomCommandReceivedCallback _customCommandCallback; + private static Native.SearchCommandReceivedCallback _searchCommandCallback; + private static Native.CommandCompletedCallback _commandCompletedCallback; /// /// Occurs when a client sends playback command. @@ -73,6 +76,18 @@ namespace Tizen.Multimedia.Remoting /// 5 public static event EventHandler CustomCommandReceived; + /// + /// Occurs when a client sends search command. + /// + /// 5 + public static event EventHandler SearchCommandReceived; + + /// + /// Occurs when a client sends custom command. + /// + /// 5 + internal static event EventHandler CommandCompleted; + private static void RegisterPlaybackCommandReceivedEvent() { _playbackCommandCallback = (clientName, playbackCode, _) => @@ -88,7 +103,7 @@ namespace Tizen.Multimedia.Remoting _playbackActionCommandCallback = (clientName, requestId, playbackCommand, _) => { var command = new PlaybackCommand(playbackCommand.ToPublic()); - command.SetClientInfo(clientName, requestId); + command.SetResponseInformation(clientName, requestId); PlaybackActionCommandReceived?.Invoke(null, new PlaybackActionCommandReceivedEventArgs(command)); }; @@ -101,7 +116,7 @@ namespace Tizen.Multimedia.Remoting _playbackPositionCommandCallback = (clientName, requestId, playbackPosition, _) => { var command = new PlaybackPositionCommand(playbackPosition); - command.SetClientInfo(clientName, requestId); + command.SetResponseInformation(clientName, requestId); PlaybackPositionCommandReceived?.Invoke(null, new PlaybackPositionCommandReceivedEventArgs(command)); }; @@ -114,7 +129,7 @@ namespace Tizen.Multimedia.Remoting _playlistCommandCallback = (clientName, requestId, playlistName, index, playbackCommand, playbackPosition, _) => { var command = new PlaylistCommand(playbackCommand.ToPublic(), playlistName, index, playbackPosition); - command.SetClientInfo(clientName, requestId); + command.SetResponseInformation(clientName, requestId); PlaylistCommandReceived?.Invoke(null, new PlaylistCommandReceivedEventArgs(command)); }; @@ -127,7 +142,7 @@ namespace Tizen.Multimedia.Remoting _shuffleModeCommandCallback = (clientName, requestId, mode, _) => { var command = new ShuffleModeCommand(mode == MediaControllerNativeShuffleMode.On ? true : false); - command.SetClientInfo(clientName, requestId); + command.SetResponseInformation(clientName, requestId); ShuffleModeCommandReceived?.Invoke(null, new ShuffleModeCommandReceivedEventArgs(command)); }; @@ -140,7 +155,7 @@ namespace Tizen.Multimedia.Remoting _repeatModeCommandCallback = (clientName, requestId, mode, _) => { var command = new RepeatModeCommand(mode.ToPublic()); - command.SetClientInfo(clientName, requestId); + command.SetResponseInformation(clientName, requestId); RepeatModeCommandReceived?.Invoke(null, new RepeatModeCommandReceivedEventArgs(command)); }; @@ -162,12 +177,65 @@ namespace Tizen.Multimedia.Remoting command = new CustomCommand(customCommand); } - command.SetClientInfo(clientName, requestId); + command.SetResponseInformation(clientName, requestId); CustomCommandReceived?.Invoke(null, new CustomCommandReceivedEventArgs(command)); }; Native.SetCustomCommandReceivedCb(Handle, _customCommandCallback). ThrowIfError("Failed to init CustomCommandReceived event."); } + + private static SearchCommand CreateSearchCommandReceivedEventArgs(IntPtr searchHandle) + { + var searchConditions = new List(); + + Native.SearchItemCallback searchItemCallback = (type, category, keyword, bundleHandle, _) => + { + Bundle bundle = null; + if (bundleHandle != IntPtr.Zero) + { + bundle = new Bundle(new SafeBundleHandle(bundleHandle, true)); + } + + searchConditions.Add(new MediaControlSearchCondition(type, category, keyword, bundle)); + + return true; + }; + Native.ForeachSearchCondition(searchHandle, searchItemCallback). + ThrowIfError("Failed to get search items."); + + return new SearchCommand(searchConditions, searchHandle); + } + + private static void RegisterSearchCommandReceivedEvent() + { + _searchCommandCallback = (clientName, requestId, searchHandle, _) => + { + var command = CreateSearchCommandReceivedEventArgs(searchHandle); + + command.SetResponseInformation(clientName, requestId); + + SearchCommandReceived?.Invoke(null, new SearchCommandReceivedEventArgs(command)); + }; + Native.SetSearchCommandReceivedCb(Handle, _searchCommandCallback). + ThrowIfError("Failed to init SearchCommandReceived event."); + } + + private static void RegisterCommandCompletedEvent() + { + _commandCompletedCallback = (clientName, requestId, result, bundleHandle, _) => + { + if (bundleHandle != IntPtr.Zero) + { + CommandCompleted?.Invoke(null, new CommandCompletedEventArgs(requestId, result, new Bundle(new SafeBundleHandle(bundleHandle, true)))); + } + else + { + CommandCompleted?.Invoke(null, new CommandCompletedEventArgs(requestId, result)); + } + }; + Native.SetEventReceivedCb(Handle, _commandCompletedCallback). + ThrowIfError("Failed to init RegisterEventCompletedEvent."); + } } } \ No newline at end of file diff --git a/src/Tizen.Multimedia.Remoting/MediaController/MediaControlServer.cs b/src/Tizen.Multimedia.Remoting/MediaController/MediaControlServer.cs index bdf5a14..3c14975 100644 --- a/src/Tizen.Multimedia.Remoting/MediaController/MediaControlServer.cs +++ b/src/Tizen.Multimedia.Remoting/MediaController/MediaControlServer.cs @@ -16,6 +16,7 @@ using System; using System.Collections.Generic; +using System.Threading.Tasks; using Tizen.Applications; using Native = Interop.MediaControllerServer; @@ -111,6 +112,8 @@ namespace Tizen.Multimedia.Remoting RegisterShuffleModeCommandReceivedEvent(); RegisterRepeatModeCommandReceivedEvent(); RegisterCustomCommandReceivedEvent(); + RegisterCommandCompletedEvent(); + RegisterSearchCommandReceivedEvent(); _isRunning = true; } @@ -312,6 +315,77 @@ namespace Tizen.Multimedia.Remoting } /// + /// Gets the active clients. + /// + /// + /// The server is not running .
+ /// -or-
+ /// An internal error occurs. + ///
+ /// the activated client ids. + /// 5 + public static IEnumerable GetActivatedClients() + { + var clientIds = new List(); + + Native.ActivatedClientCallback activatedClientCallback = (name, _) => + { + clientIds.Add(name); + return true; + }; + + Native.ForeachActivatedClient(Handle, activatedClientCallback). + ThrowIfError("Failed to get activated client."); + + return clientIds.AsReadOnly(); + } + + /// + /// Requests commands to the client. + /// + /// + /// The client can request the command to execute ,
+ /// and then, the server receive the result of each request(command). + ///
+ /// A class. + /// The client Id to send command. + /// A task that represents the asynchronous operation. + /// + /// The server has already been stopped.
+ /// -or-
+ /// An internal error occurs. + ///
+ /// 5 + public static async Task RequestAsync(Command command, string clientId) + { + command.SetRequestInformation(clientId); + + var tcs = new TaskCompletionSource(); + string reqeustId = null; + + EventHandler eventHandler = (s, e) => + { + if (e.RequestId == reqeustId) + { + tcs.TrySetResult(e.Result); + } + }; + + try + { + CommandCompleted += eventHandler; + + reqeustId = command.Request(Handle); + + (await tcs.Task).ThrowIfError("Failed to request event."); + } + finally + { + CommandCompleted -= eventHandler; + } + } + + /// /// Sends the result of each command. /// /// The command that return to client. @@ -343,5 +417,130 @@ namespace Tizen.Multimedia.Remoting { command.Response(Handle, result, null); } + + #region Capabilities + /// + /// Sets the content type of latest played media. + /// + /// A value indicating the content type of the latest played media. + /// + /// The server is not running .
+ /// -or-
+ /// An internal error occurs. + ///
+ /// is invalid. + /// 5 + public static void SetPlaybackContentType(MediaControlContentType type) + { + ValidationUtil.ValidateEnum(typeof(MediaControlContentType), type, nameof(type)); + + Native.SetPlaybackContentType(Handle, type).ThrowIfError("Failed to set playback content type."); + } + + /// + /// Sets the path of icon. + /// + /// The path of icon. + /// + /// The server is not running .
+ /// -or-
+ /// An internal error occurs. + ///
+ /// is invalid. + /// 5 + public static void SetIconPath(string path) + { + if (path == null) + { + throw new ArgumentNullException(nameof(path)); + } + + Native.SetIconPath(Handle, path).ThrowIfError("Failed to set uri path."); + } + + /// + /// Sets the capabilities by . + /// + /// The set of and . + /// + /// The server is not running .
+ /// -or-
+ /// An internal error occurs. + ///
+ /// is invalid. + /// 5 + public static void SetPlaybackCapability(Dictionary capabilities) + { + foreach (var pair in capabilities) + { + ValidationUtil.ValidateEnum(typeof(MediaControlPlaybackCommand), pair.Key, nameof(pair.Key)); + ValidationUtil.ValidateEnum(typeof(MediaControlCapabilitySupport), pair.Value, nameof(pair.Value)); + + SetPlaybackCapability(pair.Key, pair.Value); + Native.SetPlaybackCapability(Handle, pair.Key.ToNative(), pair.Value). + ThrowIfError("Failed to set playback capability."); + } + + Native.SaveAndNotifyPlaybackCapabilityUpdated(Handle).ThrowIfError("Failed to update playback capability."); + } + + /// + /// Sets the capabilities by . + /// + /// A playback command. + /// A value indicating whether the is supported or not. + /// + /// The server is not running .
+ /// -or-
+ /// An internal error occurs. + ///
+ /// or is invalid. + /// 5 + public static void SetPlaybackCapability(MediaControlPlaybackCommand action, MediaControlCapabilitySupport support) + { + ValidationUtil.ValidateEnum(typeof(MediaControlPlaybackCommand), action, nameof(action)); + ValidationUtil.ValidateEnum(typeof(MediaControlCapabilitySupport), support, nameof(support)); + + Native.SetPlaybackCapability(Handle, action.ToNative(), support).ThrowIfError("Failed to set playback capability."); + + Native.SaveAndNotifyPlaybackCapabilityUpdated(Handle).ThrowIfError("Failed to update playback capability."); + } + + /// + /// Sets the indicating shuffle mode is supported or not. + /// + /// A value indicating whether the shuffle mode is supported or not. + /// + /// The server is not running .
+ /// -or-
+ /// An internal error occurs. + ///
+ /// is invalid. + /// 5 + public static void SetShuffleModeCapability(MediaControlCapabilitySupport support) + { + ValidationUtil.ValidateEnum(typeof(MediaControlCapabilitySupport), support, nameof(support)); + + Native.SetShuffleModeCapability(Handle, support).ThrowIfError("Failed to set shuffle mode capability."); + } + + /// + /// Sets the content type of latest played media. + /// + /// A value indicating whether the is supported or not. + /// + /// The server is not running .
+ /// -or-
+ /// An internal error occurs. + ///
+ /// is invalid. + /// 5 + public static void SetRepeatModeCapability(MediaControlCapabilitySupport support) + { + ValidationUtil.ValidateEnum(typeof(MediaControlCapabilitySupport), support, nameof(support)); + + Native.SetRepeatModeCapability(Handle, support).ThrowIfError("Failed to set shuffle mode capability."); + } + #endregion Capabilities } } \ No newline at end of file diff --git a/src/Tizen.Multimedia.Remoting/MediaController/MediaController.Events.cs b/src/Tizen.Multimedia.Remoting/MediaController/MediaController.Events.cs index 08b7b47..109818c 100644 --- a/src/Tizen.Multimedia.Remoting/MediaController/MediaController.Events.cs +++ b/src/Tizen.Multimedia.Remoting/MediaController/MediaController.Events.cs @@ -15,6 +15,7 @@ */ using System; +using System.Collections.Generic; using Tizen.Applications; using Native = Interop.MediaControllerClient; @@ -142,9 +143,9 @@ namespace Tizen.Multimedia.Remoting /// 5 public event EventHandler PlaylistUpdated; - internal void RaisePlaylistUpdatedEvent(MediaControlPlaylistMode mode, string name) + internal void RaisePlaylistUpdatedEvent(MediaControlPlaylistMode mode, string name, IntPtr playlistHandle) { - PlaylistUpdated?.Invoke(this, new PlaylistUpdatedEventArgs(mode, name)); + PlaylistUpdated?.Invoke(this, new PlaylistUpdatedEventArgs(mode, name, new MediaControlPlaylist(playlistHandle))); } /// @@ -167,5 +168,81 @@ namespace Tizen.Multimedia.Remoting CommandCompleted?.Invoke(this, new CommandCompletedEventArgs(requestId, result)); } } + + /// + /// Occurs when the playback capabilities are updated. + /// + /// 5 + public event EventHandler PlaybackCapabilityUpdated; + + private PlaybackCapabilityUpdatedEventArgs CreatePlaybackCapabilityUpdatedEventArgs(IntPtr playbackCapaHandle) + { + var capabilities = new Dictionary(); + try + { + foreach (MediaControllerNativePlaybackAction action in Enum.GetValues(typeof(MediaControllerNativePlaybackAction))) + { + Native.IsCapabilitySupported(playbackCapaHandle, action, out MediaControlCapabilitySupport support); + capabilities.Add(action.ToPublic(), support); + } + + return new PlaybackCapabilityUpdatedEventArgs(capabilities); + } + catch (Exception e) + { + Log.Error(GetType().FullName, e.ToString()); + } + return null; + } + + internal void RaisePlaybackCapabilityUpdatedEvent(IntPtr playbackCapaHandle) + { + var eventHandler = PlaybackCapabilityUpdated; + + if (eventHandler == null) + { + return; + } + + var args = CreatePlaybackCapabilityUpdatedEventArgs(playbackCapaHandle); + + if (args != null) + { + eventHandler.Invoke(this, args); + } + } + + /// + /// Occurs when the repeat mode capabilities are updated. + /// + /// 5 + public event EventHandler RepeatModeCapabilityUpdated; + + internal void RaiseRepeatModeCapabilityUpdatedEvent(MediaControlCapabilitySupport support) + { + RepeatModeCapabilityUpdated?.Invoke(this, new RepeatModeCapabilityUpdatedEventArgs(support)); + } + + /// + /// Occurs when the shuffle mode capabilities are updated. + /// + /// 5 + public event EventHandler ShuffleModeCapabilityUpdated; + + internal void RaiseShuffleModeCapabilityUpdatedEvent(MediaControlCapabilitySupport support) + { + ShuffleModeCapabilityUpdated?.Invoke(this, new ShuffleModeCapabilityUpdatedEventArgs(support)); + } + + /// + /// Occurs when a server sends custom event. + /// + /// 5 + public event EventHandler CustomCommandReceived; + + internal void RaiseCustomCommandReceivedEvent(CustomCommand command) + { + CustomCommandReceived?.Invoke(this, new CustomCommandReceivedEventArgs(command)); + } } } \ No newline at end of file diff --git a/src/Tizen.Multimedia.Remoting/MediaController/MediaController.cs b/src/Tizen.Multimedia.Remoting/MediaController/MediaController.cs index 22f3de0..dd61ccf 100644 --- a/src/Tizen.Multimedia.Remoting/MediaController/MediaController.cs +++ b/src/Tizen.Multimedia.Remoting/MediaController/MediaController.cs @@ -15,9 +15,11 @@ */ using System; +using System.Linq; using System.Collections.Generic; using System.Diagnostics; using System.Threading.Tasks; +using Tizen.Applications; using Native = Interop.MediaControllerClient; using NativePlaylist = Interop.MediaControllerPlaylist; @@ -173,7 +175,7 @@ namespace Tizen.Multimedia.Remoting /// /// Returns the all playlists. /// - /// + /// The set of . /// /// The server has already been stopped.
/// -or-
@@ -185,7 +187,7 @@ namespace Tizen.Multimedia.Remoting { ThrowIfStopped(); - List playlists = null; + var playlists = new List(); NativePlaylist.PlaylistCallback playlistCallback = (handle, _) => { @@ -194,7 +196,43 @@ namespace Tizen.Multimedia.Remoting NativePlaylist.ForeachServerPlaylist(Manager.Handle, ServerAppId, playlistCallback, IntPtr.Zero) .ThrowIfError("Failed to get playlist."); - return playlists; + return playlists.AsReadOnly(); + } + + /// + /// Returns the playlist name of current playing media. + /// + /// The playlist name. + /// + /// The server has already been stopped.
+ /// -or-
+ /// An internal error occurs. + ///
+ /// The has already been disposed of. + /// 5 + public MediaControlPlaylist GetPlaylistOfCurrentPlayingMedia() + { + ThrowIfStopped(); + + IntPtr playbackHandle = IntPtr.Zero; + string name = null; + + // Get the playlist name of current playing media. + try + { + Native.GetServerPlayback(Manager.Handle, ServerAppId, out playbackHandle).ThrowIfError("Failed to get playback."); + + name = NativePlaylist.GetPlaylistIndex(playbackHandle); + } + finally + { + if (playbackHandle != IntPtr.Zero) + { + Native.DestroyPlayback(playbackHandle).ThrowIfError("Failed to destroy playback handle."); + } + } + + return GetPlaylists().FirstOrDefault(playlist => playlist.Name == name); } /// @@ -224,7 +262,7 @@ namespace Tizen.Multimedia.Remoting { if (playbackHandle != IntPtr.Zero) { - Native.DestroyPlayback(playbackHandle); + Native.DestroyPlayback(playbackHandle).ThrowIfError("Failed to destroy playback handle."); } } } @@ -282,6 +320,7 @@ namespace Tizen.Multimedia.Remoting /// and then, the client receive the result of each request(command). /// /// A class. + /// A task that represents the asynchronous operation. /// /// The server has already been stopped.
/// -or-
@@ -293,7 +332,7 @@ namespace Tizen.Multimedia.Remoting { ThrowIfStopped(); - command.SetServerInfo(Manager.Handle, ServerAppId); + command.SetRequestInformation(ServerAppId); var tcs = new TaskCompletionSource(); string reqeustId = null; @@ -310,7 +349,7 @@ namespace Tizen.Multimedia.Remoting { CommandCompleted += eventHandler; - reqeustId = command.Request(); + reqeustId = command.Request(Manager.Handle); (await tcs.Task).ThrowIfError("Failed to request command"); } @@ -321,6 +360,39 @@ namespace Tizen.Multimedia.Remoting } /// + /// Sends the result of each command. + /// + /// The command that return to client. + /// The result of . + /// The extra data. + /// + /// The server is not running .
+ /// -or-
+ /// An internal error occurs. + ///
+ /// 5 + public void Response(Command command, int result, Bundle bundle) + { + command.Response(Manager.Handle, result, bundle); + } + + /// + /// Sends the result of each command. + /// + /// The command that return to client. + /// The result of . + /// + /// The server is not running .
+ /// -or-
+ /// An internal error occurs. + ///
+ /// 5 + public void Response(Command command, int result) + { + command.Response(Manager.Handle, result, null); + } + + /// /// Sends playback command to the server. /// /// A playback command. @@ -343,5 +415,246 @@ namespace Tizen.Multimedia.Remoting Native.SendPlaybackStateCommand(Manager.Handle, ServerAppId, command.ToNative()). ThrowIfError("Failed to send command."); } + + #region Capabilities + /// + /// Gets the content type of current playing media. + /// + /// The . + /// + /// The server has already been stopped.
+ /// -or-
+ /// An internal error occurs. + ///
+ /// The has already been disposed of. + /// 5 + public MediaControlContentType GetContentTypeOfCurrentPlayingMedia() + { + ThrowIfStopped(); + + IntPtr playbackHandle = IntPtr.Zero; + + try + { + Native.GetServerPlayback(Manager.Handle, ServerAppId, out playbackHandle).ThrowIfError("Failed to get playback."); + + Native.GetPlaybackContentType(playbackHandle, out MediaControlContentType type). + ThrowIfError("Failed to get playback content type"); + + return type; + } + finally + { + if (playbackHandle != IntPtr.Zero) + { + Native.DestroyPlayback(playbackHandle); + } + } + } + + /// + /// Gets the icon path. + /// + /// The icon path. + /// + /// The server has already been stopped.
+ /// -or-
+ /// An internal error occurs. + ///
+ /// The has already been disposed of. + /// 5 + public string GetIconPath() + { + ThrowIfStopped(); + + Native.GetServerIcon(Manager.Handle, ServerAppId, out string uri). + ThrowIfError("Failed to get icon path."); + + return uri; + } + + /// + /// Gets the age rating of current playing media. + /// + /// The Age rating of current playing media. The range is 0 to 19, inclusive. + /// + /// The server has already been stopped.
+ /// -or-
+ /// An internal error occurs. + ///
+ /// The has already been disposed of. + /// 5 + public int GetAgeRatingOfCurrentPlayingMedia() + { + ThrowIfStopped(); + + IntPtr playbackHandle = IntPtr.Zero; + + try + { + Native.GetServerPlayback(Manager.Handle, ServerAppId, out playbackHandle).ThrowIfError("Failed to get playback."); + + Native.GetAgeRating(playbackHandle, out int ageRating).ThrowIfError("Failed to get age rating."); + + return ageRating; + } + finally + { + if (playbackHandle != IntPtr.Zero) + { + Native.DestroyPlayback(playbackHandle); + } + } + } + + /// + /// Gets the value whether is supported or not. + /// + /// + /// the set of and . + /// + /// + /// The server has already been stopped.
+ /// -or-
+ /// An internal error occurs. + ///
+ /// The has already been disposed of. + /// 5 + public Dictionary GetPlaybackCapabilities() + { + ThrowIfStopped(); + + IntPtr playbackCapaHandle = IntPtr.Zero; + + var playbackCapabilities = new Dictionary(); + + try + { + Native.GetPlaybackCapabilityHandle(Manager.Handle, ServerAppId, out playbackCapaHandle). + ThrowIfError("Failed to get playback capability handle."); + + foreach (MediaControllerNativePlaybackAction action in Enum.GetValues(typeof(MediaControllerNativePlaybackAction))) + { + Native.IsCapabilitySupported(playbackCapaHandle, action, out MediaControlCapabilitySupport support); + playbackCapabilities.Add(action.ToPublic(), support); + } + + return playbackCapabilities; + } + finally + { + if (playbackCapaHandle != IntPtr.Zero) + { + Native.DestroyCapability(playbackCapaHandle); + } + } + } + + /// + /// Gets the value whether is supported or not. + /// + /// A playback command. + /// A . + /// + /// The server has already been stopped.
+ /// -or-
+ /// An internal error occurs. + ///
+ /// The has already been disposed of. + /// 5 + public MediaControlCapabilitySupport GetPlaybackCapabilities(MediaControlPlaybackCommand action) + { + ThrowIfStopped(); + + IntPtr playbackCapaHandle = IntPtr.Zero; + + try + { + Native.GetPlaybackCapabilityHandle(Manager.Handle, ServerAppId, out playbackCapaHandle). + ThrowIfError("Failed to get playback capability handle."); + + Native.IsCapabilitySupported(playbackCapaHandle, action.ToNative(), out MediaControlCapabilitySupport support); + + return support; + } + finally + { + if (playbackCapaHandle != IntPtr.Zero) + { + Native.DestroyCapability(playbackCapaHandle); + } + } + } + + /// + /// Gets the value whether the shuffle mode is supported or not. + /// + /// A . + /// + /// The server has already been stopped.
+ /// -or-
+ /// An internal error occurs. + ///
+ /// The has already been disposed of. + /// 5 + public MediaControlCapabilitySupport GetShuffleModeCapability() + { + ThrowIfStopped(); + + IntPtr playbackCapaHandle = IntPtr.Zero; + + try + { + Native.GetPlaybackCapabilityHandle(Manager.Handle, ServerAppId, out playbackCapaHandle). + ThrowIfError("Failed to get playback capability handle."); + + Native.GetShuffleCapability(Manager.Handle, ServerAppId, out MediaControlCapabilitySupport support); + + return support; + } + finally + { + if (playbackCapaHandle != IntPtr.Zero) + { + Native.DestroyCapability(playbackCapaHandle); + } + } + } + + /// + /// Gets the value whether the repeat mode is supported or not. + /// + /// A . + /// + /// The server has already been stopped.
+ /// -or-
+ /// An internal error occurs. + ///
+ /// The has already been disposed of. + /// 5 + public MediaControlCapabilitySupport GetRepeatModeCapability() + { + ThrowIfStopped(); + + IntPtr playbackCapaHandle = IntPtr.Zero; + + try + { + Native.GetPlaybackCapabilityHandle(Manager.Handle, ServerAppId, out playbackCapaHandle). + ThrowIfError("Failed to get playback capability handle."); + + Native.GetRepeatCapability(Manager.Handle, ServerAppId, out MediaControlCapabilitySupport support); + + return support; + } + finally + { + if (playbackCapaHandle != IntPtr.Zero) + { + Native.DestroyCapability(playbackCapaHandle); + } + } + } + #endregion Capabilities } } \ No newline at end of file diff --git a/src/Tizen.Multimedia.Remoting/MediaController/MediaControllerManager.Events.cs b/src/Tizen.Multimedia.Remoting/MediaController/MediaControllerManager.Events.cs index bd4079d..23166bf 100644 --- a/src/Tizen.Multimedia.Remoting/MediaController/MediaControllerManager.Events.cs +++ b/src/Tizen.Multimedia.Remoting/MediaController/MediaControllerManager.Events.cs @@ -15,6 +15,7 @@ */ using System; +using Tizen.Applications; using Native = Interop.MediaControllerClient; using NativePlaylist = Interop.MediaControllerPlaylist; @@ -29,6 +30,10 @@ namespace Tizen.Multimedia.Remoting private Native.CommandCompletedCallback _commandCompletedCallback; private NativePlaylist.MetadataUpdatedCallback _metadataUpdatedCallback; private NativePlaylist.PlaylistUpdatedCallback _playlistUpdatedCallback; + private Native.PlaybackCapabilityUpdatedCallback _playbackCapabilityUpdatedCallback; + private Native.ShuffleCapabilityUpdatedCallback _shuffleModeCapabilityUpdatedCallback; + private Native.RepeatCapabilityUpdatedCallback _repeatModeCapabilityUpdatedCallback; + private Native.CustomCommandReceivedCallback _customCommandReceivedCallback; /// /// Occurs when a server is started. @@ -50,6 +55,10 @@ namespace Tizen.Multimedia.Remoting RegisterShuffleModeUpdatedEvent(); RegisterRepeatModeUpdatedEvent(); RegisterCommandCompletedEvent(); + RegisterPlaybackCapabilitiesEvent(); + RegisterRepeatModeCapabilitiesEvent(); + RegisterShuffleModeCapabilitiesEvent(); + RegisterCustomCommandReceivedEvent(); } private void RaiseServerChangedEvent(MediaControllerNativeServerState state, MediaController controller) @@ -82,9 +91,9 @@ namespace Tizen.Multimedia.Remoting private void RegisterPlaybackUpdatedEvent() { - _playbackUpdatedCallback = (serverName, playback, _) => + _playbackUpdatedCallback = (serverName, playbackHandle, _) => { - GetController(serverName)?.RaisePlaybackUpdatedEvent(playback); + GetController(serverName)?.RaisePlaybackUpdatedEvent(playbackHandle); }; Native.SetPlaybackUpdatedCb(Handle, _playbackUpdatedCallback).ThrowIfError("Failed to init PlaybackUpdated event."); @@ -125,9 +134,9 @@ namespace Tizen.Multimedia.Remoting private void RegisterPlaylistUpdatedEvent() { - _playlistUpdatedCallback = (serverName, playlistMode, name, handle, _) => + _playlistUpdatedCallback = (serverName, playlistMode, name, playlistHandle, _) => { - GetController(serverName)?.RaisePlaylistUpdatedEvent(playlistMode, name); + GetController(serverName)?.RaisePlaylistUpdatedEvent(playlistMode, name, playlistHandle); }; NativePlaylist.SetPlaylistModeUpdatedCb(Handle, _playlistUpdatedCallback). @@ -146,5 +155,61 @@ namespace Tizen.Multimedia.Remoting Native.SetCommandCompletedCb(Handle, _commandCompletedCallback). ThrowIfError("Failed to init CommandCompleted event."); } + + private void RegisterPlaybackCapabilitiesEvent() + { + _playbackCapabilityUpdatedCallback = (serverName, playbackCapaHandle, _) => + { + GetController(serverName)?.RaisePlaybackCapabilityUpdatedEvent(playbackCapaHandle); + }; + + Native.SetPlaybackCapabilityUpdatedCb(Handle, _playbackCapabilityUpdatedCallback). + ThrowIfError("Failed to init PlaylistUpdated event."); + } + + private void RegisterRepeatModeCapabilitiesEvent() + { + _repeatModeCapabilityUpdatedCallback = (serverName, support, _) => + { + GetController(serverName)?.RaiseRepeatModeCapabilityUpdatedEvent(support); + }; + + Native.SetRepeatCapabilityUpdatedCb(Handle, _repeatModeCapabilityUpdatedCallback). + ThrowIfError("Failed to init RepeatModeCapabilityUpdated event."); + } + + private void RegisterShuffleModeCapabilitiesEvent() + { + _shuffleModeCapabilityUpdatedCallback = (serverName, support, _) => + { + GetController(serverName)?.RaiseShuffleModeCapabilityUpdatedEvent(support); + }; + + Native.SetShuffleCapabilityUpdatedCb(Handle, _shuffleModeCapabilityUpdatedCallback). + ThrowIfError("Failed to init ShuffleModeCapabilityUpdated event."); + } + + private void RegisterCustomCommandReceivedEvent() + { + _customCommandReceivedCallback = (serverName, requestId, customEvent, bundleHandle, _) => + { + CustomCommand command = null; + if (bundleHandle != IntPtr.Zero) + { + command = new CustomCommand(customEvent, new Bundle(new SafeBundleHandle(bundleHandle, true))); + } + else + { + command = new CustomCommand(customEvent); + } + + command.SetResponseInformation(serverName, requestId); + + GetController(serverName)?.RaiseCustomCommandReceivedEvent(command); + }; + + Native.SetCustomEventCb(Handle, _customCommandReceivedCallback). + ThrowIfError("Failed to init CustomCommandReceived event."); + } } } \ No newline at end of file diff --git a/src/Tizen.Multimedia.Remoting/MediaController/PlaybackCapabilityUpdatedEventArgs.cs b/src/Tizen.Multimedia.Remoting/MediaController/PlaybackCapabilityUpdatedEventArgs.cs new file mode 100644 index 0000000..3fdf658 --- /dev/null +++ b/src/Tizen.Multimedia.Remoting/MediaController/PlaybackCapabilityUpdatedEventArgs.cs @@ -0,0 +1,46 @@ +/* + * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the License); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an AS IS BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +using System; +using System.Collections.Generic; +using Native = Interop.MediaControllerClient; + +namespace Tizen.Multimedia.Remoting +{ + /// + /// Provides data for the event. + /// + /// 5 + public class PlaybackCapabilityUpdatedEventArgs : EventArgs + { + /// + /// Initializes a new instance of the class. + /// + /// The set of playback capabilities. + /// is invalid. + /// 5 + public PlaybackCapabilityUpdatedEventArgs(Dictionary support) + { + Support = support ?? throw new ArgumentNullException(nameof(support)); + } + + /// + /// Gets the value whether the playback action is supported or not. + /// + /// 5 + public Dictionary Support { get; } + } +} \ No newline at end of file diff --git a/src/Tizen.Multimedia.Remoting/MediaController/PlaylistUpdatedEventArgs.cs b/src/Tizen.Multimedia.Remoting/MediaController/PlaylistUpdatedEventArgs.cs index 54cf2c5..eb11df8 100644 --- a/src/Tizen.Multimedia.Remoting/MediaController/PlaylistUpdatedEventArgs.cs +++ b/src/Tizen.Multimedia.Remoting/MediaController/PlaylistUpdatedEventArgs.cs @@ -29,14 +29,16 @@ namespace Tizen.Multimedia.Remoting /// /// A value indicating the updated repeat mode. /// A value indicating the playlist name. + /// A value indicating the playlist. /// is invalid. /// 5 - public PlaylistUpdatedEventArgs(MediaControlPlaylistMode mode, string name) + public PlaylistUpdatedEventArgs(MediaControlPlaylistMode mode, string name, MediaControlPlaylist playlist) { ValidationUtil.ValidateEnum(typeof(MediaControlPlaylistMode), mode, nameof(mode)); Mode = mode; Name = name; + Playlist = playlist; } /// @@ -55,5 +57,11 @@ namespace Tizen.Multimedia.Remoting /// /// 5 public string Name { get; } + + /// + /// Gets the updated playlist. + /// + /// 5 + public MediaControlPlaylist Playlist { get; } } } diff --git a/src/Tizen.Multimedia.Remoting/MediaController/MediaControlPlaybackState.cs b/src/Tizen.Multimedia.Remoting/MediaController/RepeatModeCapabilityUpdatedEventArgs.cs similarity index 53% rename from src/Tizen.Multimedia.Remoting/MediaController/MediaControlPlaybackState.cs rename to src/Tizen.Multimedia.Remoting/MediaController/RepeatModeCapabilityUpdatedEventArgs.cs index 12b54f5..9dbe3ff 100644 --- a/src/Tizen.Multimedia.Remoting/MediaController/MediaControlPlaybackState.cs +++ b/src/Tizen.Multimedia.Remoting/MediaController/RepeatModeCapabilityUpdatedEventArgs.cs @@ -14,54 +14,32 @@ * limitations under the License. */ +using System; +using System.Collections.Generic; +using Native = Interop.MediaControllerClient; + namespace Tizen.Multimedia.Remoting { /// - /// Specifies playback states. + /// Provides data for the event. /// - /// 4 - public enum MediaControlPlaybackState + /// 5 + public class RepeatModeCapabilityUpdatedEventArgs : EventArgs { /// - /// Unknown; no state is set. - /// - None, - - /// - /// Playing. - /// - Playing, - - /// - /// Paused. - /// - Paused, - - /// - /// Stopped. - /// - Stopped, - - /// - /// Fast forwarding. - /// - FastForwarding, - - /// - /// Rewinding. - /// - Rewinding, - - /// - /// Skipping to the next item. + /// Initializes a new instance of the class. /// + /// The repeat mode capabilities. /// 5 - MovingToNext, + public RepeatModeCapabilityUpdatedEventArgs(MediaControlCapabilitySupport support) + { + Support = support; + } /// - /// Skipping to the previous item. + /// Gets the value whether the repeat mode is supported or not. /// /// 5 - MovingToPrevious, + public MediaControlCapabilitySupport Support { get; } } } \ No newline at end of file diff --git a/src/Tizen.Multimedia.Remoting/MediaController/MediaControllerPlaylistMode.cs b/src/Tizen.Multimedia.Remoting/MediaController/SearchCommandReceivedEventArgs.cs similarity index 57% rename from src/Tizen.Multimedia.Remoting/MediaController/MediaControllerPlaylistMode.cs rename to src/Tizen.Multimedia.Remoting/MediaController/SearchCommandReceivedEventArgs.cs index b0a86dd..843cef5 100644 --- a/src/Tizen.Multimedia.Remoting/MediaController/MediaControllerPlaylistMode.cs +++ b/src/Tizen.Multimedia.Remoting/MediaController/SearchCommandReceivedEventArgs.cs @@ -14,22 +14,30 @@ * limitations under the License. */ +using System; + namespace Tizen.Multimedia.Remoting { /// - /// Specifies the playlist mode. + /// Provides data for the event. /// /// 5 - public enum MediaControlPlaylistMode + public class SearchCommandReceivedEventArgs : EventArgs { /// - /// Playlist is created or update. + /// Initializes a new instance of the class. /// - Updated, + /// The search command. + /// 5 + public SearchCommandReceivedEventArgs(SearchCommand command) + { + Command = command; + } /// - /// Playlist is removed. + /// Gets the . /// - Removed, + /// 5 + public SearchCommand Command { get; } } } \ No newline at end of file diff --git a/src/Tizen.Multimedia.Remoting/MediaController/MediaControllerRepeatMode.cs b/src/Tizen.Multimedia.Remoting/MediaController/ShuffleModeCapabilityUpdatedEventArgs.cs similarity index 51% rename from src/Tizen.Multimedia.Remoting/MediaController/MediaControllerRepeatMode.cs rename to src/Tizen.Multimedia.Remoting/MediaController/ShuffleModeCapabilityUpdatedEventArgs.cs index da434d8..c795fd6 100644 --- a/src/Tizen.Multimedia.Remoting/MediaController/MediaControllerRepeatMode.cs +++ b/src/Tizen.Multimedia.Remoting/MediaController/ShuffleModeCapabilityUpdatedEventArgs.cs @@ -14,28 +14,32 @@ * limitations under the License. */ +using System; +using System.Collections.Generic; +using Native = Interop.MediaControllerClient; + namespace Tizen.Multimedia.Remoting { /// - /// Specifies the repeat mode. + /// Provides data for the event. /// - /// 4 - public enum MediaControlRepeatMode + /// 5 + public class ShuffleModeCapabilityUpdatedEventArgs : EventArgs { /// - /// Off. + /// Initializes a new instance of the class. /// - Off, - - /// - /// On. - /// - On, + /// The shuffle mode capabilities. + /// 5 + public ShuffleModeCapabilityUpdatedEventArgs(MediaControlCapabilitySupport support) + { + Support = support; + } /// - /// One media. + /// Gets the value whether the shuffle mode is supported or not. /// /// 5 - OneMedia + public MediaControlCapabilitySupport Support { get; } } } \ No newline at end of file