2 * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
4 * Licensed under the Apache License, Version 2.0 (the License);
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an AS IS BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 using Tizen.Applications;
19 using Native = Interop.MediaControllerServer;
21 namespace Tizen.Multimedia.Remoting
23 public static partial class MediaControlServer
25 private static Native.PlaybackStateCommandReceivedCallback _playbackCommandCallback;
26 private static Native.PlaybackActionCommandReceivedCallback _playbackActionCommandCallback;
27 private static Native.PlaybackPositionCommandReceivedCallback _playbackPositionCommandCallback;
28 private static Native.PlaylistCommandReceivedCallback _playlistCommandCallback;
29 private static Native.ShuffleModeCommandReceivedCallback _shuffleModeCommandCallback;
30 private static Native.RepeatModeCommandReceivedCallback _repeatModeCommandCallback;
31 private static Native.CustomCommandReceivedCallback _customCommandCallback;
34 /// Occurs when a client sends playback command.
36 /// <since_tizen> 4 </since_tizen>
37 [Obsolete("Please do not use! This will be deprecated. Please use PlaybackActionCommandReceived instead.")]
38 public static event EventHandler<PlaybackCommandReceivedEventArgs> PlaybackCommandReceived;
41 /// Occurs when a client sends playback command.
43 /// <since_tizen> 5 </since_tizen>
44 public static event EventHandler<PlaybackActionCommandReceivedEventArgs> PlaybackActionCommandReceived;
47 /// Occurs when a client sends playback position command.
49 /// <since_tizen> 5 </since_tizen>
50 public static event EventHandler<PlaybackPositionCommandReceivedEventArgs> PlaybackPositionCommandReceived;
53 /// Occurs when a client sends playlist command.
55 /// <since_tizen> 5 </since_tizen>
56 public static event EventHandler<PlaylistCommandReceivedEventArgs> PlaylistCommandReceived;
59 /// Occurs when a client sends shuffle mode command.
61 /// <since_tizen> 5 </since_tizen>
62 public static event EventHandler<ShuffleModeCommandReceivedEventArgs> ShuffleModeCommandReceived;
65 /// Occurs when a client sends repeat mode command.
67 /// <since_tizen> 5 </since_tizen>
68 public static event EventHandler<RepeatModeCommandReceivedEventArgs> RepeatModeCommandReceived;
71 /// Occurs when a client sends custom command.
73 /// <since_tizen> 5 </since_tizen>
74 public static event EventHandler<CustomCommandReceivedEventArgs> CustomCommandReceived;
76 private static void RegisterPlaybackCommandReceivedEvent()
78 _playbackCommandCallback = (clientName, playbackCode, _) =>
80 PlaybackCommandReceived?.Invoke(null, new PlaybackCommandReceivedEventArgs(clientName, playbackCode.ToPublic()));
82 Native.SetPlaybackStateCommandReceivedCb(Handle, _playbackCommandCallback).
83 ThrowIfError("Failed to init PlaybackStateCommandReceived event.");
86 private static void RegisterPlaybackActionCommandReceivedEvent()
88 _playbackActionCommandCallback = (clientName, requestId, playbackCommand, _) =>
90 var command = new PlaybackCommand(playbackCommand.ToPublic());
91 command.SetClientInfo(clientName, requestId);
93 PlaybackActionCommandReceived?.Invoke(null, new PlaybackActionCommandReceivedEventArgs(command));
95 Native.SetPlaybackActionCommandReceivedCb(Handle, _playbackActionCommandCallback).
96 ThrowIfError("Failed to init PlaybackActionCommandReceived event.");
99 private static void RegisterPlaybackPositionCommandReceivedEvent()
101 _playbackPositionCommandCallback = (clientName, requestId, playbackPosition, _) =>
103 var command = new PlaybackPositionCommand(playbackPosition);
104 command.SetClientInfo(clientName, requestId);
106 PlaybackPositionCommandReceived?.Invoke(null, new PlaybackPositionCommandReceivedEventArgs(command));
108 Native.SetPlaybackPosotionCommandReceivedCb(Handle, _playbackPositionCommandCallback).
109 ThrowIfError("Failed to init PlaybackPositionCommandReceived event.");
112 private static void RegisterPlaylistCommandReceivedEvent()
114 _playlistCommandCallback = (clientName, requestId, playlistName, index, playbackCommand, playbackPosition, _) =>
116 var command = new PlaylistCommand(playbackCommand.ToPublic(), playlistName, index, playbackPosition);
117 command.SetClientInfo(clientName, requestId);
119 PlaylistCommandReceived?.Invoke(null, new PlaylistCommandReceivedEventArgs(command));
121 Native.SetPlaylistCommandReceivedCb(Handle, _playlistCommandCallback).
122 ThrowIfError("Failed to init PlaylistCommandReceived event.");
125 private static void RegisterShuffleModeCommandReceivedEvent()
127 _shuffleModeCommandCallback = (clientName, requestId, mode, _) =>
129 var command = new ShuffleModeCommand(mode == MediaControllerNativeShuffleMode.On ? true : false);
130 command.SetClientInfo(clientName, requestId);
132 ShuffleModeCommandReceived?.Invoke(null, new ShuffleModeCommandReceivedEventArgs(command));
134 Native.SetShuffleModeCommandReceivedCb(Handle, _shuffleModeCommandCallback).
135 ThrowIfError("Failed to init ShuffleModeCommandReceived event.");
138 private static void RegisterRepeatModeCommandReceivedEvent()
140 _repeatModeCommandCallback = (clientName, requestId, mode, _) =>
142 var command = new RepeatModeCommand(mode.ToPublic());
143 command.SetClientInfo(clientName, requestId);
145 RepeatModeCommandReceived?.Invoke(null, new RepeatModeCommandReceivedEventArgs(command));
147 Native.SetRepeatModeCommandReceivedCb(Handle, _repeatModeCommandCallback).
148 ThrowIfError("Failed to init RepeatModeCommandReceived event.");
151 private static void RegisterCustomCommandReceivedEvent()
153 _customCommandCallback = (clientName, requestId, customCommand, bundleHandle, _) =>
155 CustomCommand command = null;
156 if (bundleHandle != IntPtr.Zero)
158 command = new CustomCommand(customCommand, new Bundle(new SafeBundleHandle(bundleHandle, true)));
162 command = new CustomCommand(customCommand);
165 command.SetClientInfo(clientName, requestId);
167 CustomCommandReceived?.Invoke(null, new CustomCommandReceivedEventArgs(command));
169 Native.SetCustomCommandReceivedCb(Handle, _customCommandCallback).
170 ThrowIfError("Failed to init CustomCommandReceived event.");