From 23def3f3e6b561d10dbe9f45c2cc7634694a1b40 Mon Sep 17 00:00:00 2001 From: DotnetBuild Date: Tue, 5 Sep 2017 09:56:18 +0900 Subject: [PATCH] Release 4.0.0-preview1-00151 --- packaging/csapi-tizenfx.spec | 2 +- pkg/PlatformFileList.txt | 8 +- .../Interop/Interop.MediaController.cs | 202 ------- .../Interop/Interop.MediaControllerClient.cs | 166 ++++++ .../Interop/Interop.MediaControllerServer.cs | 66 +++ .../MediaController/CustomCommandEventArgs.cs | 57 -- .../MediaController/CustomCommandReplyEventArgs.cs | 57 -- .../MediaController/EnumExtensions.cs | 99 ++++ .../MediaController/InternalEnums.cs | 66 +++ .../MediaController/MediaControlMetadata.cs | 107 ++++ .../MediaController/MediaControlPlaybackCommand.cs | 59 ++ .../MediaController/MediaControlPlaybackState.cs | 54 ++ .../MediaController/MediaControlServer.cs | 231 ++++++++ .../MediaControlServerStartedEventArgs.cs | 47 ++ .../MediaControlServerStoppedEventArgs.cs | 47 ++ .../MediaController/MediaController.cs | 332 ++++++++++++ .../MediaController/MediaControllerClient.cs | 595 --------------------- .../MediaController/MediaControllerEnums.cs | 236 -------- .../MediaController/MediaControllerError.cs | 48 +- .../MediaController/MediaControllerLog.cs | 25 - .../MediaControllerManager.Events.cs | 120 +++++ .../MediaController/MediaControllerManager.cs | 204 +++++++ .../MediaController/MediaControllerMetadata.cs | 123 ----- .../MediaController/MediaControllerPlayback.cs | 76 --- .../MediaController/MediaControllerRepeatMode.cs | 24 + .../MediaController/MediaControllerServer.cs | 302 ----------- .../MediaController/MetadataUpdatedEventArgs.cs | 60 +-- .../PlaybackCommandReceivedEventArgs.cs | 58 ++ .../PlaybackStateCommandEventArgs.cs | 49 -- .../PlaybackStateUpdatedEventArgs.cs | 58 ++ .../MediaController/PlaybackUpdatedEventArgs.cs | 49 -- .../MediaController/RepeatModeUpdatedEventArgs.cs | 61 +-- .../MediaController/ServerInformation.cs | 45 -- .../MediaController/ServerUpdatedEventArgs.cs | 42 -- .../MediaController/ShuffleModeUpdatedEventArgs.cs | 60 +-- 35 files changed, 1850 insertions(+), 1985 deletions(-) delete mode 100644 src/Tizen.Multimedia.Remoting/Interop/Interop.MediaController.cs create mode 100644 src/Tizen.Multimedia.Remoting/Interop/Interop.MediaControllerClient.cs create mode 100644 src/Tizen.Multimedia.Remoting/Interop/Interop.MediaControllerServer.cs delete mode 100755 src/Tizen.Multimedia.Remoting/MediaController/CustomCommandEventArgs.cs delete mode 100755 src/Tizen.Multimedia.Remoting/MediaController/CustomCommandReplyEventArgs.cs create mode 100644 src/Tizen.Multimedia.Remoting/MediaController/EnumExtensions.cs create mode 100644 src/Tizen.Multimedia.Remoting/MediaController/InternalEnums.cs create mode 100644 src/Tizen.Multimedia.Remoting/MediaController/MediaControlMetadata.cs create mode 100644 src/Tizen.Multimedia.Remoting/MediaController/MediaControlPlaybackCommand.cs create mode 100644 src/Tizen.Multimedia.Remoting/MediaController/MediaControlPlaybackState.cs create mode 100644 src/Tizen.Multimedia.Remoting/MediaController/MediaControlServer.cs create mode 100644 src/Tizen.Multimedia.Remoting/MediaController/MediaControlServerStartedEventArgs.cs create mode 100644 src/Tizen.Multimedia.Remoting/MediaController/MediaControlServerStoppedEventArgs.cs create mode 100644 src/Tizen.Multimedia.Remoting/MediaController/MediaController.cs delete mode 100755 src/Tizen.Multimedia.Remoting/MediaController/MediaControllerClient.cs delete mode 100755 src/Tizen.Multimedia.Remoting/MediaController/MediaControllerEnums.cs delete mode 100644 src/Tizen.Multimedia.Remoting/MediaController/MediaControllerLog.cs create mode 100644 src/Tizen.Multimedia.Remoting/MediaController/MediaControllerManager.Events.cs create mode 100644 src/Tizen.Multimedia.Remoting/MediaController/MediaControllerManager.cs delete mode 100755 src/Tizen.Multimedia.Remoting/MediaController/MediaControllerMetadata.cs delete mode 100755 src/Tizen.Multimedia.Remoting/MediaController/MediaControllerPlayback.cs create mode 100644 src/Tizen.Multimedia.Remoting/MediaController/MediaControllerRepeatMode.cs delete mode 100755 src/Tizen.Multimedia.Remoting/MediaController/MediaControllerServer.cs create mode 100644 src/Tizen.Multimedia.Remoting/MediaController/PlaybackCommandReceivedEventArgs.cs delete mode 100755 src/Tizen.Multimedia.Remoting/MediaController/PlaybackStateCommandEventArgs.cs create mode 100644 src/Tizen.Multimedia.Remoting/MediaController/PlaybackStateUpdatedEventArgs.cs delete mode 100755 src/Tizen.Multimedia.Remoting/MediaController/PlaybackUpdatedEventArgs.cs delete mode 100755 src/Tizen.Multimedia.Remoting/MediaController/ServerInformation.cs delete mode 100755 src/Tizen.Multimedia.Remoting/MediaController/ServerUpdatedEventArgs.cs diff --git a/packaging/csapi-tizenfx.spec b/packaging/csapi-tizenfx.spec index 9a99b01..cd71075 100644 --- a/packaging/csapi-tizenfx.spec +++ b/packaging/csapi-tizenfx.spec @@ -10,7 +10,7 @@ Name: csapi-tizenfx Summary: Assemblies of Tizen .NET -Version: 4.0.0.147 +Version: 4.0.0.151 Release: 1 Group: Development/Libraries License: Apache-2.0 diff --git a/pkg/PlatformFileList.txt b/pkg/PlatformFileList.txt index d98f125..df00365 100644 --- a/pkg/PlatformFileList.txt +++ b/pkg/PlatformFileList.txt @@ -10,7 +10,7 @@ Tizen.Account.OAuth2.dll #mobile #mobile-emul #ivi #we Tizen.Account.SyncManager.dll #mobile #mobile-emul #wearable Tizen.Applications.Alarm.dll #common #mobile #mobile-emul #tv #ivi #wearable Tizen.Applications.AttachPanel.dll #mobile #mobile-emul -Tizen.Applications.Badge.dll #mobile #mobile-emul #ivi +Tizen.Applications.Badge.dll #mobile #mobile-emul #ivi #wearable Tizen.Applications.Common.dll #common #mobile #mobile-emul #tv #ivi #wearable Tizen.Applications.DataControl.dll #common #mobile #mobile-emul #tv #ivi #wearable Tizen.Applications.MessagePort.dll #common #mobile #mobile-emul #tv #ivi #wearable @@ -18,13 +18,13 @@ Tizen.Applications.Notification.dll #common #mobile #mobile-emul Tizen.Applications.NotificationEventListener.dll #common #mobile #mobile-emul #tv #ivi #wearable Tizen.Applications.PackageManager.dll #common #mobile #mobile-emul #tv #ivi #wearable Tizen.Applications.Preference.dll #common #mobile #mobile-emul #tv #ivi #wearable -Tizen.Applications.RemoteView.dll #mobile #mobile-emul #tv +Tizen.Applications.RemoteView.dll #mobile #mobile-emul #tv #wearable Tizen.Applications.Service.dll #common #mobile #mobile-emul #tv #ivi #wearable Tizen.Applications.ToastMessage.dll #common #mobile #mobile-emul #tv #ivi #wearable Tizen.Applications.UI.dll #common #mobile #mobile-emul #tv #ivi #wearable Tizen.Applications.WatchApplication.dll #wearable -Tizen.Applications.WidgetApplication.dll #mobile #mobile-emul #tv #ivi -Tizen.Applications.WidgetControl.dll #mobile #mobile-emul #tv #ivi +Tizen.Applications.WidgetApplication.dll #mobile #mobile-emul #tv #ivi #wearable +Tizen.Applications.WidgetControl.dll #mobile #mobile-emul #tv #ivi #wearable Tizen.Content.Download.dll #common #mobile #mobile-emul #tv #ivi #wearable Tizen.Content.MediaContent.dll #common #mobile #mobile-emul #tv #ivi #wearable Tizen.Content.MimeType.dll #common #mobile #mobile-emul #tv #ivi #wearable diff --git a/src/Tizen.Multimedia.Remoting/Interop/Interop.MediaController.cs b/src/Tizen.Multimedia.Remoting/Interop/Interop.MediaController.cs deleted file mode 100644 index 7efbf0a..0000000 --- a/src/Tizen.Multimedia.Remoting/Interop/Interop.MediaController.cs +++ /dev/null @@ -1,202 +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. - */ - -using System; -using System.Runtime.InteropServices; -using Tizen.Applications; -using Tizen.Multimedia; -using Tizen.Multimedia.MediaController; - -internal static partial class Interop -{ - internal static partial class MediaControllerClient - { - [UnmanagedFunctionPointer(CallingConvention.Cdecl)] - internal delegate void ServerUpdatedCallback(IntPtr serverName, MediaControllerServerState serverState, IntPtr userData); - - [UnmanagedFunctionPointer(CallingConvention.Cdecl)] - internal delegate void PlaybackUpdatedCallback(IntPtr serverName, IntPtr playback, IntPtr userData); - - [UnmanagedFunctionPointer(CallingConvention.Cdecl)] - internal delegate void MetadataUpdatedCallback(IntPtr serverName, IntPtr metadata, IntPtr userData); - - [UnmanagedFunctionPointer(CallingConvention.Cdecl)] - internal delegate void ShuffleModeUpdatedCallback(IntPtr serverName, MediaControllerShuffleMode shuffleMode, IntPtr userData); - - [UnmanagedFunctionPointer(CallingConvention.Cdecl)] - internal delegate void RepeatModeUpdatedCallback(IntPtr serverName, MediaControllerRepeatMode repeatMode, IntPtr userData); - - [UnmanagedFunctionPointer(CallingConvention.Cdecl)] - internal delegate void CommandReplyRecievedCallback(IntPtr serverName, int result, IntPtr bundle, IntPtr userData); - - [UnmanagedFunctionPointer(CallingConvention.Cdecl)] - internal delegate bool SubscribedServerCallback(IntPtr serverName, IntPtr userData); - - [UnmanagedFunctionPointer(CallingConvention.Cdecl)] - internal delegate bool ActivatedServerCallback(IntPtr serverName, IntPtr userData); - - [DllImport(Libraries.MediaController, EntryPoint = "mc_client_create")] - internal static extern MediaControllerError Create(out IntPtr handle); - - [DllImport(Libraries.MediaController, EntryPoint = "mc_client_destroy")] - internal static extern MediaControllerError Destroy(IntPtr handle); - - [DllImport(Libraries.MediaController, EntryPoint = "mc_client_set_server_update_cb")] - internal static extern MediaControllerError SetServerUpdatedCb(IntPtr handle, ServerUpdatedCallback callback, IntPtr userData); - - [DllImport(Libraries.MediaController, EntryPoint = "mc_client_unset_server_update_cb")] - internal static extern MediaControllerError UnsetServerUpdatedCb(IntPtr handle); - - [DllImport(Libraries.MediaController, EntryPoint = "mc_client_set_playback_update_cb")] - internal static extern MediaControllerError SetPlaybackUpdatedCb(IntPtr handle, PlaybackUpdatedCallback callback, IntPtr userData); - - [DllImport(Libraries.MediaController, EntryPoint = "mc_client_unset_playback_update_cb")] - internal static extern MediaControllerError UnsetPlaybackUpdatedCb(IntPtr handle); - - [DllImport(Libraries.MediaController, EntryPoint = "mc_client_set_metadata_update_cb")] - internal static extern MediaControllerError SetMetadataUpdatedCb(IntPtr handle, MetadataUpdatedCallback callback, IntPtr userData); - - [DllImport(Libraries.MediaController, EntryPoint = "mc_client_unset_metadata_update_cb")] - internal static extern MediaControllerError UnsetMetadataUpdatedCb(IntPtr handle); - - [DllImport(Libraries.MediaController, EntryPoint = "mc_client_set_shuffle_mode_update_cb")] - internal static extern MediaControllerError SetShuffleModeUpdatedCb(IntPtr handle, ShuffleModeUpdatedCallback callback, IntPtr userData); - - [DllImport(Libraries.MediaController, EntryPoint = "mc_client_unset_shuffle_mode_update_cb")] - internal static extern MediaControllerError UnsetShuffleModeUpdatedCb(IntPtr handle); - - [DllImport(Libraries.MediaController, EntryPoint = "mc_client_set_repeat_mode_update_cb")] - internal static extern MediaControllerError SetRepeatModeUpdatedCb(IntPtr handle, RepeatModeUpdatedCallback callback, IntPtr userData); - - [DllImport(Libraries.MediaController, EntryPoint = "mc_client_unset_repeat_mode_update_cb")] - internal static extern MediaControllerError UnsetRepeatModeUpdatedCb(IntPtr handle); - - [DllImport(Libraries.MediaController, EntryPoint = "mc_client_subscribe")] - internal static extern MediaControllerError Subscribe(IntPtr handle, MediaControllerSubscriptionType subscriptionType, string serverName); - - [DllImport(Libraries.MediaController, EntryPoint = "mc_client_unsubscribe")] - internal static extern MediaControllerError Unsubscribe(IntPtr handle, MediaControllerSubscriptionType subscriptionType, string serverName); - - [DllImport(Libraries.MediaController, EntryPoint = "mc_client_get_playback_state")] - internal static extern MediaControllerError GetPlaybackState(IntPtr playback, out MediaControllerPlaybackState state); - - [DllImport(Libraries.MediaController, EntryPoint = "mc_client_get_playback_position")] - internal static extern MediaControllerError GetPlaybackPosition(IntPtr playback, out ulong position); - - [DllImport(Libraries.MediaController, EntryPoint = "mc_client_destroy_playback")] - internal static extern MediaControllerError DestroyPlayback(IntPtr playback); - - [DllImport(Libraries.MediaController, EntryPoint = "mc_client_get_metadata")] - private static extern MediaControllerError GetMetadata(IntPtr metadata, MediaControllerAttributes attribute, out IntPtr value); - - internal static string GetMetadata(IntPtr handle, MediaControllerAttributes attr) - { - IntPtr valuePtr = IntPtr.Zero; - - try - { - var ret = GetMetadata(handle, attr, out valuePtr); - MediaControllerValidator.ThrowIfError(ret, "Failed to get value for " + attr); - return Marshal.PtrToStringAnsi(valuePtr); - } - finally - { - LibcSupport.Free(valuePtr); - } - } - - [DllImport(Libraries.MediaController, EntryPoint = "mc_client_destroy_metadata")] - internal static extern MediaControllerError DestroyMetadata(IntPtr metadata); - - [DllImport(Libraries.MediaController, EntryPoint = "mc_client_get_latest_server_info")] - internal static extern MediaControllerError GetLatestServer(IntPtr handle, out IntPtr serverName, out MediaControllerServerState serverState); - - [DllImport(Libraries.MediaController, EntryPoint = "mc_client_get_server_playback_info")] - internal static extern MediaControllerError GetServerPlayback(IntPtr handle, string serverName, out IntPtr playback); - - [DllImport(Libraries.MediaController, EntryPoint = "mc_client_get_server_metadata")] - internal static extern MediaControllerError GetServerMetadata(IntPtr handle, string serverName, out IntPtr metadata); - - [DllImport(Libraries.MediaController, EntryPoint = "mc_client_get_server_shuffle_mode")] - internal static extern MediaControllerError GetServerShuffleMode(IntPtr handle, string serverName, out MediaControllerShuffleMode mode); - - [DllImport(Libraries.MediaController, EntryPoint = "mc_client_get_server_repeat_mode")] - internal static extern MediaControllerError GetServerRepeatMode(IntPtr handle, string serverName, out MediaControllerRepeatMode mode); - - [DllImport(Libraries.MediaController, EntryPoint = "mc_client_send_playback_state_command")] - internal static extern MediaControllerError SendPlaybackStateCommand(IntPtr handle, string serverName, MediaControllerPlaybackState state); - - [DllImport(Libraries.MediaController, EntryPoint = "mc_client_send_custom_command")] - internal static extern MediaControllerError SendCustomCommand(IntPtr handle, string serverName, string command, SafeBundleHandle bundle, CommandReplyRecievedCallback callback, IntPtr userData); - - [DllImport(Libraries.MediaController, EntryPoint = "mc_client_foreach_server_subscribed")] - internal static extern MediaControllerError ForeachSubscribedServer(IntPtr handle, MediaControllerSubscriptionType subscriptionType, SubscribedServerCallback callback, IntPtr userData); - - [DllImport(Libraries.MediaController, EntryPoint = "mc_client_foreach_server")] - internal static extern MediaControllerError ForeachActivatedServer(IntPtr handle, ActivatedServerCallback callback, IntPtr userData); - } - - internal static partial class MediaControllerServer - { - [UnmanagedFunctionPointer(CallingConvention.Cdecl)] - internal delegate void PlaybackStateCommandRecievedCallback(IntPtr clientName, MediaControllerPlaybackState state, IntPtr userData); - - [UnmanagedFunctionPointer(CallingConvention.Cdecl)] - internal delegate void CustomCommandRecievedCallback(IntPtr clientName, IntPtr command, IntPtr bundle, IntPtr userData); - - [DllImport(Libraries.MediaController, EntryPoint = "mc_server_create")] - internal static extern MediaControllerError Create(out IntPtr handle); - - [DllImport(Libraries.MediaController, EntryPoint = "mc_server_destroy")] - internal static extern MediaControllerError Destroy(IntPtr handle); - - [DllImport(Libraries.MediaController, EntryPoint = "mc_server_set_playback_state")] - internal static extern MediaControllerError SetPlaybackState(IntPtr handle, MediaControllerPlaybackState state); - - [DllImport(Libraries.MediaController, EntryPoint = "mc_server_set_playback_position")] - internal static extern MediaControllerError SetPlaybackPosition(IntPtr handle, ulong position); - - [DllImport(Libraries.MediaController, EntryPoint = "mc_server_update_playback_info")] - internal static extern MediaControllerError UpdatePlayback(IntPtr handle); - - [DllImport(Libraries.MediaController, EntryPoint = "mc_server_set_metadata")] - internal static extern MediaControllerError SetMetadata(IntPtr handle, MediaControllerAttributes attribute, string value); - - [DllImport(Libraries.MediaController, EntryPoint = "mc_server_update_metadata")] - internal static extern MediaControllerError UpdateMetadata(IntPtr handle); - - [DllImport(Libraries.MediaController, EntryPoint = "mc_server_update_shuffle_mode")] - internal static extern MediaControllerError UpdateShuffleMode(IntPtr handle, MediaControllerShuffleMode mode); - - [DllImport(Libraries.MediaController, EntryPoint = "mc_server_update_repeat_mode")] - internal static extern MediaControllerError UpdateRepeatMode(IntPtr handle, MediaControllerRepeatMode mode); - - [DllImport(Libraries.MediaController, EntryPoint = "mc_server_set_playback_state_command_received_cb")] - internal static extern MediaControllerError SetPlaybackStateCmdRecvCb(IntPtr handle, PlaybackStateCommandRecievedCallback callback, IntPtr userData); - - [DllImport(Libraries.MediaController, EntryPoint = "mc_server_unset_playback_state_command_received_cb")] - internal static extern MediaControllerError UnsetPlaybackStateCmdRecvCb(IntPtr handle); - - [DllImport(Libraries.MediaController, EntryPoint = "mc_server_set_custom_command_received_cb")] - internal static extern MediaControllerError SetCustomCmdRecvCb(IntPtr handle, CustomCommandRecievedCallback callback, IntPtr userData); - - [DllImport(Libraries.MediaController, EntryPoint = "mc_server_unset_custom_command_received_cb")] - internal static extern MediaControllerError UnsetCustomCmdRecvCb(IntPtr handle); - - [DllImport(Libraries.MediaController, EntryPoint = "mc_server_send_command_reply")] - internal static extern MediaControllerError SendCommandReply(IntPtr handle, string clientName, int result, SafeBundleHandle bundle); - } -} diff --git a/src/Tizen.Multimedia.Remoting/Interop/Interop.MediaControllerClient.cs b/src/Tizen.Multimedia.Remoting/Interop/Interop.MediaControllerClient.cs new file mode 100644 index 0000000..2029564 --- /dev/null +++ b/src/Tizen.Multimedia.Remoting/Interop/Interop.MediaControllerClient.cs @@ -0,0 +1,166 @@ +/* + * 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.Runtime.InteropServices; +using Tizen.Multimedia.Remoting; + +internal static partial class Interop +{ + internal static partial class MediaControllerClient + { + [UnmanagedFunctionPointer(CallingConvention.Cdecl)] + internal delegate void ServerUpdatedCallback(string serverName, MediaControllerServerState serverState, + IntPtr userData); + + [UnmanagedFunctionPointer(CallingConvention.Cdecl)] + internal delegate void PlaybackUpdatedCallback(string serverName, IntPtr playback, IntPtr userData); + + [UnmanagedFunctionPointer(CallingConvention.Cdecl)] + internal delegate void MetadataUpdatedCallback(string serverName, IntPtr metadata, IntPtr userData); + + [UnmanagedFunctionPointer(CallingConvention.Cdecl)] + internal delegate void ShuffleModeUpdatedCallback(string serverName, MediaControllerShuffleMode shuffleMode, + IntPtr userData); + + [UnmanagedFunctionPointer(CallingConvention.Cdecl)] + internal delegate void RepeatModeUpdatedCallback(string serverName, NativeRepeatMode repeatMode, IntPtr userData); + + [UnmanagedFunctionPointer(CallingConvention.Cdecl)] + internal delegate bool ActivatedServerCallback(string serverName, IntPtr userData); + + [DllImport(Libraries.MediaController, EntryPoint = "mc_client_create")] + internal static extern MediaControllerError Create(out MediaControllerClientHandle handle); + + [DllImport(Libraries.MediaController, EntryPoint = "mc_client_destroy")] + internal static extern MediaControllerError Destroy(IntPtr handle); + + [DllImport(Libraries.MediaController, EntryPoint = "mc_client_set_server_update_cb")] + internal static extern MediaControllerError SetServerUpdatedCb(MediaControllerClientHandle handle, + ServerUpdatedCallback callback, IntPtr userData = default(IntPtr)); + + [DllImport(Libraries.MediaController, EntryPoint = "mc_client_unset_server_update_cb")] + internal static extern MediaControllerError UnsetServerUpdatedCb(MediaControllerClientHandle handle); + + [DllImport(Libraries.MediaController, EntryPoint = "mc_client_set_playback_update_cb")] + internal static extern MediaControllerError SetPlaybackUpdatedCb(MediaControllerClientHandle handle, + PlaybackUpdatedCallback callback, IntPtr userData = default(IntPtr)); + + [DllImport(Libraries.MediaController, EntryPoint = "mc_client_unset_playback_update_cb")] + internal static extern MediaControllerError UnsetPlaybackUpdatedCb(MediaControllerClientHandle handle); + + [DllImport(Libraries.MediaController, EntryPoint = "mc_client_set_metadata_update_cb")] + internal static extern MediaControllerError SetMetadataUpdatedCb(MediaControllerClientHandle handle, + MetadataUpdatedCallback callback, IntPtr userData = default(IntPtr)); + + [DllImport(Libraries.MediaController, EntryPoint = "mc_client_unset_metadata_update_cb")] + internal static extern MediaControllerError UnsetMetadataUpdatedCb(MediaControllerClientHandle handle); + + [DllImport(Libraries.MediaController, EntryPoint = "mc_client_set_shuffle_mode_update_cb")] + internal static extern MediaControllerError SetShuffleModeUpdatedCb(MediaControllerClientHandle handle, + ShuffleModeUpdatedCallback callback, IntPtr userData = default(IntPtr)); + + [DllImport(Libraries.MediaController, EntryPoint = "mc_client_unset_shuffle_mode_update_cb")] + internal static extern MediaControllerError UnsetShuffleModeUpdatedCb(MediaControllerClientHandle handle); + + [DllImport(Libraries.MediaController, EntryPoint = "mc_client_set_repeat_mode_update_cb")] + internal static extern MediaControllerError SetRepeatModeUpdatedCb(MediaControllerClientHandle handle, + RepeatModeUpdatedCallback callback, IntPtr userData = default(IntPtr)); + + [DllImport(Libraries.MediaController, EntryPoint = "mc_client_unset_repeat_mode_update_cb")] + internal static extern MediaControllerError UnsetRepeatModeUpdatedCb(MediaControllerClientHandle handle); + + [DllImport(Libraries.MediaController, EntryPoint = "mc_client_get_playback_state")] + internal static extern MediaControllerError GetPlaybackState(IntPtr playback, out MediaControllerPlaybackCode state); + + [DllImport(Libraries.MediaController, EntryPoint = "mc_client_get_playback_position")] + internal static extern MediaControllerError GetPlaybackPosition(IntPtr playback, out ulong position); + + [DllImport(Libraries.MediaController, EntryPoint = "mc_client_destroy_playback")] + internal static extern MediaControllerError DestroyPlayback(IntPtr playback); + + [DllImport(Libraries.MediaController, EntryPoint = "mc_client_get_metadata")] + private static extern MediaControllerError GetMetadata(IntPtr metadata, MediaControllerAttribute attribute, + out IntPtr value); + + internal static string GetMetadata(IntPtr handle, MediaControllerAttribute attr) + { + IntPtr valuePtr = IntPtr.Zero; + + try + { + GetMetadata(handle, attr, out valuePtr).ThrowIfError($"Failed to get value for {attr}."); + return Marshal.PtrToStringAnsi(valuePtr); + } + finally + { + Tizen.Multimedia.LibcSupport.Free(valuePtr); + } + } + + [DllImport(Libraries.MediaController, EntryPoint = "mc_client_destroy_metadata")] + internal static extern MediaControllerError DestroyMetadata(IntPtr metadata); + + [DllImport(Libraries.MediaController, EntryPoint = "mc_client_get_latest_server_info")] + internal static extern MediaControllerError GetLatestServer(MediaControllerClientHandle handle, + out IntPtr serverName, out MediaControllerServerState serverState); + + [DllImport(Libraries.MediaController, EntryPoint = "mc_client_get_server_playback_info")] + internal static extern MediaControllerError GetServerPlayback(MediaControllerClientHandle handle, + string serverName, out IntPtr playback); + + [DllImport(Libraries.MediaController, EntryPoint = "mc_client_get_server_metadata")] + internal static extern MediaControllerError GetServerMetadata(MediaControllerClientHandle handle, + string serverName, out IntPtr metadata); + + [DllImport(Libraries.MediaController, EntryPoint = "mc_client_get_server_shuffle_mode")] + internal static extern MediaControllerError GetServerShuffleMode(MediaControllerClientHandle handle, + string serverName, out MediaControllerShuffleMode mode); + + [DllImport(Libraries.MediaController, EntryPoint = "mc_client_get_server_repeat_mode")] + internal static extern MediaControllerError GetServerRepeatMode(MediaControllerClientHandle handle, + string serverName, out NativeRepeatMode mode); + + [DllImport(Libraries.MediaController, EntryPoint = "mc_client_send_playback_state_command")] + internal static extern MediaControllerError SendPlaybackStateCommand(MediaControllerClientHandle handle, + string serverName, MediaControllerPlaybackCode command); + + [DllImport(Libraries.MediaController, EntryPoint = "mc_client_foreach_server")] + internal static extern MediaControllerError ForeachActivatedServer(MediaControllerClientHandle handle, + ActivatedServerCallback callback, IntPtr userData); + } + + internal class MediaControllerClientHandle : SafeHandle + { + protected MediaControllerClientHandle() : base(IntPtr.Zero, true) + { + } + + public override bool IsInvalid => handle == IntPtr.Zero; + + protected override bool ReleaseHandle() + { + var ret = MediaControllerClient.Destroy(handle); + if (ret != MediaControllerError.None) + { + Tizen.Log.Debug(GetType().FullName, $"Failed to release native {GetType().Name}"); + return false; + } + + return true; + } + } +} diff --git a/src/Tizen.Multimedia.Remoting/Interop/Interop.MediaControllerServer.cs b/src/Tizen.Multimedia.Remoting/Interop/Interop.MediaControllerServer.cs new file mode 100644 index 0000000..6fe514d --- /dev/null +++ b/src/Tizen.Multimedia.Remoting/Interop/Interop.MediaControllerServer.cs @@ -0,0 +1,66 @@ +/* + * 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.Runtime.InteropServices; +using Tizen.Multimedia.Remoting; + +internal static partial class Interop +{ + internal static partial class MediaControllerServer + { + [UnmanagedFunctionPointer(CallingConvention.Cdecl)] + internal delegate void PlaybackStateCommandReceivedCallback(string clientName, + MediaControllerPlaybackCode state, IntPtr userData); + + [DllImport(Libraries.MediaController, EntryPoint = "mc_server_create")] + internal static extern MediaControllerError Create(out IntPtr handle); + + [DllImport(Libraries.MediaController, EntryPoint = "mc_server_destroy")] + internal static extern MediaControllerError Destroy(IntPtr handle); + + [DllImport(Libraries.MediaController, EntryPoint = "mc_server_set_playback_state")] + internal static extern MediaControllerError SetPlaybackState(IntPtr handle, + MediaControllerPlaybackCode state); + + [DllImport(Libraries.MediaController, EntryPoint = "mc_server_set_playback_position")] + internal static extern MediaControllerError SetPlaybackPosition(IntPtr handle, ulong position); + + [DllImport(Libraries.MediaController, EntryPoint = "mc_server_update_playback_info")] + internal static extern MediaControllerError UpdatePlayback(IntPtr handle); + + [DllImport(Libraries.MediaController, EntryPoint = "mc_server_set_metadata")] + internal static extern MediaControllerError SetMetadata(IntPtr handle, + MediaControllerAttribute attribute, string value); + + [DllImport(Libraries.MediaController, EntryPoint = "mc_server_update_metadata")] + internal static extern MediaControllerError UpdateMetadata(IntPtr handle); + + [DllImport(Libraries.MediaController, EntryPoint = "mc_server_update_shuffle_mode")] + internal static extern MediaControllerError UpdateShuffleMode(IntPtr handle, + MediaControllerShuffleMode mode); + + [DllImport(Libraries.MediaController, EntryPoint = "mc_server_update_repeat_mode")] + internal static extern MediaControllerError UpdateRepeatMode(IntPtr handle, NativeRepeatMode mode); + + [DllImport(Libraries.MediaController, EntryPoint = "mc_server_set_playback_state_command_received_cb")] + internal static extern MediaControllerError SetPlaybackStateCmdRecvCb(IntPtr handle, + PlaybackStateCommandReceivedCallback callback, IntPtr userData = default(IntPtr)); + + [DllImport(Libraries.MediaController, EntryPoint = "mc_server_unset_playback_state_command_received_cb")] + internal static extern MediaControllerError UnsetPlaybackStateCmdRecvCb(IntPtr handle); + } +} diff --git a/src/Tizen.Multimedia.Remoting/MediaController/CustomCommandEventArgs.cs b/src/Tizen.Multimedia.Remoting/MediaController/CustomCommandEventArgs.cs deleted file mode 100755 index a485e3f..0000000 --- a/src/Tizen.Multimedia.Remoting/MediaController/CustomCommandEventArgs.cs +++ /dev/null @@ -1,57 +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. -*/ - -using System; -using Tizen.Applications; - -namespace Tizen.Multimedia.MediaController -{ - - /// - /// CustomCommandRecieved event arguments - /// - /// - /// CustomCommandRecieved event arguments - /// - public class CustomCommandEventArgs : EventArgs - { - internal CustomCommandEventArgs(string name, string command, Bundle bundle) - { - ClientName = name; - Command = command; - BundleData = bundle; - } - - /// - /// Get the Client Name. - /// - /// 3 - public string ClientName { get; } - - /// - /// Get the Custom Command. - /// - /// 3 - public string Command { get; } - - /// - /// Get the Bundle Data. - /// - /// 3 - public Bundle BundleData { get; } - } -} - diff --git a/src/Tizen.Multimedia.Remoting/MediaController/CustomCommandReplyEventArgs.cs b/src/Tizen.Multimedia.Remoting/MediaController/CustomCommandReplyEventArgs.cs deleted file mode 100755 index e7bac0e..0000000 --- a/src/Tizen.Multimedia.Remoting/MediaController/CustomCommandReplyEventArgs.cs +++ /dev/null @@ -1,57 +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. -*/ - -using System; -using Tizen.Applications; - -namespace Tizen.Multimedia.MediaController -{ - - /// - /// CustomCommandRecieved event arguments - /// - /// - /// CustomCommandRecieved event arguments - /// - public class CustomCommandReplyEventArgs : EventArgs - { - internal CustomCommandReplyEventArgs(string serverName, int result, Bundle bundle) - { - ServerName = serverName; - Result = result; - BundleData = bundle; - } - - /// - /// Get the Sserver Name. - /// - /// 3 - public string ServerName { get; } - - /// - /// Get the Result. - /// - /// 3 - public int Result { get; } - - /// - /// Get the Bundle Data. - /// - /// 3 - public Bundle BundleData { get; } - } -} - diff --git a/src/Tizen.Multimedia.Remoting/MediaController/EnumExtensions.cs b/src/Tizen.Multimedia.Remoting/MediaController/EnumExtensions.cs new file mode 100644 index 0000000..d49135e --- /dev/null +++ b/src/Tizen.Multimedia.Remoting/MediaController/EnumExtensions.cs @@ -0,0 +1,99 @@ +/* + * 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.Diagnostics; + +namespace Tizen.Multimedia.Remoting +{ + internal static class EnumExtensions + { + internal static MediaControlPlaybackState ToState(this MediaControllerPlaybackCode code) + { + switch (code) + { + case MediaControllerPlaybackCode.None: return MediaControlPlaybackState.None; + case MediaControllerPlaybackCode.Play: return MediaControlPlaybackState.Playing; + case MediaControllerPlaybackCode.Pause: return MediaControlPlaybackState.Paused; + case MediaControllerPlaybackCode.Stop: return MediaControlPlaybackState.Stopped; + case MediaControllerPlaybackCode.FastForward: return MediaControlPlaybackState.FastForwarding; + case MediaControllerPlaybackCode.Rewind: return MediaControlPlaybackState.Rewinding; + } + + Debug.Fail($"Not supported code for playback state{code}."); + return MediaControlPlaybackState.None; + } + + internal static MediaControllerPlaybackCode ToCode(this MediaControlPlaybackState state) + { + switch (state) + { + case MediaControlPlaybackState.Playing: return MediaControllerPlaybackCode.Play; + case MediaControlPlaybackState.Paused: return MediaControllerPlaybackCode.Pause; + case MediaControlPlaybackState.Stopped: return MediaControllerPlaybackCode.Stop; + case MediaControlPlaybackState.FastForwarding: return MediaControllerPlaybackCode.FastForward; + case MediaControlPlaybackState.Rewinding: return MediaControllerPlaybackCode.Rewind; + } + return MediaControllerPlaybackCode.None; + } + + internal static MediaControlPlaybackCommand ToCommand(this MediaControllerPlaybackCode code) + { + switch (code) + { + case MediaControllerPlaybackCode.Play: return MediaControlPlaybackCommand.Play; + case MediaControllerPlaybackCode.Pause: return MediaControlPlaybackCommand.Pause; + case MediaControllerPlaybackCode.Stop: return MediaControlPlaybackCommand.Stop; + case MediaControllerPlaybackCode.Next: return MediaControlPlaybackCommand.Next; + case MediaControllerPlaybackCode.Prev: return MediaControlPlaybackCommand.Previous; + case MediaControllerPlaybackCode.FastForward: return MediaControlPlaybackCommand.FastForward; + case MediaControllerPlaybackCode.Rewind: return MediaControlPlaybackCommand.Rewind; + } + + Debug.Fail($"Not supported code for playback command{code}."); + return MediaControlPlaybackCommand.Play; + } + + internal static MediaControllerPlaybackCode ToCode(this MediaControlPlaybackCommand command) + { + switch (command) + { + case MediaControlPlaybackCommand.Play: return MediaControllerPlaybackCode.Play; + case MediaControlPlaybackCommand.Pause: return MediaControllerPlaybackCode.Pause; + case MediaControlPlaybackCommand.Stop: return MediaControllerPlaybackCode.Stop; + case MediaControlPlaybackCommand.Next: return MediaControllerPlaybackCode.Next; + case MediaControlPlaybackCommand.Previous: return MediaControllerPlaybackCode.Prev; + case MediaControlPlaybackCommand.FastForward: return MediaControllerPlaybackCode.FastForward; + case MediaControlPlaybackCommand.Rewind: return MediaControllerPlaybackCode.Rewind; + } + return MediaControllerPlaybackCode.Play; + } + + internal static NativeRepeatMode ToNative(this MediaControlRepeatMode mode) + { + Debug.Assert(Enum.IsDefined(typeof(MediaControlRepeatMode), mode)); + + return mode == MediaControlRepeatMode.Off ? NativeRepeatMode.On : NativeRepeatMode.Off; + } + + internal static MediaControlRepeatMode ToPublic(this NativeRepeatMode mode) + { + Debug.Assert(Enum.IsDefined(typeof(NativeRepeatMode), mode)); + + return mode == NativeRepeatMode.Off ? MediaControlRepeatMode.On : MediaControlRepeatMode.Off; + } + } +} \ No newline at end of file diff --git a/src/Tizen.Multimedia.Remoting/MediaController/InternalEnums.cs b/src/Tizen.Multimedia.Remoting/MediaController/InternalEnums.cs new file mode 100644 index 0000000..b25c43b --- /dev/null +++ b/src/Tizen.Multimedia.Remoting/MediaController/InternalEnums.cs @@ -0,0 +1,66 @@ +/* + * 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.Diagnostics; + +namespace Tizen.Multimedia.Remoting +{ + internal enum MediaControllerPlaybackCode + { + None, + Play, + Pause, + Stop, + Next, + Prev, + FastForward, + Rewind, + } + + internal enum MediaControllerServerState + { + None, + Activated, + Deactivated, + } + + internal enum MediaControllerShuffleMode + { + On, + Off, + } + + internal enum NativeRepeatMode + { + On, + Off, + } + + internal enum MediaControllerAttribute + { + Title, + Artist, + Album, + Author, + Genre, + Duration, + Date, + Copyright, + Description, + TrackNumber, + Picture, + } +} \ No newline at end of file diff --git a/src/Tizen.Multimedia.Remoting/MediaController/MediaControlMetadata.cs b/src/Tizen.Multimedia.Remoting/MediaController/MediaControlMetadata.cs new file mode 100644 index 0000000..8ec676d --- /dev/null +++ b/src/Tizen.Multimedia.Remoting/MediaController/MediaControlMetadata.cs @@ -0,0 +1,107 @@ +/* + * 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.Diagnostics; +using Native = Interop.MediaControllerClient; + +namespace Tizen.Multimedia.Remoting +{ + /// + /// Represents metadata for media control. + /// + public class MediaControlMetadata + { + /// + /// Initializes a new instance of the class. + /// + public MediaControlMetadata() + { + } + + internal MediaControlMetadata(IntPtr handle) + { + Debug.Assert(handle != IntPtr.Zero); + + Title = Native.GetMetadata(handle, MediaControllerAttribute.Title); + Artist = Native.GetMetadata(handle, MediaControllerAttribute.Artist); + Album = Native.GetMetadata(handle, MediaControllerAttribute.Album); + Author = Native.GetMetadata(handle, MediaControllerAttribute.Author); + Genre = Native.GetMetadata(handle, MediaControllerAttribute.Genre); + Duration = Native.GetMetadata(handle, MediaControllerAttribute.Duration); + Date = Native.GetMetadata(handle, MediaControllerAttribute.Date); + Copyright = Native.GetMetadata(handle, MediaControllerAttribute.Copyright); + Description = Native.GetMetadata(handle, MediaControllerAttribute.Description); + TrackNumber = Native.GetMetadata(handle, MediaControllerAttribute.TrackNumber); + AlbumArtPath = Native.GetMetadata(handle, MediaControllerAttribute.Picture); + } + + /// + /// Gets or sets the title. + /// + public string Title { get; set; } + + /// + /// Gets or sets the artist. + /// + public string Artist { get; set; } + + /// + /// Gets or sets the album. + /// + public string Album { get; set; } + + /// + /// Gets or sets the author. + /// + public string Author { get; set; } + + /// + /// Gets or sets the genre. + /// + public string Genre { get; set; } + + /// + /// Gets or sets the duration. + /// + public string Duration { get; set; } + + /// + /// Gets or sets the date. + /// + public string Date { get; set; } + + /// + /// Gets or sets the copyright. + /// + public string Copyright { get; set; } + + /// + /// Gets or sets the description. + /// + public string Description { get; set; } + + /// + /// Gets or sets the track number. + /// + public string TrackNumber { get; set; } + + /// + /// Gets or sets the path of the album art. + /// + public string AlbumArtPath { get; set; } + } +} \ No newline at end of file diff --git a/src/Tizen.Multimedia.Remoting/MediaController/MediaControlPlaybackCommand.cs b/src/Tizen.Multimedia.Remoting/MediaController/MediaControlPlaybackCommand.cs new file mode 100644 index 0000000..664eb19 --- /dev/null +++ b/src/Tizen.Multimedia.Remoting/MediaController/MediaControlPlaybackCommand.cs @@ -0,0 +1,59 @@ +/* + * 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. + /// + public enum MediaControlPlaybackCommand + { + /// + /// Play. + /// + Play, + + /// + /// Pause. + /// + Pause, + + /// + /// Stop. + /// + Stop, + + /// + /// Skip to next. + /// + Next, + + /// + /// Skip to previous. + /// + Previous, + + /// + /// Fast forward. + /// + FastForward, + + /// + /// Rewind. + /// + Rewind, + } +} \ No newline at end of file diff --git a/src/Tizen.Multimedia.Remoting/MediaController/MediaControlPlaybackState.cs b/src/Tizen.Multimedia.Remoting/MediaController/MediaControlPlaybackState.cs new file mode 100644 index 0000000..e1f3fc1 --- /dev/null +++ b/src/Tizen.Multimedia.Remoting/MediaController/MediaControlPlaybackState.cs @@ -0,0 +1,54 @@ +/* + * 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 states. + /// + public enum MediaControlPlaybackState + { + /// + /// Unknown; no state is set. + /// + None, + + /// + /// Playing. + /// + Playing, + + /// + /// Paused. + /// + Paused, + + /// + /// Stopped. + /// + Stopped, + + /// + /// Fast forwarding. + /// + FastForwarding, + + /// + /// Rewinding. + /// + Rewinding, + } +} \ No newline at end of file diff --git a/src/Tizen.Multimedia.Remoting/MediaController/MediaControlServer.cs b/src/Tizen.Multimedia.Remoting/MediaController/MediaControlServer.cs new file mode 100644 index 0000000..f4fcdf2 --- /dev/null +++ b/src/Tizen.Multimedia.Remoting/MediaController/MediaControlServer.cs @@ -0,0 +1,231 @@ +/* + * 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 Native = Interop.MediaControllerServer; + +namespace Tizen.Multimedia.Remoting +{ + /// + /// Provides a means to set playback information and metadata and receive commands from clients. + /// + /// + /// + public static class MediaControlServer + { + private static IntPtr _handle = IntPtr.Zero; + + /// + /// Gets a value indicating whether the server is running. + /// + /// true if the server has started; otherwise, false. + /// + /// + public static bool IsRunning + { + get => _handle != IntPtr.Zero; + } + + private static void ThrowIfNotRunning() + { + if (IsRunning == false) + { + throw new InvalidOperationException("The server is not running."); + } + } + + private static IntPtr Handle + { + get + { + ThrowIfNotRunning(); + + return _handle; + } + } + + /// + /// Starts the media control server. + /// + /// + /// When the server starts, will be raised. + /// + /// http://tizen.org/privilege/mediacontroller.server + /// + /// The server has already started.\n + /// -or-\n + /// An internal error occurs. + /// + /// Caller does not have required privilege. + /// + public static void Start() + { + if (IsRunning) + { + throw new InvalidOperationException("The server is already running."); + } + + Native.Create(out _handle).ThrowIfError("Failed to create media controller server."); + + try + { + RegisterPlaybackCommandReceivedEvent(); + } + catch + { + Native.Destroy(_handle); + _playbackCommandCallback = null; + _handle = IntPtr.Zero; + throw; + } + } + + /// + /// Stops the media control server. + /// + /// + /// When the server stops, will be raised. + /// + /// + /// The server is not running .\n + /// -or-\n + /// An internal error occurs. + /// + /// + public static void Stop() + { + ThrowIfNotRunning(); + + Native.Destroy(_handle).ThrowIfError("Failed to stop the server."); + + _handle = IntPtr.Zero; + _playbackCommandCallback = null; + } + + /// + /// Updates playback state and playback position. + /// The playback state. + /// The playback position in milliseconds. + /// is not valid. + /// is less than zero. + /// + /// The server is not running .\n + /// -or-\n + /// An internal error occurs. + /// + public static void SetPlaybackState(MediaControlPlaybackState state, long position) + { + ValidationUtil.ValidateEnum(typeof(MediaControlPlaybackState), state, nameof(state)); + + if (position < 0) + { + throw new ArgumentOutOfRangeException(nameof(position), position, "position can't be less than zero."); + } + + Native.SetPlaybackState(Handle, state.ToCode()).ThrowIfError("Failed to set playback state."); + + Native.SetPlaybackPosition(Handle, (ulong)position).ThrowIfError("Failed to set playback position."); + + Native.UpdatePlayback(Handle).ThrowIfError("Failed to set playback."); + } + + private static void SetMetadata(MediaControllerAttribute attribute, string value) + { + Native.SetMetadata(Handle, attribute, value).ThrowIfError($"Failed to set metadata({attribute})."); + } + + /// + /// Updates metadata information. + /// + /// The metadata to update. + /// is null. + /// + /// The server is not running .\n + /// -or-\n + /// An internal error occurs. + /// + public static void SetMetadata(MediaControlMetadata metadata) + { + if (metadata == null) + { + throw new ArgumentNullException(nameof(metadata)); + } + + SetMetadata(MediaControllerAttribute.Title, metadata.Title); + SetMetadata(MediaControllerAttribute.Artist, metadata.Artist); + SetMetadata(MediaControllerAttribute.Album, metadata.Album); + SetMetadata(MediaControllerAttribute.Author, metadata.Author); + SetMetadata(MediaControllerAttribute.Genre, metadata.Genre); + SetMetadata(MediaControllerAttribute.Duration, metadata.Duration); + SetMetadata(MediaControllerAttribute.Date, metadata.Date); + SetMetadata(MediaControllerAttribute.Copyright, metadata.Copyright); + SetMetadata(MediaControllerAttribute.Description, metadata.Description); + SetMetadata(MediaControllerAttribute.TrackNumber, metadata.TrackNumber); + SetMetadata(MediaControllerAttribute.Picture, metadata.AlbumArtPath); + + Native.UpdateMetadata(Handle).ThrowIfError("Failed to set metadata."); + } + + /// + /// Updates the shuffle mode. + /// + /// A value indicating whether the shuffle mode is enabled. + /// + /// The server is not running .\n + /// -or-\n + /// An internal error occurs. + /// + public static void SetShuffleModeEnabled(bool enabled) + { + Native.UpdateShuffleMode(Handle, enabled ? MediaControllerShuffleMode.On : MediaControllerShuffleMode.Off). + ThrowIfError("Failed to set shuffle mode."); + } + + /// + /// Updates the repeat mode. + /// + /// A value indicating the repeat mode. + /// + /// The server is not running .\n + /// -or-\n + /// An internal error occurs. + /// + /// is invalid. + public static void SetRepeatMode(MediaControlRepeatMode mode) + { + ValidationUtil.ValidateEnum(typeof(MediaControlRepeatMode), mode, nameof(mode)); + + Native.UpdateRepeatMode(Handle, mode.ToNative()).ThrowIfError("Failed to set repeat mode."); + } + + /// + /// Occurs when a client sends playback command. + /// + public static event EventHandler PlaybackCommandReceived; + + private static Native.PlaybackStateCommandReceivedCallback _playbackCommandCallback; + + private static void RegisterPlaybackCommandReceivedEvent() + { + _playbackCommandCallback = (clientName, playbackCode, _) => + { + PlaybackCommandReceived?.Invoke(null, new PlaybackCommandReceivedEventArgs(clientName, playbackCode.ToCommand())); + }; + Native.SetPlaybackStateCmdRecvCb(Handle, _playbackCommandCallback). + ThrowIfError("Failed to init PlaybackStateCommandReceived event."); ; + } + } +} \ No newline at end of file diff --git a/src/Tizen.Multimedia.Remoting/MediaController/MediaControlServerStartedEventArgs.cs b/src/Tizen.Multimedia.Remoting/MediaController/MediaControlServerStartedEventArgs.cs new file mode 100644 index 0000000..5749d51 --- /dev/null +++ b/src/Tizen.Multimedia.Remoting/MediaController/MediaControlServerStartedEventArgs.cs @@ -0,0 +1,47 @@ +/* + * 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; + +namespace Tizen.Multimedia.Remoting +{ + /// + /// Provides data for the event. + /// + public class MediaControlServerStartedEventArgs : EventArgs + { + /// + /// Initializes a new instance of the class. + /// + /// A of the server. + /// is null. + public MediaControlServerStartedEventArgs(MediaController mediaController) + { + if (mediaController == null) + { + throw new ArgumentNullException(nameof(mediaController)); + } + + Controller = mediaController; + } + + /// + /// Gets the controller of the server added. + /// + /// A . + public MediaController Controller { get; } + } +} \ No newline at end of file diff --git a/src/Tizen.Multimedia.Remoting/MediaController/MediaControlServerStoppedEventArgs.cs b/src/Tizen.Multimedia.Remoting/MediaController/MediaControlServerStoppedEventArgs.cs new file mode 100644 index 0000000..bb0636d --- /dev/null +++ b/src/Tizen.Multimedia.Remoting/MediaController/MediaControlServerStoppedEventArgs.cs @@ -0,0 +1,47 @@ +/* + * 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; + +namespace Tizen.Multimedia.Remoting +{ + /// + /// Provides data for the event. + /// + public class MediaControlServerStoppedEventArgs : EventArgs + { + /// + /// Initializes a new instance of the class. + /// + /// The application id of the server stopped. + /// is null. + public MediaControlServerStoppedEventArgs(string serverAppId) + { + if (serverAppId == null) + { + throw new ArgumentNullException(nameof(serverAppId)); + } + + ServerAppId = serverAppId; + } + + /// + /// Gets the application id of the server. + /// + /// A string represents the application id. + public string ServerAppId { get; } + } +} \ No newline at end of file diff --git a/src/Tizen.Multimedia.Remoting/MediaController/MediaController.cs b/src/Tizen.Multimedia.Remoting/MediaController/MediaController.cs new file mode 100644 index 0000000..fd35a57 --- /dev/null +++ b/src/Tizen.Multimedia.Remoting/MediaController/MediaController.cs @@ -0,0 +1,332 @@ +/* + * 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.Diagnostics; +using Native = Interop.MediaControllerClient; + +namespace Tizen.Multimedia.Remoting +{ + /// + /// Provides a means to to send commands to and handle events from media control server. + /// + public class MediaController + { + internal MediaController(MediaControllerManager manager, string serverAppId) + { + Debug.Assert(manager != null); + Debug.Assert(serverAppId != null); + + Manager = manager; + ServerAppId = serverAppId; + } + + private MediaControllerManager Manager { get; } + + /// + /// Gets the application id of the server. + /// + /// The server application id. + public string ServerAppId { get; } + + /// + /// Gets a value indicating whether the sever has been stopped. + /// + /// true if the server has been stopped; otherwise, false. + public bool IsStopped + { + get; + private set; + } + + private void ThrowIfStopped() + { + if (IsStopped) + { + throw new InvalidOperationException("The server has already been stopped."); + } + } + + /// + /// Occurs when the server is stopped. + /// + public event EventHandler ServerStopped; + + internal void RaiseStoppedEvent() + { + IsStopped = true; + ServerStopped?.Invoke(this, EventArgs.Empty); + } + + /// + /// Occurs when the playback state is updated. + /// + public event EventHandler PlaybackStateUpdated; + + private PlaybackStateUpdatedEventArgs CreatePlaybackUpdatedEventArgs(IntPtr playbackHandle) + { + try + { + Native.GetPlaybackState(playbackHandle, out var playbackCode).ThrowIfError("Failed to get state."); + + Native.GetPlaybackPosition(playbackHandle, out var position).ThrowIfError("Failed to get position."); + + return new PlaybackStateUpdatedEventArgs(playbackCode.ToState(), (long)position); + } + catch (Exception e) + { + Log.Error(GetType().FullName, e.ToString()); + } + return null; + } + + internal void RaisePlaybackUpdatedEvent(IntPtr playbackHandle) + { + var eventHandler = PlaybackStateUpdated; + + if (eventHandler == null) + { + return; + } + + var args = CreatePlaybackUpdatedEventArgs(playbackHandle); + + if (args != null) + { + eventHandler.Invoke(this, args); + } + } + + /// + /// Occurs when the metadata is updated. + /// + public event EventHandler MetadataUpdated; + + private MetadataUpdatedEventArgs CreateMetadataUpdatedEventArgs(IntPtr metadataHandle) + { + try + { + return new MetadataUpdatedEventArgs(new MediaControlMetadata(metadataHandle)); + } + catch (Exception e) + { + Log.Error(GetType().FullName, e.ToString()); + } + return null; + } + + internal void RaiseMetadataUpdatedEvent(IntPtr metadataHandle) + { + var eventHandler = MetadataUpdated; + + if (eventHandler == null) + { + return; + } + + var args = CreateMetadataUpdatedEventArgs(metadataHandle); + + if (args != null) + { + eventHandler.Invoke(this, args); + } + } + + /// + /// Occurs when the shuffle mode is updated. + /// + public event EventHandler ShuffleModeUpdated; + + internal void RaiseShuffleModeUpdatedEvent(MediaControllerShuffleMode mode) + { + ShuffleModeUpdated?.Invoke(this, new ShuffleModeUpdatedEventArgs(mode == MediaControllerShuffleMode.On)); + } + + /// + /// Occurs when the repeat mode is updated. + /// + public event EventHandler RepeatModeUpdated; + + internal void RaiseRepeatModeUpdatedEvent(MediaControlRepeatMode mode) + { + RepeatModeUpdated?.Invoke(this, new RepeatModeUpdatedEventArgs(mode)); + } + + /// + /// Returns the playback state set by the server. + /// + /// The playback state. + /// + /// The server has already been stopped. + /// -or-\n + /// An internal error occurs. + /// + /// The has already been disposed of. + /// + public MediaControlPlaybackState GetPlaybackState() + { + ThrowIfStopped(); + + IntPtr playbackHandle = IntPtr.Zero; + + try + { + Native.GetServerPlayback(Manager.Handle, ServerAppId, out playbackHandle).ThrowIfError("Failed to get playback."); + + Native.GetPlaybackState(playbackHandle, out var playbackCode).ThrowIfError("Failed to get state."); + + return playbackCode.ToState(); + } + finally + { + if (playbackHandle != IntPtr.Zero) + { + Native.DestroyPlayback(playbackHandle); + } + } + } + + /// + /// Returns the playback position set by the server. + /// + /// The playback position in milliseconds. + /// + /// The server has already been stopped. + /// -or-\n + /// An internal error occurs. + /// + /// The has already been disposed of. + /// + public long GetPlaybackPosition() + { + ThrowIfStopped(); + + IntPtr playbackHandle = IntPtr.Zero; + + try + { + Native.GetServerPlayback(Manager.Handle, ServerAppId, out playbackHandle).ThrowIfError("Failed to get playback."); + + Native.GetPlaybackPosition(playbackHandle, out var position).ThrowIfError("Failed to get position."); + + return (long)position; + } + finally + { + if (playbackHandle != IntPtr.Zero) + { + Native.DestroyPlayback(playbackHandle); + } + } + } + + /// + /// Returns the metadata set by the server. + /// + /// The metadata. + /// + /// The server has already been stopped. + /// -or-\n + /// An internal error occurs. + /// + /// The has already been disposed of. + /// + public MediaControlMetadata GetMetadata() + { + ThrowIfStopped(); + + IntPtr metadataHandle = IntPtr.Zero; + + try + { + Native.GetServerMetadata(Manager.Handle, ServerAppId, out metadataHandle). + ThrowIfError("Failed to get metadata."); + + return new MediaControlMetadata(metadataHandle); + } + finally + { + if (metadataHandle != IntPtr.Zero) + { + Native.DestroyMetadata(metadataHandle); + } + } + } + + /// + /// Returns whether the shuffle mode is enabled. + /// + /// A value indicating whether the shuffle mode is enabled. + /// + /// The server has already been stopped. + /// -or-\n + /// An internal error occurs. + /// + /// The has already been disposed of. + /// + public bool IsShuffleModeEnabled() + { + ThrowIfStopped(); + + Native.GetServerShuffleMode(Manager.Handle, ServerAppId, out var shuffleMode). + ThrowIfError("Failed to get shuffle mode state."); + + return shuffleMode == MediaControllerShuffleMode.On; + } + + /// + /// Returns the repeat mode. + /// + /// A set by the server. + /// + /// The server has already been stopped. + /// -or-\n + /// An internal error occurs. + /// + /// The has already been disposed of. + /// + public MediaControlRepeatMode GetRepeatMode() + { + ThrowIfStopped(); + + Native.GetServerRepeatMode(Manager.Handle, ServerAppId, out var repeatMode). + ThrowIfError("Failed to get repeat mode state."); + + return repeatMode.ToPublic(); + } + + /// + /// Sends playback command to the server. + /// A playback command. + /// + /// The server has already been stopped. + /// -or-\n + /// An internal error occurs. + /// + /// is not valid. + /// The has already been disposed of. + /// + public void SendPlaybackCommand(MediaControlPlaybackCommand command) + { + ThrowIfStopped(); + + ValidationUtil.ValidateEnum(typeof(MediaControlPlaybackCommand), command, nameof(command)); + + Native.SendPlaybackStateCommand(Manager.Handle, ServerAppId, command.ToCode()). + ThrowIfError("Failed to send command."); + } + } +} \ No newline at end of file diff --git a/src/Tizen.Multimedia.Remoting/MediaController/MediaControllerClient.cs b/src/Tizen.Multimedia.Remoting/MediaController/MediaControllerClient.cs deleted file mode 100755 index 529719a..0000000 --- a/src/Tizen.Multimedia.Remoting/MediaController/MediaControllerClient.cs +++ /dev/null @@ -1,595 +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. -*/ - -using System; -using System.Collections.Generic; -using System.Runtime.InteropServices; -using System.Threading.Tasks; -using Tizen.Applications; -using Native = Interop.MediaControllerClient; - -namespace Tizen.Multimedia.MediaController -{ - - /// - /// The MediaControllerClient class provides APIs required for media-controller-client. - /// - /// - /// http://tizen.org/privilege/mediacontroller.client - /// - /// - /// The MediaControllerClient APIs provides functions to get media information from server. - /// - public class MediaControllerClient : IDisposable - { - internal IntPtr _handle = IntPtr.Zero; - - private bool _disposed = false; - private EventHandler _serverUpdated; - private Native.ServerUpdatedCallback _serverUpdatedCallback; - private EventHandler _playbackUpdated; - private Native.PlaybackUpdatedCallback _playbackUpdatedCallback; - private EventHandler _metadataUpdated; - private Native.MetadataUpdatedCallback _metadataUpdatedCallback; - private EventHandler _shufflemodeUpdated; - private Native.ShuffleModeUpdatedCallback _shufflemodeUpdatedCallback; - private EventHandler _repeatmodeUpdated; - private Native.RepeatModeUpdatedCallback _repeatmodeUpdatedCallback; - private EventHandler _customcommandReply; - private Native.CommandReplyRecievedCallback _customcommandReplyCallback; - - private bool IsValidHandle - { - get { return (_handle != IntPtr.Zero); } - } - - private IntPtr SafeHandle - { - get - { - if (!IsValidHandle) - { - throw new ObjectDisposedException(nameof(MediaControllerClient), "Fail to operate MediaControllerClient"); - } - - return _handle; - } - } - - /// - /// The constructor of MediaControllerClient class. - /// - /// 3 - /// Thrown when the operation is invalid for the current state - /// Thrown when the access is denied for media controller client - public MediaControllerClient() - { - MediaControllerValidator.ThrowIfError( - Native.Create(out _handle), "Create client failed"); - } - - ~MediaControllerClient() - { - Dispose(false); - } - - public void Dispose() - { - Dispose(true); - GC.SuppressFinalize(this); - } - - protected virtual void Dispose(bool disposing) - { - if (!_disposed) - { - if (disposing) - { - // To be used if there are any other disposable objects - } - - if (IsValidHandle) - { - Native.Destroy(_handle); - _handle = IntPtr.Zero; - } - - _disposed = true; - } - } - - /// - /// ServerUpdated event is raised when server is changed - /// - /// 3 - public event EventHandler ServerUpdated - { - add - { - if (_serverUpdated == null) - { - RegisterServerUpdatedEvent(); - } - - _serverUpdated += value; - - } - - remove - { - _serverUpdated -= value; - if (_serverUpdated == null) - { - UnregisterServerUpdatedEvent(); - } - } - } - - /// - /// PlaybackUpdated event is raised when playback is changed - /// - /// 3 - public event EventHandler PlaybackUpdated - { - add - { - if (_playbackUpdated == null) - { - RegisterPlaybackUpdatedEvent(); - } - - _playbackUpdated += value; - - } - - remove - { - _playbackUpdated -= value; - if (_playbackUpdated == null) - { - UnregisterPlaybackUpdatedEvent(); - } - } - } - - /// - /// MetadataUpdated event is raised when metadata is changed - /// - /// 3 - public event EventHandler MetadataUpdated - { - add - { - if (_metadataUpdated == null) - { - RegisterMetadataUpdatedEvent(); - } - - _metadataUpdated += value; - - } - - remove - { - _metadataUpdated -= value; - if (_metadataUpdated == null) - { - UnregisterMetadataUpdatedEvent(); - } - } - } - - /// - /// ShuffleModeUpdated event is raised when shuffle mode is changed - /// - /// 3 - public event EventHandler ShuffleModeUpdated - { - add - { - if (_shufflemodeUpdated == null) - { - RegisterShuffleModeUpdatedEvent(); - } - - _shufflemodeUpdated += value; - - } - - remove - { - _shufflemodeUpdated -= value; - if (_shufflemodeUpdated == null) - { - UnregisterShuffleModeUpdatedEvent(); - } - } - } - - /// - /// RepeatModeUpdated event is raised when server is changed - /// - /// 3 - public event EventHandler RepeatModeUpdated - { - add - { - if (_repeatmodeUpdated == null) - { - RegisterRepeatModeUpdatedEvent(); - } - - _repeatmodeUpdated += value; - } - - remove - { - _repeatmodeUpdated -= value; - if (_repeatmodeUpdated == null) - { - UnregisterRepeatModeUpdatedEvent(); - } - } - } - - /// - /// CommandReply event is raised when reply for command is recieved - /// - /// 3 - public event EventHandler CustomCommandReply - { - add - { - if (_customcommandReply == null) - { - _customcommandReplyCallback = (IntPtr serverName, int result, IntPtr bundle, IntPtr userData) => - { - SafeBundleHandle safeBundleHandle = new SafeBundleHandle(bundle, true); - Bundle bundleData = new Bundle(safeBundleHandle); - CustomCommandReplyEventArgs eventArgs = new CustomCommandReplyEventArgs(Marshal.PtrToStringAnsi(serverName), result, bundleData); - _customcommandReply?.Invoke(this, eventArgs); - }; - } - - _customcommandReply += value; - - } - - remove - { - _customcommandReply -= value; - if (_customcommandReply == null) - { - _customcommandReplyCallback = null; - } - } - } - - /// - /// gets latest server information - /// 3 - /// The name and state of the latest media controller server application: ServerInformation object - /// Thrown when the operation is invalid for the current state - public ServerInformation GetLatestServer() - { - IntPtr name = IntPtr.Zero; - MediaControllerServerState state = MediaControllerServerState.None; - - try - { - MediaControllerValidator.ThrowIfError( - Native.GetLatestServer(SafeHandle, out name, out state), "Get Latest server failed"); - return new ServerInformation(Marshal.PtrToStringAnsi(name), (MediaControllerServerState)state); - } - finally - { - LibcSupport.Free(name); - } - } - - /// - /// gets playback information for specific server - /// 3 - /// Server Name - /// The playback state and playback position of the specific media controller server application:MediaControllerPlayback object - /// Thrown when an invalid argument is used - /// Thrown when the operation is invalid for the current state - public MediaControllerPlayback GetPlayback(string serverName) - { - IntPtr playbackHandle = IntPtr.Zero; - MediaControllerPlayback playback = null; - - try - { - MediaControllerValidator.ThrowIfError( - Native.GetServerPlayback(SafeHandle, serverName, out playbackHandle), "Get Playback handle failed"); - playback = new MediaControllerPlayback(playbackHandle); - } - finally - { - if (playbackHandle != IntPtr.Zero) - { - MediaControllerValidator.ThrowIfError( - Native.DestroyPlayback(playbackHandle), "Destroy playback failed"); - } - } - - return playback; - } - - /// - /// gets metadata information for specific server - /// 3 - /// Server Name - /// The metadata information of the specific media controller server application:MediaControllerMetadata object - /// Thrown when an invalid argument is used - /// Thrown when the operation is invalid for the current state - public MediaControllerMetadata GetMetadata(string serverName) - { - IntPtr metadataHandle = IntPtr.Zero; - MediaControllerMetadata metadata = null; - - try - { - MediaControllerValidator.ThrowIfError( - Native.GetServerMetadata(SafeHandle, serverName, out metadataHandle), "Get Metadata handle failed"); - metadata = new MediaControllerMetadata(metadataHandle); - } - finally - { - if (metadataHandle != IntPtr.Zero) - { - MediaControllerValidator.ThrowIfError( - Native.DestroyMetadata(metadataHandle), "Destroy metadata failed"); - } - } - - return metadata; - } - - /// - /// gets shuffle mode for specific server - /// 3 - /// Server Name - /// The shuffle mode of the specific media controller server application:MediaControllerShuffleMode enum - /// Thrown when an invalid argument is used - /// Thrown when the operation is invalid for the current state - public MediaControllerShuffleMode GetShuffleMode(string serverName) - { - MediaControllerShuffleMode shuffleMode = MediaControllerShuffleMode.Off; - - MediaControllerValidator.ThrowIfError( - Native.GetServerShuffleMode(SafeHandle, serverName, out shuffleMode), "Get ShuffleMode failed"); - - return shuffleMode; - } - - /// - /// gets repeat mode for specific server \ - /// 3 - /// Server Name - /// The repeat mode of the specific media controller server application:MediaControllerRepeatMode enum - /// Thrown when an invalid argument is used - /// Thrown when the operation is invalid for the current state - public MediaControllerRepeatMode GetRepeatMode(string serverName) - { - MediaControllerRepeatMode repeatMode = MediaControllerRepeatMode.Off; - - MediaControllerValidator.ThrowIfError( - Native.GetServerRepeatMode(SafeHandle, serverName, out repeatMode), "Get RepeatMode failed"); - - return repeatMode; - } - - /// - /// Send command of playback state to server application - /// Server Name - /// Playback State - /// Thrown when an invalid argument is used - /// Thrown when the operation is invalid for the current state - public void SendPlaybackStateCommand(string serverName, MediaControllerPlaybackState state) - { - MediaControllerValidator.ThrowIfError( - Native.SendPlaybackStateCommand(SafeHandle, serverName, state), "Send playback state command failed"); - } - - /// - /// Send customized command to server application - /// 3 - /// Server Name - /// Command - /// Bundle data - /// Thrown when an invalid argument is used - /// Thrown when the operation is invalid for the current state - public void SendCustomCommand(string serverName, string command, Bundle bundle) - { - MediaControllerValidator.ThrowIfError( - Native.SendCustomCommand(SafeHandle, serverName, command, bundle.SafeBundleHandle, _customcommandReplyCallback, IntPtr.Zero), - "Send custom command failed"); - } - - /// - /// Subscribe subscription type from specific server application - /// 3 - /// Subscription Type - /// Server Name - /// Thrown when an invalid argument is used - public void Subscribe(MediaControllerSubscriptionType type, string serverName) - { - MediaControllerValidator.ThrowIfError( - Native.Subscribe(SafeHandle, type, serverName), "Subscribe failed"); - } - - /// - /// Subscribe subscription type from specific server application - /// 3 - /// Subscription Type - /// Server Name - /// Thrown when an invalid argument is used - public void Unsubscribe(MediaControllerSubscriptionType type, string serverName) - { - MediaControllerValidator.ThrowIfError( - Native.Unsubscribe(SafeHandle, type, serverName), "Unsubscribe failed"); - } - - /// - /// gets activated server list - /// 3 - /// The list of activated media controller server applications: IEnumerable of string - public Task> GetActivatedServerList() - { - var task = new TaskCompletionSource>(); - - List collectionList = ForEachActivatedServer(SafeHandle); - task.TrySetResult((IEnumerable)collectionList); - - return task.Task; - } - - /// - /// gets subscribed server list - /// 3 - /// Subscription Type - /// The list of subscribed media controller server applications: IEnumerable of string - /// Thrown when an invalid argument is used - /// Thrown when the operation is invalid for the current state - public Task> GetSubscribedServerList(MediaControllerSubscriptionType subscriptionType) - { - var task = new TaskCompletionSource>(); - - List collectionList = ForEachSubscribedServer(SafeHandle, subscriptionType); - task.TrySetResult((IEnumerable)collectionList); - - return task.Task; - } - - private void RegisterServerUpdatedEvent() - { - _serverUpdatedCallback = (IntPtr serverName, MediaControllerServerState serverState, IntPtr userData) => - { - ServerUpdatedEventArgs eventArgs = new ServerUpdatedEventArgs(Marshal.PtrToStringAnsi(serverName), serverState); - _serverUpdated?.Invoke(this, eventArgs); - }; - Native.SetServerUpdatedCb(SafeHandle, _serverUpdatedCallback, IntPtr.Zero); - } - - private void UnregisterServerUpdatedEvent() - { - Native.UnsetServerUpdatedCb(SafeHandle); - } - - private void RegisterPlaybackUpdatedEvent() - { - _playbackUpdatedCallback = (IntPtr serverName, IntPtr playback, IntPtr userData) => - { - PlaybackUpdatedEventArgs eventArgs = new PlaybackUpdatedEventArgs(Marshal.PtrToStringAnsi(serverName), playback); - _playbackUpdated?.Invoke(this, eventArgs); - }; - Native.SetPlaybackUpdatedCb(SafeHandle, _playbackUpdatedCallback, IntPtr.Zero); - } - - private void UnregisterPlaybackUpdatedEvent() - { - Native.UnsetPlaybackUpdatedCb(SafeHandle); - } - - private void RegisterMetadataUpdatedEvent() - { - _metadataUpdatedCallback = (IntPtr serverName, IntPtr metadata, IntPtr userData) => - { - MetadataUpdatedEventArgs eventArgs = new MetadataUpdatedEventArgs(Marshal.PtrToStringAnsi(serverName), metadata); - _metadataUpdated?.Invoke(this, eventArgs); - }; - Native.SetMetadataUpdatedCb(SafeHandle, _metadataUpdatedCallback, IntPtr.Zero); - } - - private void UnregisterMetadataUpdatedEvent() - { - Native.UnsetMetadataUpdatedCb(SafeHandle); - } - - private void RegisterShuffleModeUpdatedEvent() - { - _shufflemodeUpdatedCallback = (IntPtr serverName, MediaControllerShuffleMode shuffleMode, IntPtr userData) => - { - ShuffleModeUpdatedEventArgs eventArgs = new ShuffleModeUpdatedEventArgs(Marshal.PtrToStringAnsi(serverName), shuffleMode); - _shufflemodeUpdated?.Invoke(this, eventArgs); - }; - - MediaControllerValidator.ThrowIfError( - Native.SetShuffleModeUpdatedCb(SafeHandle, _shufflemodeUpdatedCallback, IntPtr.Zero), - "Set ShuffleModeUpdated callback failed"); - } - - private void UnregisterShuffleModeUpdatedEvent() - { - Native.UnsetShuffleModeUpdatedCb(SafeHandle); - } - - private void RegisterRepeatModeUpdatedEvent() - { - _repeatmodeUpdatedCallback = (IntPtr serverName, MediaControllerRepeatMode repeatMode, IntPtr userData) => - { - RepeatModeUpdatedEventArgs eventArgs = new RepeatModeUpdatedEventArgs(Marshal.PtrToStringAnsi(serverName), repeatMode); - _repeatmodeUpdated?.Invoke(this, eventArgs); - }; - - MediaControllerValidator.ThrowIfError( - Native.SetRepeatModeUpdatedCb(SafeHandle, _repeatmodeUpdatedCallback, IntPtr.Zero), - "Set RepeatModeUpdated callback failed"); - } - - private void UnregisterRepeatModeUpdatedEvent() - { - Native.UnsetRepeatModeUpdatedCb(SafeHandle); - } - - private static List ForEachSubscribedServer(IntPtr handle, MediaControllerSubscriptionType subscriptionType) - { - List subscribedServerCollections = new List(); - - Native.SubscribedServerCallback serverCallback = (IntPtr serverName, IntPtr userData) => - { - subscribedServerCollections.Add(Marshal.PtrToStringAnsi(serverName)); - return true; - }; - - MediaControllerValidator.ThrowIfError( - Native.ForeachSubscribedServer(handle, subscriptionType, serverCallback, IntPtr.Zero), - "Foreach Subscribed server failed"); - - return subscribedServerCollections; - } - - private static List ForEachActivatedServer(IntPtr handle) - { - List activatedServerCollections = new List(); - - Native.ActivatedServerCallback serverCallback = (IntPtr serverName, IntPtr userData) => - { - activatedServerCollections.Add(Marshal.PtrToStringAnsi(serverName)); - return true; - }; - - MediaControllerValidator.ThrowIfError( - Native.ForeachActivatedServer(handle, serverCallback, IntPtr.Zero), - "Foreach Activated server failed"); - - return activatedServerCollections; - } - } -} - diff --git a/src/Tizen.Multimedia.Remoting/MediaController/MediaControllerEnums.cs b/src/Tizen.Multimedia.Remoting/MediaController/MediaControllerEnums.cs deleted file mode 100755 index dc12318..0000000 --- a/src/Tizen.Multimedia.Remoting/MediaController/MediaControllerEnums.cs +++ /dev/null @@ -1,236 +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.MediaController -{ - /// - /// Specifies states that a can have. - /// - public enum MediaControllerServerState - { - /// - /// Server state is unknown - /// - /// 3 - None, - - /// - /// Server is activated - /// - /// 3 - Activated, - - /// - /// Server is deactivated - /// - /// 3 - Deactivated, - } - - /// - /// Enumeration for playback state - /// - public enum MediaControllerPlaybackState - { - /// - /// Playback state is unknown - /// - /// 3 - None, - - /// - /// Playback is playing - /// - /// 3 - Play, - - /// - /// Playback is paused - /// - /// 3 - Pause, - - /// - /// Playback is next - /// - /// 3 - Next, - - /// - /// Playback is prev - /// - /// 3 - Prev, - - /// - /// Playback is fastforward - /// - /// 3 - FastForward, - - /// - /// Playback is rewind - /// - /// 3 - Rewind, - } - - /// - /// Enumeration for shuffle mode - /// - public enum MediaControllerShuffleMode - { - /// - /// Shuffle mode is On - /// - /// 3 - On, - - /// - /// Shuffle mode is Off - /// - /// 3 - Off, - } - - /// - /// Enumeration for repeat mode - /// - public enum MediaControllerRepeatMode - { - /// - /// Repeat mode is On - /// - /// 3 - On, - - /// - /// Repeat mode is Off - /// - /// 3 - Off, - } - - /// - /// Enumeration for repeat mode - /// - public enum MediaControllerSubscriptionType - { - /// - /// The type of subscription is the state of server - /// - /// 3 - ServerState, - - /// - /// The type of subscription is the playback - /// - /// 3 - Playback, - - /// - /// The type of subscription is the metadata - /// - /// 3 - Metadata, - - /// - /// The type of subscription is the shuffle mode - /// - /// 3 - ShuffleMode, - - /// - /// The type of subscription is the repeat mode - /// - /// 3 - RepeatMode, - } - - /// - /// Enumeration for metadata attributes - /// - internal enum MediaControllerAttributes - { - /// - /// Attribute is title - /// - /// 3 - Title, - - /// - /// Attribute is artist - /// - /// 3 - Artist, - - /// - /// Attribute is album - /// - /// 3 - Album, - - /// - /// Attribute is author - /// - /// 3 - Author, - - /// - /// Attribute is genre - /// - /// 3 - Genre, - - /// - /// Attribute is duration - /// - /// 3 - Duration, - - /// - /// Attribute is date - /// - /// 3 - Date, - - /// - /// Attribute is copyright - /// - /// 3 - Copyright, - - /// - /// Attribute is description - /// - /// 3 - Description, - - /// - /// Attribute is track number - /// - /// 3 - TrackNumber, - - /// - /// Attribute is picture - /// - /// 3 - Picture, - } -} - diff --git a/src/Tizen.Multimedia.Remoting/MediaController/MediaControllerError.cs b/src/Tizen.Multimedia.Remoting/MediaController/MediaControllerError.cs index 680bedd..7a492a8 100644 --- a/src/Tizen.Multimedia.Remoting/MediaController/MediaControllerError.cs +++ b/src/Tizen.Multimedia.Remoting/MediaController/MediaControllerError.cs @@ -1,24 +1,24 @@ /* -* 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. -*/ + * 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.IO; using Tizen.Internals.Errors; -namespace Tizen.Multimedia.MediaController +namespace Tizen.Multimedia.Remoting { internal enum MediaControllerError { @@ -28,12 +28,17 @@ namespace Tizen.Multimedia.MediaController InvalidOperation = ErrorCode.InvalidOperation, NoSpaceOnDevice = ErrorCode.FileNoSpaceOnDevice, PermissionDenied = ErrorCode.PermissionDenied, - }; + } - internal static class MediaControllerValidator + internal static class MediaControllerErrorExtensions { - internal static void ThrowIfError(MediaControllerError error, string errorMessage) + internal static void ThrowIfError(this MediaControllerError error, string errorMessage) { + if (error == MediaControllerError.None) + { + return; + } + switch (error) { case MediaControllerError.InvalidParameter: @@ -46,12 +51,13 @@ namespace Tizen.Multimedia.MediaController throw new InvalidOperationException(errorMessage); case MediaControllerError.NoSpaceOnDevice: - throw new IOException(errorMessage); + throw new IOException($"Not enough storage : {errorMessage}"); case MediaControllerError.PermissionDenied: throw new UnauthorizedAccessException(errorMessage); } + + throw new InvalidOperationException($"Unknown error({error}) : {errorMessage}"); } } -} - +} \ No newline at end of file diff --git a/src/Tizen.Multimedia.Remoting/MediaController/MediaControllerLog.cs b/src/Tizen.Multimedia.Remoting/MediaController/MediaControllerLog.cs deleted file mode 100644 index 44eac12..0000000 --- a/src/Tizen.Multimedia.Remoting/MediaController/MediaControllerLog.cs +++ /dev/null @@ -1,25 +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. -*/ - -using System; - -namespace Tizen.Multimedia.MediaController -{ - static internal class MediaControllerLog - { - internal const string LogTag = "Tizen.Multimedia.MediaController"; - } -} \ 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 new file mode 100644 index 0000000..4cdd504 --- /dev/null +++ b/src/Tizen.Multimedia.Remoting/MediaController/MediaControllerManager.Events.cs @@ -0,0 +1,120 @@ +/* + * 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 Native = Interop.MediaControllerClient; + +namespace Tizen.Multimedia.Remoting +{ + public partial class MediaControllerManager + { + private Native.ServerUpdatedCallback _serverUpdatedCallback; + private Native.PlaybackUpdatedCallback _playbackUpdatedCallback; + private Native.MetadataUpdatedCallback _metadataUpdatedCallback; + private Native.ShuffleModeUpdatedCallback _shufflemodeUpdatedCallback; + private Native.RepeatModeUpdatedCallback _repeatmodeUpdatedCallback; + + /// + /// Occurs when a server is started. + /// + public event EventHandler ServerStarted; + + /// + /// Occurs when a server is stopped. + /// + public event EventHandler ServerStopped; + + private void InitializeEvents() + { + RegisterPlaybackUpdatedEvent(); + RegisterServerUpdatedEvent(); + RegisterMetadataUpdatedEvent(); + RegisterShuffleModeUpdatedEvent(); + RegisterRepeatModeUpdatedEvent(); + } + + private void RaiseServerChangedEvent(MediaControllerServerState state, MediaController controller) + { + if (controller == null) + { + return; + } + + if (state == MediaControllerServerState.Activated) + { + ServerStarted?.Invoke(this, new MediaControlServerStartedEventArgs(controller)); + } + else + { + controller.RaiseStoppedEvent(); + ServerStopped?.Invoke(this, new MediaControlServerStoppedEventArgs(controller.ServerAppId)); + } + } + + private void RegisterServerUpdatedEvent() + { + _serverUpdatedCallback = (serverName, state, _) => + { + RaiseServerChangedEvent(state, HandleServerUpdated(serverName, state)); + }; + + Native.SetServerUpdatedCb(Handle, _serverUpdatedCallback).ThrowIfError("Failed to init server changed event."); + } + + private void RegisterPlaybackUpdatedEvent() + { + _playbackUpdatedCallback = (serverName, playback, _) => + { + GetController(serverName)?.RaisePlaybackUpdatedEvent(playback); + }; + + Native.SetPlaybackUpdatedCb(Handle, _playbackUpdatedCallback).ThrowIfError("Failed to init PlaybackUpdated event."); + } + + + private void RegisterMetadataUpdatedEvent() + { + _metadataUpdatedCallback = (serverName, metadata, _) => + { + GetController(serverName)?.RaiseMetadataUpdatedEvent(metadata); + }; + + Native.SetMetadataUpdatedCb(Handle, _metadataUpdatedCallback).ThrowIfError("Failed to init MetadataUpdated event."); + } + + private void RegisterShuffleModeUpdatedEvent() + { + _shufflemodeUpdatedCallback = (serverName, shuffleMode, _) => + { + GetController(serverName)?.RaiseShuffleModeUpdatedEvent(shuffleMode); + }; + + Native.SetShuffleModeUpdatedCb(Handle, _shufflemodeUpdatedCallback). + ThrowIfError("Failed to init ShuffleModeUpdated event."); + } + + private void RegisterRepeatModeUpdatedEvent() + { + _repeatmodeUpdatedCallback = (serverName, repeatMode, _) => + { + GetController(serverName)?.RaiseRepeatModeUpdatedEvent(repeatMode.ToPublic()); + }; + + Native.SetRepeatModeUpdatedCb(Handle, _repeatmodeUpdatedCallback). + ThrowIfError("Failed to init RepeatModeUpdated event."); + } + } +} \ No newline at end of file diff --git a/src/Tizen.Multimedia.Remoting/MediaController/MediaControllerManager.cs b/src/Tizen.Multimedia.Remoting/MediaController/MediaControllerManager.cs new file mode 100644 index 0000000..a8f6c5a --- /dev/null +++ b/src/Tizen.Multimedia.Remoting/MediaController/MediaControllerManager.cs @@ -0,0 +1,204 @@ +/* + * 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 System.Linq; +using System.Threading; +using Native = Interop.MediaControllerClient; +using NativeHandle = Interop.MediaControllerClientHandle; + +namespace Tizen.Multimedia.Remoting +{ + /// + /// Provides a means to retrieve active controllers and observe controllers added and removed. + /// + public partial class MediaControllerManager : IDisposable + { + private NativeHandle _handle; + + private Dictionary _activated = new Dictionary(); + + private ReaderWriterLockSlim _lock = new ReaderWriterLockSlim(); + + internal NativeHandle Handle + { + get + { + if (_disposed) + { + throw new ObjectDisposedException(nameof(MediaControllerManager)); + } + + return _handle; + } + } + + /// + /// Initializes a new instance of the class. + /// + /// http://tizen.org/privilege/mediacontroller.client + /// An internal error occurs. + /// Caller does not have required privilege. + public MediaControllerManager() + { + Native.Create(out _handle).ThrowIfError("Failed to create media controller client."); + + InitializeEvents(); + + LoadActivatedServers(); + } + + private bool _disposed; + + /// + /// Releases all resources used by the . + /// + public void Dispose() + { + Dispose(true); + } + + /// + /// Releases the unmanaged resources used by the . + /// + /// true to release both managed and unmanaged resources; false to release only unmanaged resources. + protected virtual void Dispose(bool disposing) + { + if (!_disposed) + { + if (disposing) + { + // To be used if there are any other disposable objects + } + _handle.Dispose(); + + _disposed = true; + } + } + + /// + /// Gets the active controllers. + /// + /// An array of . + public MediaController[] GetActiveControllers() + { + if (_disposed) + { + return new MediaController[0]; + } + + try + { + _lock.EnterReadLock(); + return _activated.Values.ToArray(); + } + finally + { + _lock.ExitReadLock(); + } + } + + #region Controllers-related operations + + #region Unlocking operations + + private MediaController HandleActivation(string serverName) + { + if (_activated.ContainsKey(serverName)) + { + return null; + } + + var controller = new MediaController(this, serverName); + _activated.Add(serverName, controller); + + return controller; + } + + private MediaController HandleDeactivation(string serverName) + { + if (_activated.TryGetValue(serverName, out var controller)) + { + _activated.Remove(serverName); + } + + return controller; + } + #endregion + + #region Locking operations + + private MediaController HandleServerUpdated(string serverName, MediaControllerServerState state) + { + try + { + _lock.EnterWriteLock(); + + if (state == MediaControllerServerState.Activated) + { + return HandleActivation(serverName); + } + + return HandleDeactivation(serverName); + } + finally + { + _lock.ExitWriteLock(); + } + } + + private MediaController GetController(string serverName) + { + try + { + _lock.EnterReadLock(); + + _activated.TryGetValue(serverName, out var value); + return value; + } + finally + { + _lock.ExitReadLock(); + } + } + + private void LoadActivatedServers() + { + try + { + _lock.EnterWriteLock(); + + Native.ActivatedServerCallback serverCallback = (serverName, _) => + { + _activated.Add(serverName, new MediaController(this, serverName)); + return true; + }; + + Native.ForeachActivatedServer(Handle, serverCallback, IntPtr.Zero). + ThrowIfError("Failed to get activated servers."); + } + finally + { + _lock.ExitWriteLock(); + } + } + + #endregion + + #endregion + } +} \ No newline at end of file diff --git a/src/Tizen.Multimedia.Remoting/MediaController/MediaControllerMetadata.cs b/src/Tizen.Multimedia.Remoting/MediaController/MediaControllerMetadata.cs deleted file mode 100755 index 1b0968b..0000000 --- a/src/Tizen.Multimedia.Remoting/MediaController/MediaControllerMetadata.cs +++ /dev/null @@ -1,123 +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. -*/ - -using System; -using Native = Interop.MediaControllerClient; - -namespace Tizen.Multimedia.MediaController -{ - /// - /// Metadata represents a metadata of media for server application to play - /// - public class MediaControllerMetadata - { - /// - /// The constructor of MediaControllerMetadata class. - /// - /// 3 - public MediaControllerMetadata() - { - // Do nothing - } - - internal MediaControllerMetadata(IntPtr handle) - { - if (handle == IntPtr.Zero) - { - throw new InvalidOperationException("MediaControllerMetadata is not valid."); - } - - Title = Native.GetMetadata(handle, MediaControllerAttributes.Title); - Artist = Native.GetMetadata(handle, MediaControllerAttributes.Artist); - Album = Native.GetMetadata(handle, MediaControllerAttributes.Album); - Author = Native.GetMetadata(handle, MediaControllerAttributes.Author); - Genre = Native.GetMetadata(handle, MediaControllerAttributes.Genre); - Duration = Native.GetMetadata(handle, MediaControllerAttributes.Duration); - Date = Native.GetMetadata(handle, MediaControllerAttributes.Date); - Copyright = Native.GetMetadata(handle, MediaControllerAttributes.Copyright); - Description = Native.GetMetadata(handle, MediaControllerAttributes.Description); - TrackNumber = Native.GetMetadata(handle, MediaControllerAttributes.TrackNumber); - Picture = Native.GetMetadata(handle, MediaControllerAttributes.Picture); - } - - /// - /// Set/Get the Title of media - /// - /// 3 - public string Title { get; set; } - - /// - /// Set/Get the Artist of media - /// - /// 3 - public string Artist { get; set; } - - /// - /// Set/Get the Album of media - /// - /// 3 - public string Album { get; set; } - - /// - /// Set/Get the Author of media - /// - /// 3 - public string Author { get; set; } - - /// - /// Set/Get the Genre of media - /// - /// 3 - public string Genre { get; set; } - - /// - /// Set/Get the Duration of media - /// - /// 3 - public string Duration { get; set; } - - /// - /// Set/Get the Date of media - /// - /// 3 - public string Date { get; set; } - - /// - /// Set/Get the Copyright of media - /// - /// 3 - public string Copyright { get; set; } - - /// - /// Set/Get the Description of media - /// - /// 3 - public string Description { get; set; } - - /// - /// Set/Get the Track Number of media - /// - /// 3 - public string TrackNumber { get; set; } - - /// - /// Set/Get the Picture of media - /// - /// 3 - public string Picture { get; set; } - } -} - diff --git a/src/Tizen.Multimedia.Remoting/MediaController/MediaControllerPlayback.cs b/src/Tizen.Multimedia.Remoting/MediaController/MediaControllerPlayback.cs deleted file mode 100755 index 52143e5..0000000 --- a/src/Tizen.Multimedia.Remoting/MediaController/MediaControllerPlayback.cs +++ /dev/null @@ -1,76 +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. -*/ - -using System; -using Native = Interop.MediaControllerClient; - -namespace Tizen.Multimedia.MediaController -{ - /// - /// Playback represents a playback state and playback position. - /// - public class MediaControllerPlayback - { - /// - /// The constructor of MediaControllerPlayback class. - /// - /// 3 - /// - /// The state of the playback which is playing in MediaConttoller server application - /// - /// - /// The position of the playback which is playing in MediaConttoller server application - /// - public MediaControllerPlayback(MediaControllerPlaybackState state, ulong position) - { - State = state; - Position = position; - } - - internal MediaControllerPlayback(IntPtr handle) - { - MediaControllerPlaybackState state = MediaControllerPlaybackState.None; - ulong position = 0L; - - if (handle == IntPtr.Zero) - { - throw new InvalidOperationException("MediaControllerPlayback is not valid."); - } - - MediaControllerValidator.ThrowIfError( - Native.GetPlaybackState(handle, out state), "Get Playback state failed"); - - MediaControllerValidator.ThrowIfError( - Native.GetPlaybackPosition(handle, out position), "Get Playback position failed"); - - State = state; - Position = position; - } - - /// - /// Set/Get the State of playback information - /// - /// 3 - public MediaControllerPlaybackState State { get; } - - /// - /// Set/Get the Position of playback information - /// - /// 3 - public ulong Position { get; } - } -} - diff --git a/src/Tizen.Multimedia.Remoting/MediaController/MediaControllerRepeatMode.cs b/src/Tizen.Multimedia.Remoting/MediaController/MediaControllerRepeatMode.cs new file mode 100644 index 0000000..5bcd5c8 --- /dev/null +++ b/src/Tizen.Multimedia.Remoting/MediaController/MediaControllerRepeatMode.cs @@ -0,0 +1,24 @@ +/* + * 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 +{ + public enum MediaControlRepeatMode + { + Off, + On, + } +} \ No newline at end of file diff --git a/src/Tizen.Multimedia.Remoting/MediaController/MediaControllerServer.cs b/src/Tizen.Multimedia.Remoting/MediaController/MediaControllerServer.cs deleted file mode 100755 index 9928e53..0000000 --- a/src/Tizen.Multimedia.Remoting/MediaController/MediaControllerServer.cs +++ /dev/null @@ -1,302 +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. -*/ - -using System; -using System.Runtime.InteropServices; -using Tizen.Applications; -using Native = Interop.MediaControllerServer; - -namespace Tizen.Multimedia.MediaController -{ - - /// - /// The MediaControllerServer class provides APIs required for media-controller-server. - /// - /// - /// http://tizen.org/privilege/mediacontroller.server - /// - /// - /// The MediaControllerServer APIs provides functions to update media information. - /// - public class MediaControllerServer : IDisposable - { - internal IntPtr _handle = IntPtr.Zero; - - private bool _disposed = false; - private EventHandler _playbackCommand; - private Native.PlaybackStateCommandRecievedCallback _playbackCommandCallback; - private EventHandler _customCommand; - private Native.CustomCommandRecievedCallback _customCommandCallback; - - private bool IsValidHandle - { - get { return (_handle != IntPtr.Zero); } - } - - private IntPtr SafeHandle - { - get - { - if (!IsValidHandle) - { - throw new ObjectDisposedException(nameof(MediaControllerServer), "Fail to operate MediaControllerServer"); - } - - return _handle; - } - } - - /// - /// The constructor of MediaControllerServer class. - /// - /// 3 - /// Thrown when the operation is invalid for the current state - /// Thrown when the access is denied for media controller client - public MediaControllerServer() - { - MediaControllerValidator.ThrowIfError( - Native.Create(out _handle), "Create server failed"); - } - - ~MediaControllerServer() - { - Dispose(false); - } - - public void Dispose() - { - Dispose(true); - GC.SuppressFinalize(this); - } - - protected virtual void Dispose(bool disposing) - { - if (!_disposed) - { - if (disposing) - { - // To be used if there are any other disposable objects - } - - if (IsValidHandle) - { - Native.Destroy(_handle); - _handle = IntPtr.Zero; - } - - _disposed = true; - } - } - - /// - /// PlaybackStateCommandRecieved event is raised when client send command for playback - /// - /// 3 - public event EventHandler PlaybackStateCommand - { - add - { - if (_playbackCommand == null) - { - RegisterPlaybackCmdRecvEvent(); - } - - _playbackCommand += value; - - } - - remove - { - _playbackCommand -= value; - if (_playbackCommand == null) - { - UnregisterPlaybackCmdRecvEvent(); - } - } - } - - /// - /// CustomCommandRecieved event is raised when client send customized command - /// - /// 3 - public event EventHandler CustomCommand - { - add - { - if (_customCommand == null) - { - RegisterCustomCommandEvent(); - } - - _customCommand += value; - - } - - remove - { - _customCommand -= value; - if (_customCommand == null) - { - UnregisterCustomCommandEvent(); - } - } - } - - /// - /// Update playback state and playback position - /// 3 - /// playback state and playback position - /// Thrown when an invalid argument is used - /// Thrown when the operation is invalid for the current state - public void UpdatePlayback(MediaControllerPlayback playback) - { - if (playback == null) - { - throw new ArgumentNullException("playback is null"); - } - - MediaControllerValidator.ThrowIfError( - Native.SetPlaybackState(SafeHandle, playback.State), "Set Playback state failed"); - - MediaControllerValidator.ThrowIfError( - Native.SetPlaybackPosition(SafeHandle, playback.Position), "Set Playback position failed"); - - MediaControllerValidator.ThrowIfError( - Native.UpdatePlayback(SafeHandle), "Update Playback failed"); - } - - /// - /// Update metadata information - /// 3 - /// metadata information - /// Thrown when an invalid argument is used - /// Thrown when the operation is invalid for the current state - public void UpdateMetadata(MediaControllerMetadata metadata) - { - if (metadata == null) - { - throw new ArgumentNullException("metadata is null"); - } - - MediaControllerValidator.ThrowIfError( - Native.SetMetadata(SafeHandle, MediaControllerAttributes.Title, metadata.Title), "Set Title failed"); - - MediaControllerValidator.ThrowIfError( - Native.SetMetadata(SafeHandle, MediaControllerAttributes.Artist, metadata.Artist), "Set Artist failed"); - - MediaControllerValidator.ThrowIfError( - Native.SetMetadata(SafeHandle, MediaControllerAttributes.Album, metadata.Album), "Set Album failed"); - - MediaControllerValidator.ThrowIfError( - Native.SetMetadata(SafeHandle, MediaControllerAttributes.Author, metadata.Author), "Set Author failed"); - - MediaControllerValidator.ThrowIfError( - Native.SetMetadata(SafeHandle, MediaControllerAttributes.Genre, metadata.Genre), "Set Genre failed"); - - MediaControllerValidator.ThrowIfError( - Native.SetMetadata(SafeHandle, MediaControllerAttributes.Duration, metadata.Duration), "Set Duration failed"); - - MediaControllerValidator.ThrowIfError( - Native.SetMetadata(SafeHandle, MediaControllerAttributes.Date, metadata.Date), "Set Date failed"); - - MediaControllerValidator.ThrowIfError( - Native.SetMetadata(SafeHandle, MediaControllerAttributes.Copyright, metadata.Copyright), "Set Copyright failed"); - - MediaControllerValidator.ThrowIfError( - Native.SetMetadata(SafeHandle, MediaControllerAttributes.Description, metadata.Description), "Set Description failed"); - - MediaControllerValidator.ThrowIfError( - Native.SetMetadata(SafeHandle, MediaControllerAttributes.TrackNumber, metadata.TrackNumber), "Set TrackNumber failed"); - - MediaControllerValidator.ThrowIfError( - Native.SetMetadata(SafeHandle, MediaControllerAttributes.Picture, metadata.Picture), "Set Picture failed"); - - MediaControllerValidator.ThrowIfError( - Native.UpdateMetadata(SafeHandle), "UpdateMetadata Metadata failed"); - } - - /// - /// Update shuffle mode - /// 3 - /// shuffle mode - /// Thrown when an invalid argument is used - /// Thrown when the operation is invalid for the current state - public void UpdateShuffleMode(MediaControllerShuffleMode mode) - { - MediaControllerValidator.ThrowIfError( - Native.UpdateShuffleMode(SafeHandle, mode), "Update Shuffle Mode failed"); - } - - /// - /// Update repeat mode - /// 3 - /// repeat mode - /// Thrown when an invalid argument is used - /// Thrown when the operation is invalid for the current state - public void UpdateRepeatMode(MediaControllerRepeatMode mode) - { - MediaControllerValidator.ThrowIfError( - Native.UpdateRepeatMode(SafeHandle, mode), "Update Repeat Mode failed"); - } - - /// - /// Send reply for command from server to client - /// 3 - /// client name to recieve reply - /// result to run command - /// Bundle to send various data - /// Thrown when an invalid argument is used - /// Thrown when the operation is invalid for the current state - public void SendCustomCommandReply(string clientName, int result, Bundle bundle) - { - MediaControllerValidator.ThrowIfError( - Native.SendCommandReply(SafeHandle, clientName, result, bundle.SafeBundleHandle), "Send reply for command failed"); - } - - private void RegisterPlaybackCmdRecvEvent() - { - _playbackCommandCallback = (IntPtr clientName, MediaControllerPlaybackState state, IntPtr userData) => - { - PlaybackStateCommandEventArgs eventArgs = new PlaybackStateCommandEventArgs(Marshal.PtrToStringAnsi(clientName), state); - _playbackCommand?.Invoke(this, eventArgs); - }; - Native.SetPlaybackStateCmdRecvCb(SafeHandle, _playbackCommandCallback, IntPtr.Zero); - } - - private void UnregisterPlaybackCmdRecvEvent() - { - Native.UnsetPlaybackStateCmdRecvCb(SafeHandle); - } - - private void RegisterCustomCommandEvent() - { - _customCommandCallback = (IntPtr clientName, IntPtr command, IntPtr bundle, IntPtr userData) => - { - SafeBundleHandle safeBundleHandle = new SafeBundleHandle(bundle, true); - Bundle bundleData = new Bundle(safeBundleHandle); - CustomCommandEventArgs eventArgs = new CustomCommandEventArgs(Marshal.PtrToStringAnsi(clientName), Marshal.PtrToStringAnsi(command), bundleData); - _customCommand?.Invoke(this, eventArgs); - }; - Native.SetCustomCmdRecvCb(SafeHandle, _customCommandCallback, IntPtr.Zero); - } - - private void UnregisterCustomCommandEvent() - { - Native.UnsetCustomCmdRecvCb(SafeHandle); - } - } -} - diff --git a/src/Tizen.Multimedia.Remoting/MediaController/MetadataUpdatedEventArgs.cs b/src/Tizen.Multimedia.Remoting/MediaController/MetadataUpdatedEventArgs.cs index 51a718c..98cbfed 100755 --- a/src/Tizen.Multimedia.Remoting/MediaController/MetadataUpdatedEventArgs.cs +++ b/src/Tizen.Multimedia.Remoting/MediaController/MetadataUpdatedEventArgs.cs @@ -1,49 +1,41 @@ /* -* 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. -*/ + * 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; -namespace Tizen.Multimedia.MediaController +namespace Tizen.Multimedia.Remoting { - /// - /// MetadataUpdated event arguments + /// Provides data for the event. /// - /// - /// MetadataUpdated event arguments - /// public class MetadataUpdatedEventArgs : EventArgs { - internal MetadataUpdatedEventArgs(string name, IntPtr handle) - { - ServerName = name; - Metadata = new MediaControllerMetadata(handle); - } - /// - /// Get the Server Name. + /// Initializes a new instance of the class. /// - /// 3 - public string ServerName { get; } + /// The updated . + public MetadataUpdatedEventArgs(MediaControlMetadata metadata) + { + Metadata = metadata; + } /// - /// Get the Metadata information. + /// Gets the metadata. /// - /// 3 - public MediaControllerMetadata Metadata { get; } + /// The updated . + public MediaControlMetadata Metadata { get; } } -} - +} \ No newline at end of file diff --git a/src/Tizen.Multimedia.Remoting/MediaController/PlaybackCommandReceivedEventArgs.cs b/src/Tizen.Multimedia.Remoting/MediaController/PlaybackCommandReceivedEventArgs.cs new file mode 100644 index 0000000..7d7c3e1 --- /dev/null +++ b/src/Tizen.Multimedia.Remoting/MediaController/PlaybackCommandReceivedEventArgs.cs @@ -0,0 +1,58 @@ +/* + * 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; + +namespace Tizen.Multimedia.Remoting +{ + /// + /// Provides data for the event. + /// + public class PlaybackCommandReceivedEventArgs : EventArgs + { + /// + /// Initializes a new instance of the class. + /// + /// The client application id. + /// The playback command. + /// is null. + /// is invalid. + public PlaybackCommandReceivedEventArgs(string clientAppId, MediaControlPlaybackCommand command) + { + if (clientAppId == null) + { + throw new ArgumentNullException(nameof(clientAppId)); + } + + ValidationUtil.ValidateEnum(typeof(MediaControlPlaybackCommand), command, nameof(command)); + + ClientAppId = clientAppId; + Command = command; + } + + /// + /// Gets the application id of the client that sent command. + /// + /// The client application id. + public string ClientAppId { get; } + + /// + /// Gets the command. + /// + /// The . + public MediaControlPlaybackCommand Command { get; } + } +} \ No newline at end of file diff --git a/src/Tizen.Multimedia.Remoting/MediaController/PlaybackStateCommandEventArgs.cs b/src/Tizen.Multimedia.Remoting/MediaController/PlaybackStateCommandEventArgs.cs deleted file mode 100755 index 339a90b..0000000 --- a/src/Tizen.Multimedia.Remoting/MediaController/PlaybackStateCommandEventArgs.cs +++ /dev/null @@ -1,49 +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. -*/ - -using System; - -namespace Tizen.Multimedia.MediaController -{ - - /// - /// PlaybackStateCommand event arguments - /// - /// - /// PlaybackStateCommand event arguments - /// - public class PlaybackStateCommandEventArgs : EventArgs - { - internal PlaybackStateCommandEventArgs(string name, MediaControllerPlaybackState state) - { - ClientName = name; - State = state; - } - - /// - /// Get the Client Name. - /// - /// 3 - public string ClientName { get; } - - /// - /// Get the State of playback. - /// - /// 3 - public MediaControllerPlaybackState State { get; } - } -} - diff --git a/src/Tizen.Multimedia.Remoting/MediaController/PlaybackStateUpdatedEventArgs.cs b/src/Tizen.Multimedia.Remoting/MediaController/PlaybackStateUpdatedEventArgs.cs new file mode 100644 index 0000000..d4ad662 --- /dev/null +++ b/src/Tizen.Multimedia.Remoting/MediaController/PlaybackStateUpdatedEventArgs.cs @@ -0,0 +1,58 @@ +/* + * 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.Diagnostics; +using Native = Interop.MediaControllerClient; + +namespace Tizen.Multimedia.Remoting +{ + /// + /// Provides data for the event. + /// + public class PlaybackStateUpdatedEventArgs : EventArgs + { + /// + /// Initializes a new instance of the class. + /// + /// The playback state. + /// The playback position in milliseconds. + /// is invalid. + /// is less than zero. + public PlaybackStateUpdatedEventArgs(MediaControlPlaybackState state, long position) + { + ValidationUtil.ValidateEnum(typeof(MediaControlPlaybackState), state, nameof(state)); + + if (position < 0) + { + throw new ArgumentOutOfRangeException(nameof(position), position, "position can't be less than zero."); + } + + State = state; + Position = position; + } + + /// + /// Gets the playback state. + /// + public MediaControlPlaybackState State { get; } + + /// + /// Gets the playback position in milliseconds. + /// + public long Position { get; } + } +} \ No newline at end of file diff --git a/src/Tizen.Multimedia.Remoting/MediaController/PlaybackUpdatedEventArgs.cs b/src/Tizen.Multimedia.Remoting/MediaController/PlaybackUpdatedEventArgs.cs deleted file mode 100755 index e6db63d..0000000 --- a/src/Tizen.Multimedia.Remoting/MediaController/PlaybackUpdatedEventArgs.cs +++ /dev/null @@ -1,49 +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. -*/ - -using System; - -namespace Tizen.Multimedia.MediaController -{ - - /// - /// PlaybackUpdated event arguments - /// - /// - /// PlaybackUpdated event arguments - /// - public class PlaybackUpdatedEventArgs : EventArgs - { - internal PlaybackUpdatedEventArgs(string name, IntPtr handle) - { - ServerName = name; - PlaybackInfo = new MediaControllerPlayback(handle); - } - - /// - /// Get the Server Name. - /// - /// 3 - public string ServerName { get; } - - /// - /// Get the Playback Information. - /// - /// 3 - public MediaControllerPlayback PlaybackInfo { get; } - } -} - diff --git a/src/Tizen.Multimedia.Remoting/MediaController/RepeatModeUpdatedEventArgs.cs b/src/Tizen.Multimedia.Remoting/MediaController/RepeatModeUpdatedEventArgs.cs index e9abebd..f0fecf3 100755 --- a/src/Tizen.Multimedia.Remoting/MediaController/RepeatModeUpdatedEventArgs.cs +++ b/src/Tizen.Multimedia.Remoting/MediaController/RepeatModeUpdatedEventArgs.cs @@ -1,49 +1,44 @@ /* -* 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. -*/ + * 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; -namespace Tizen.Multimedia.MediaController +namespace Tizen.Multimedia.Remoting { - /// - /// RepeatModeUpdated event arguments + /// Provides data for the event. /// - /// - /// RepeatModeUpdated event arguments - /// public class RepeatModeUpdatedEventArgs : EventArgs { - internal RepeatModeUpdatedEventArgs(string name, MediaControllerRepeatMode mode) + /// + /// Initializes a new instance of the class. + /// + /// A value indicating the updated repeat mode. + /// is invalid. + public RepeatModeUpdatedEventArgs(MediaControlRepeatMode mode) { - ServerName = name; + ValidationUtil.ValidateEnum(typeof(MediaControlRepeatMode), mode, nameof(mode)); + RepeatMode = mode; } /// - /// Get the Server Name. + /// Gets the updated repeat mode. /// - /// 3 - public string ServerName { get; } - - /// - /// Get the Repeat Mode. - /// - /// 3 - public MediaControllerRepeatMode RepeatMode { get; } + /// The . + public MediaControlRepeatMode RepeatMode { get; } } -} - +} \ No newline at end of file diff --git a/src/Tizen.Multimedia.Remoting/MediaController/ServerInformation.cs b/src/Tizen.Multimedia.Remoting/MediaController/ServerInformation.cs deleted file mode 100755 index 39684e8..0000000 --- a/src/Tizen.Multimedia.Remoting/MediaController/ServerInformation.cs +++ /dev/null @@ -1,45 +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. -*/ - -using System; - -namespace Tizen.Multimedia.MediaController -{ - /// - /// ServerInformation represents a name and state of server application. - /// - public class ServerInformation - { - internal ServerInformation(string name, MediaControllerServerState state) - { - Name = name; - State = state; - } - - /// - /// Get the Name of server - /// - /// 3 - public string Name { get; } - - /// - /// Get the State of server - /// - /// 3 - public MediaControllerServerState State { get; } - } -} - diff --git a/src/Tizen.Multimedia.Remoting/MediaController/ServerUpdatedEventArgs.cs b/src/Tizen.Multimedia.Remoting/MediaController/ServerUpdatedEventArgs.cs deleted file mode 100755 index 1fa8319..0000000 --- a/src/Tizen.Multimedia.Remoting/MediaController/ServerUpdatedEventArgs.cs +++ /dev/null @@ -1,42 +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. -*/ - -using System; - -namespace Tizen.Multimedia.MediaController -{ - - /// - /// ServerUpdated event arguments - /// - /// - /// ServerUpdated event arguments - /// - public class ServerUpdatedEventArgs : EventArgs - { - internal ServerUpdatedEventArgs(string name, MediaControllerServerState state) - { - ServerInfo = new ServerInformation(name, state); - } - - /// - /// Get the Server Information. - /// - /// 3 - public ServerInformation ServerInfo { get; } - } -} - diff --git a/src/Tizen.Multimedia.Remoting/MediaController/ShuffleModeUpdatedEventArgs.cs b/src/Tizen.Multimedia.Remoting/MediaController/ShuffleModeUpdatedEventArgs.cs index 6d5a5c3..7905803 100755 --- a/src/Tizen.Multimedia.Remoting/MediaController/ShuffleModeUpdatedEventArgs.cs +++ b/src/Tizen.Multimedia.Remoting/MediaController/ShuffleModeUpdatedEventArgs.cs @@ -1,49 +1,41 @@ /* -* 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. -*/ + * 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; -namespace Tizen.Multimedia.MediaController +namespace Tizen.Multimedia.Remoting { - /// - /// ShuffleModeUpdated event arguments + /// Provides data for the event. /// - /// - /// ShuffleModeUpdated event arguments - /// public class ShuffleModeUpdatedEventArgs : EventArgs { - internal ShuffleModeUpdatedEventArgs(string name, MediaControllerShuffleMode mode) - { - ServerName = name; - ShuffleMode = mode; - } - /// - /// Get the Server Name. + /// Initializes a new instance of the class. /// - /// 3 - public string ServerName { get; } + /// A value indicating whether the shuffle mode is enabled. + public ShuffleModeUpdatedEventArgs(bool enabled) + { + Enabled = enabled; + } /// - /// Get the Shuffle Mode. + /// Gets a value indicating whether the shuffle mode is enabled. /// - /// 3 - public MediaControllerShuffleMode ShuffleMode { get; } + /// true if the shuffle mode is enabled; otherwise, false. + public bool Enabled { get; } } -} - +} \ No newline at end of file -- 2.7.4