/
MediaControlServer.Events.cs
324 lines (275 loc) · 14.4 KB
/
MediaControlServer.Events.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
/*
* Copyright (c) 2018 Samsung Electronics Co., Ltd All Rights Reserved
*
* Licensed under the Apache License, Version 2.0 (the License);
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an AS IS BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
using Tizen.Applications;
using System;
using System.Collections.Generic;
using Native = Interop.MediaControllerServer;
namespace Tizen.Multimedia.Remoting
{
public static partial class MediaControlServer
{
private static Native.PlaybackActionCommandReceivedCallback _playbackActionCommandCallback;
private static Native.PlaybackPositionCommandReceivedCallback _playbackPositionCommandCallback;
private static Native.PlaylistCommandReceivedCallback _playlistCommandCallback;
private static Native.ShuffleModeCommandReceivedCallback _shuffleModeCommandCallback;
private static Native.RepeatModeCommandReceivedCallback _repeatModeCommandCallback;
private static Native.SimpleCommandReceivedCallback _subtitleModeCommandCallback;
private static Native.SimpleCommandReceivedCallback _mode360CommandCallback;
private static Native.DisplayModeCommandReceivedCallback _displayModeCommandCallback;
private static Native.DisplayRotationCommandReceivedCallback _displayRotationCommandCallback;
private static Native.CustomCommandReceivedCallback _customCommandCallback;
private static Native.SearchCommandReceivedCallback _searchCommandCallback;
private static Native.CommandCompletedCallback _commandCompletedCallback;
/// <summary>
/// Occurs when a client sends playback command.
/// </summary>
/// <since_tizen> 4 </since_tizen>
[Obsolete("Please do not use! This will be deprecated. Please use PlaybackActionCommandReceived instead.")]
public static event EventHandler<PlaybackCommandReceivedEventArgs> PlaybackCommandReceived;
/// <summary>
/// Occurs when a client sends playback command.
/// </summary>
/// <since_tizen> 5 </since_tizen>
public static event EventHandler<PlaybackActionCommandReceivedEventArgs> PlaybackActionCommandReceived;
/// <summary>
/// Occurs when a client sends playback position command.
/// </summary>
/// <since_tizen> 5 </since_tizen>
public static event EventHandler<PlaybackPositionCommandReceivedEventArgs> PlaybackPositionCommandReceived;
/// <summary>
/// Occurs when a client sends playlist command.
/// </summary>
/// <since_tizen> 5 </since_tizen>
public static event EventHandler<PlaylistCommandReceivedEventArgs> PlaylistCommandReceived;
/// <summary>
/// Occurs when a client sends shuffle mode command.
/// </summary>
/// <since_tizen> 5 </since_tizen>
public static event EventHandler<ShuffleModeCommandReceivedEventArgs> ShuffleModeCommandReceived;
/// <summary>
/// Occurs when a client sends repeat mode command.
/// </summary>
/// <since_tizen> 5 </since_tizen>
public static event EventHandler<RepeatModeCommandReceivedEventArgs> RepeatModeCommandReceived;
/// <summary>
/// Occurs when a client sends subtitle mode command.
/// </summary>
/// <since_tizen> 6 </since_tizen>
public static event EventHandler<SubtitleModeCommandReceivedEventArgs> SubtitleModeCommandReceived;
/// <summary>
/// Occurs when a client sends mode 360 command.
/// </summary>
/// <since_tizen> 6 </since_tizen>
public static event EventHandler<Mode360CommandReceivedEventArgs> Mode360CommandReceived;
/// <summary>
/// Occurs when a client sends display mode command.
/// </summary>
/// <since_tizen> 6 </since_tizen>
public static event EventHandler<DisplayModeCommandReceivedEventArgs> DisplayModeCommandReceived;
/// <summary>
/// Occurs when a client sends display rotation command.
/// </summary>
/// <since_tizen> 6 </since_tizen>
public static event EventHandler<DisplayRotationCommandReceivedEventArgs> DisplayRotationCommandReceived;
/// <summary>
/// Occurs when a client sends custom command.
/// </summary>
/// <since_tizen> 5 </since_tizen>
public static event EventHandler<CustomCommandReceivedEventArgs> CustomCommandReceived;
/// <summary>
/// Occurs when a client sends search command.
/// </summary>
/// <since_tizen> 5 </since_tizen>
public static event EventHandler<SearchCommandReceivedEventArgs> SearchCommandReceived;
/// <summary>
/// Occurs when a client sends custom command.
/// </summary>
/// <since_tizen> 5 </since_tizen>
internal static event EventHandler<CommandCompletedEventArgs> CommandCompleted;
private static void RegisterPlaybackActionCommandReceivedEvent()
{
_playbackActionCommandCallback = (clientName, requestId, playbackCommand, _) =>
{
// SendPlaybackCommand doesn't use requestId. It'll be removed in Level 7.
if (requestId == null)
{
#pragma warning disable CS0618 // Type or member is obsolete
PlaybackCommandReceived?.Invoke(null, new PlaybackCommandReceivedEventArgs(clientName, playbackCommand.ToPublic()));
#pragma warning restore CS0618 // Type or member is obsolete
}
else
{
var command = new PlaybackCommand(playbackCommand.ToPublic());
command.SetResponseInformation(clientName, requestId);
PlaybackActionCommandReceived?.Invoke(null, new PlaybackActionCommandReceivedEventArgs(command));
}
};
Native.SetPlaybackActionCommandReceivedCb(Handle, _playbackActionCommandCallback).
ThrowIfError("Failed to init PlaybackActionCommandReceived event.");
}
private static void RegisterPlaybackPositionCommandReceivedEvent()
{
_playbackPositionCommandCallback = (clientName, requestId, playbackPosition, _) =>
{
var command = new PlaybackPositionCommand(playbackPosition);
command.SetResponseInformation(clientName, requestId);
PlaybackPositionCommandReceived?.Invoke(null, new PlaybackPositionCommandReceivedEventArgs(command));
};
Native.SetPlaybackPosotionCommandReceivedCb(Handle, _playbackPositionCommandCallback).
ThrowIfError("Failed to init PlaybackPositionCommandReceived event.");
}
private static void RegisterPlaylistCommandReceivedEvent()
{
_playlistCommandCallback = (clientName, requestId, playlistName, index, playbackCommand, playbackPosition, _) =>
{
var command = new PlaylistCommand(playbackCommand.ToPublic(), playlistName, index, playbackPosition);
command.SetResponseInformation(clientName, requestId);
PlaylistCommandReceived?.Invoke(null, new PlaylistCommandReceivedEventArgs(command));
};
Native.SetPlaylistCommandReceivedCb(Handle, _playlistCommandCallback).
ThrowIfError("Failed to init PlaylistCommandReceived event.");
}
private static void RegisterShuffleModeCommandReceivedEvent()
{
_shuffleModeCommandCallback = (clientName, requestId, mode, _) =>
{
var command = new ShuffleModeCommand(mode == MediaControllerNativeShuffleMode.On ? true : false);
command.SetResponseInformation(clientName, requestId);
ShuffleModeCommandReceived?.Invoke(null, new ShuffleModeCommandReceivedEventArgs(command));
};
Native.SetShuffleModeCommandReceivedCb(Handle, _shuffleModeCommandCallback).
ThrowIfError("Failed to init ShuffleModeCommandReceived event.");
}
private static void RegisterRepeatModeCommandReceivedEvent()
{
_repeatModeCommandCallback = (clientName, requestId, mode, _) =>
{
var command = new RepeatModeCommand(mode.ToPublic());
command.SetResponseInformation(clientName, requestId);
RepeatModeCommandReceived?.Invoke(null, new RepeatModeCommandReceivedEventArgs(command));
};
Native.SetRepeatModeCommandReceivedCb(Handle, _repeatModeCommandCallback).
ThrowIfError("Failed to init RepeatModeCommandReceived event.");
}
private static void RegisterSubtitleModeCommandReceivedEvent()
{
_subtitleModeCommandCallback = (clientName, requestId, isEnabled, _) =>
{
var command = new SubtitleModeCommand(isEnabled);
command.SetResponseInformation(clientName, requestId);
SubtitleModeCommandReceived?.Invoke(null, new SubtitleModeCommandReceivedEventArgs(command));
};
Native.SetSubtitleModeCommandReceivedCb(Handle, _subtitleModeCommandCallback).
ThrowIfError("Failed to init SubtitleModeCommandReceived event.");
}
private static void RegisterMode360CommandReceivedEvent()
{
_mode360CommandCallback = (clientName, requestId, isEnabled, _) =>
{
var command = new Mode360Command(isEnabled);
command.SetResponseInformation(clientName, requestId);
Mode360CommandReceived?.Invoke(null, new Mode360CommandReceivedEventArgs(command));
};
Native.SetMode360CommandReceivedCb(Handle, _mode360CommandCallback).
ThrowIfError("Failed to init Mode360CommandReceived event.");
}
private static void RegisterDisplayModeCommandReceivedEvent()
{
_displayModeCommandCallback = (clientName, requestId, mode, _) =>
{
var command = new DisplayModeCommand(mode.ToPublic());
command.SetResponseInformation(clientName, requestId);
DisplayModeCommandReceived?.Invoke(null, new DisplayModeCommandReceivedEventArgs(command));
};
Native.SetDisplayModeCommandReceivedCb(Handle, _displayModeCommandCallback).
ThrowIfError("Failed to init DisplayModeCommandReceived event.");
}
private static void RegisterDisplayRotationCommandReceivedEvent()
{
_displayRotationCommandCallback = (clientName, requestId, rotation, _) =>
{
var command = new DisplayRotationCommand(rotation.ToPublic());
command.SetResponseInformation(clientName, requestId);
DisplayRotationCommandReceived?.Invoke(null, new DisplayRotationCommandReceivedEventArgs(command));
};
Native.SetDisplayRotationCommandReceivedCb(Handle, _displayRotationCommandCallback).
ThrowIfError("Failed to init DisplayRotationCommandReceived event.");
}
private static void RegisterCustomCommandReceivedEvent()
{
_customCommandCallback = (clientName, requestId, customCommand, bundleHandle, _) =>
{
CustomCommand command = null;
if (bundleHandle != IntPtr.Zero)
{
command = new CustomCommand(customCommand, new Bundle(new SafeBundleHandle(bundleHandle, true)));
}
else
{
command = new CustomCommand(customCommand);
}
command.SetResponseInformation(clientName, requestId);
CustomCommandReceived?.Invoke(null, new CustomCommandReceivedEventArgs(command));
};
Native.SetCustomCommandReceivedCb(Handle, _customCommandCallback).
ThrowIfError("Failed to init CustomCommandReceived event.");
}
private static SearchCommand CreateSearchCommandReceivedEventArgs(IntPtr searchHandle)
{
var searchConditions = new List<MediaControlSearchCondition>();
Native.SearchItemCallback searchItemCallback = (type, category, keyword, bundleHandle, _) =>
{
Bundle bundle = null;
if (bundleHandle != IntPtr.Zero)
{
bundle = new Bundle(new SafeBundleHandle(bundleHandle, true));
}
searchConditions.Add(new MediaControlSearchCondition(type, category, keyword, bundle));
return true;
};
Native.ForeachSearchCondition(searchHandle, searchItemCallback).
ThrowIfError("Failed to get search items.");
return new SearchCommand(searchConditions, searchHandle);
}
private static void RegisterSearchCommandReceivedEvent()
{
_searchCommandCallback = (clientName, requestId, searchHandle, _) =>
{
var command = CreateSearchCommandReceivedEventArgs(searchHandle);
command.SetResponseInformation(clientName, requestId);
SearchCommandReceived?.Invoke(null, new SearchCommandReceivedEventArgs(command));
};
Native.SetSearchCommandReceivedCb(Handle, _searchCommandCallback).
ThrowIfError("Failed to init SearchCommandReceived event.");
}
private static void RegisterCommandCompletedEvent()
{
_commandCompletedCallback = (clientName, requestId, result, bundleHandle, _) =>
{
if (bundleHandle != IntPtr.Zero)
{
CommandCompleted?.Invoke(null, new CommandCompletedEventArgs(requestId, result, new Bundle(new SafeBundleHandle(bundleHandle, true))));
}
else
{
CommandCompleted?.Invoke(null, new CommandCompletedEventArgs(requestId, result));
}
};
Native.SetEventReceivedCb(Handle, _commandCompletedCallback).
ThrowIfError("Failed to init RegisterEventCompletedEvent.");
}
}
}