2 * Copyright (c) 2018 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 System.Collections.Generic;
20 using Native = Interop.MediaControllerServer;
22 namespace Tizen.Multimedia.Remoting
24 public static partial class MediaControlServer
26 private static Native.PlaybackStateCommandReceivedCallback _playbackCommandCallback;
27 private static Native.PlaybackActionCommandReceivedCallback _playbackActionCommandCallback;
28 private static Native.PlaybackPositionCommandReceivedCallback _playbackPositionCommandCallback;
29 private static Native.PlaylistCommandReceivedCallback _playlistCommandCallback;
30 private static Native.ShuffleModeCommandReceivedCallback _shuffleModeCommandCallback;
31 private static Native.RepeatModeCommandReceivedCallback _repeatModeCommandCallback;
32 private static Native.SimpleCommandReceivedCallback _subtitleModeCommandCallback;
33 private static Native.SimpleCommandReceivedCallback _mode360CommandCallback;
34 private static Native.DisplayModeCommandReceivedCallback _displayModeCommandCallback;
35 private static Native.DisplayRotationCommandReceivedCallback _displayRotationCommandCallback;
37 private static Native.CustomCommandReceivedCallback _customCommandCallback;
38 private static Native.SearchCommandReceivedCallback _searchCommandCallback;
39 private static Native.CommandCompletedCallback _commandCompletedCallback;
43 /// Occurs when a client sends playback command.
45 /// <since_tizen> 4 </since_tizen>
46 [Obsolete("Please do not use! This will be deprecated. Please use PlaybackActionCommandReceived instead.")]
47 public static event EventHandler<PlaybackCommandReceivedEventArgs> PlaybackCommandReceived;
50 /// Occurs when a client sends playback command.
52 /// <since_tizen> 5 </since_tizen>
53 public static event EventHandler<PlaybackActionCommandReceivedEventArgs> PlaybackActionCommandReceived;
56 /// Occurs when a client sends playback position command.
58 /// <since_tizen> 5 </since_tizen>
59 public static event EventHandler<PlaybackPositionCommandReceivedEventArgs> PlaybackPositionCommandReceived;
62 /// Occurs when a client sends playlist command.
64 /// <since_tizen> 5 </since_tizen>
65 public static event EventHandler<PlaylistCommandReceivedEventArgs> PlaylistCommandReceived;
68 /// Occurs when a client sends shuffle mode command.
70 /// <since_tizen> 5 </since_tizen>
71 public static event EventHandler<ShuffleModeCommandReceivedEventArgs> ShuffleModeCommandReceived;
74 /// Occurs when a client sends repeat mode command.
76 /// <since_tizen> 5 </since_tizen>
77 public static event EventHandler<RepeatModeCommandReceivedEventArgs> RepeatModeCommandReceived;
80 /// Occurs when a client sends subtitle mode command.
82 /// <since_tizen> 6 </since_tizen>
83 public static event EventHandler<SubtitleModeCommandReceivedEventArgs> SubtitleModeCommandReceived;
86 /// Occurs when a client sends mode 360 command.
88 /// <since_tizen> 6 </since_tizen>
89 public static event EventHandler<Mode360CommandReceivedEventArgs> Mode360CommandReceived;
92 /// Occurs when a client sends display mode command.
94 /// <since_tizen> 6 </since_tizen>
95 public static event EventHandler<DisplayModeCommandReceivedEventArgs> DisplayModeCommandReceived;
98 /// Occurs when a client sends display rotation command.
100 /// <since_tizen> 6 </since_tizen>
101 public static event EventHandler<DisplayRotationCommandReceivedEventArgs> DisplayRotationCommandReceived;
104 /// Occurs when a client sends custom command.
106 /// <since_tizen> 5 </since_tizen>
107 public static event EventHandler<CustomCommandReceivedEventArgs> CustomCommandReceived;
110 /// Occurs when a client sends search command.
112 /// <since_tizen> 5 </since_tizen>
113 public static event EventHandler<SearchCommandReceivedEventArgs> SearchCommandReceived;
116 /// Occurs when a client sends custom command.
118 /// <since_tizen> 5 </since_tizen>
119 internal static event EventHandler<CommandCompletedEventArgs> CommandCompleted;
121 private static void RegisterPlaybackActionCommandReceivedEvent()
123 _playbackActionCommandCallback = (clientName, requestId, playbackCommand, _) =>
125 // SendPlaybackCommand doesn't use requestId. It'll be removed in Level 7.
126 if (requestId == null)
128 #pragma warning disable CS0618 // Type or member is obsolete
129 PlaybackCommandReceived?.Invoke(null, new PlaybackCommandReceivedEventArgs(clientName, playbackCommand.ToPublic()));
130 #pragma warning restore CS0618 // Type or member is obsolete
134 var command = new PlaybackCommand(playbackCommand.ToPublic());
135 command.SetResponseInformation(clientName, requestId);
137 PlaybackActionCommandReceived?.Invoke(null, new PlaybackActionCommandReceivedEventArgs(command));
140 Native.SetPlaybackActionCommandReceivedCb(Handle, _playbackActionCommandCallback).
141 ThrowIfError("Failed to init PlaybackActionCommandReceived event.");
144 private static void RegisterPlaybackPositionCommandReceivedEvent()
146 _playbackPositionCommandCallback = (clientName, requestId, playbackPosition, _) =>
148 var command = new PlaybackPositionCommand(playbackPosition);
149 command.SetResponseInformation(clientName, requestId);
151 PlaybackPositionCommandReceived?.Invoke(null, new PlaybackPositionCommandReceivedEventArgs(command));
153 Native.SetPlaybackPosotionCommandReceivedCb(Handle, _playbackPositionCommandCallback).
154 ThrowIfError("Failed to init PlaybackPositionCommandReceived event.");
157 private static void RegisterPlaylistCommandReceivedEvent()
159 _playlistCommandCallback = (clientName, requestId, playlistName, index, playbackCommand, playbackPosition, _) =>
161 var command = new PlaylistCommand(playbackCommand.ToPublic(), playlistName, index, playbackPosition);
162 command.SetResponseInformation(clientName, requestId);
164 PlaylistCommandReceived?.Invoke(null, new PlaylistCommandReceivedEventArgs(command));
166 Native.SetPlaylistCommandReceivedCb(Handle, _playlistCommandCallback).
167 ThrowIfError("Failed to init PlaylistCommandReceived event.");
170 private static void RegisterShuffleModeCommandReceivedEvent()
172 _shuffleModeCommandCallback = (clientName, requestId, mode, _) =>
174 var command = new ShuffleModeCommand(mode == MediaControllerNativeShuffleMode.On ? true : false);
175 command.SetResponseInformation(clientName, requestId);
177 ShuffleModeCommandReceived?.Invoke(null, new ShuffleModeCommandReceivedEventArgs(command));
179 Native.SetShuffleModeCommandReceivedCb(Handle, _shuffleModeCommandCallback).
180 ThrowIfError("Failed to init ShuffleModeCommandReceived event.");
183 private static void RegisterRepeatModeCommandReceivedEvent()
185 _repeatModeCommandCallback = (clientName, requestId, mode, _) =>
187 var command = new RepeatModeCommand(mode.ToPublic());
188 command.SetResponseInformation(clientName, requestId);
190 RepeatModeCommandReceived?.Invoke(null, new RepeatModeCommandReceivedEventArgs(command));
192 Native.SetRepeatModeCommandReceivedCb(Handle, _repeatModeCommandCallback).
193 ThrowIfError("Failed to init RepeatModeCommandReceived event.");
196 private static void RegisterSubtitleModeCommandReceivedEvent()
198 _subtitleModeCommandCallback = (clientName, requestId, isEnabled, _) =>
200 var command = new SubtitleModeCommand(isEnabled);
201 command.SetResponseInformation(clientName, requestId);
203 SubtitleModeCommandReceived?.Invoke(null, new SubtitleModeCommandReceivedEventArgs(command));
205 Native.SetSubtitleModeCommandReceivedCb(Handle, _subtitleModeCommandCallback).
206 ThrowIfError("Failed to init SubtitleModeCommandReceived event.");
209 private static void RegisterMode360CommandReceivedEvent()
211 _mode360CommandCallback = (clientName, requestId, isEnabled, _) =>
213 var command = new Mode360Command(isEnabled);
214 command.SetResponseInformation(clientName, requestId);
216 Mode360CommandReceived?.Invoke(null, new Mode360CommandReceivedEventArgs(command));
218 Native.SetMode360CommandReceivedCb(Handle, _mode360CommandCallback).
219 ThrowIfError("Failed to init Mode360CommandReceived event.");
222 private static void RegisterDisplayModeCommandReceivedEvent()
224 _displayModeCommandCallback = (clientName, requestId, mode, _) =>
226 var command = new DisplayModeCommand(mode.ToPublic());
227 command.SetResponseInformation(clientName, requestId);
229 DisplayModeCommandReceived?.Invoke(null, new DisplayModeCommandReceivedEventArgs(command));
231 Native.SetDisplayModeCommandReceivedCb(Handle, _displayModeCommandCallback).
232 ThrowIfError("Failed to init DisplayModeCommandReceived event.");
235 private static void RegisterDisplayRotationCommandReceivedEvent()
237 _displayRotationCommandCallback = (clientName, requestId, rotation, _) =>
239 var command = new DisplayRotationCommand(rotation.ToPublic());
240 command.SetResponseInformation(clientName, requestId);
242 DisplayRotationCommandReceived?.Invoke(null, new DisplayRotationCommandReceivedEventArgs(command));
244 Native.SetDisplayRotationCommandReceivedCb(Handle, _displayRotationCommandCallback).
245 ThrowIfError("Failed to init DisplayRotationCommandReceived event.");
248 private static void RegisterCustomCommandReceivedEvent()
250 _customCommandCallback = (clientName, requestId, customCommand, bundleHandle, _) =>
252 CustomCommand command = null;
253 if (bundleHandle != IntPtr.Zero)
255 command = new CustomCommand(customCommand, new Bundle(new SafeBundleHandle(bundleHandle, true)));
259 command = new CustomCommand(customCommand);
262 command.SetResponseInformation(clientName, requestId);
264 CustomCommandReceived?.Invoke(null, new CustomCommandReceivedEventArgs(command));
266 Native.SetCustomCommandReceivedCb(Handle, _customCommandCallback).
267 ThrowIfError("Failed to init CustomCommandReceived event.");
270 private static SearchCommand CreateSearchCommandReceivedEventArgs(IntPtr searchHandle)
272 var searchConditions = new List<MediaControlSearchCondition>();
274 Native.SearchItemCallback searchItemCallback = (type, category, keyword, bundleHandle, _) =>
276 Bundle bundle = null;
278 if (bundleHandle != IntPtr.Zero)
280 bundle = new Bundle(new SafeBundleHandle(bundleHandle, true));
283 searchConditions.Add(new MediaControlSearchCondition(type, category, keyword, bundle));
288 Native.ForeachSearchCondition(searchHandle, searchItemCallback).
289 ThrowIfError("Failed to get search items.");
291 return new SearchCommand(searchConditions, searchHandle);
294 private static void RegisterSearchCommandReceivedEvent()
296 _searchCommandCallback = (clientName, requestId, searchHandle, _) =>
298 var command = CreateSearchCommandReceivedEventArgs(searchHandle);
300 command.SetResponseInformation(clientName, requestId);
302 SearchCommandReceived?.Invoke(null, new SearchCommandReceivedEventArgs(command));
304 Native.SetSearchCommandReceivedCb(Handle, _searchCommandCallback).
305 ThrowIfError("Failed to init SearchCommandReceived event.");
308 private static void RegisterCommandCompletedEvent()
310 _commandCompletedCallback = (clientName, requestId, result, bundleHandle, _) =>
312 if (bundleHandle != IntPtr.Zero)
314 CommandCompleted?.Invoke(null, new CommandCompletedEventArgs(requestId, result, new Bundle(new SafeBundleHandle(bundleHandle, true))));
318 CommandCompleted?.Invoke(null, new CommandCompletedEventArgs(requestId, result));
321 Native.SetEventReceivedCb(Handle, _commandCompletedCallback).
322 ThrowIfError("Failed to init RegisterEventCompletedEvent.");