-
Notifications
You must be signed in to change notification settings - Fork 241
/
MediaController.Events.cs
385 lines (325 loc) · 14.2 KB
/
MediaController.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
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
/*
* 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.Linq;
using System.Collections.Generic;
using Tizen.Applications;
using Native = Interop.MediaControllerClient;
namespace Tizen.Multimedia.Remoting
{
/// <summary>
/// Provides a means to to send commands to and handle events from media control server.
/// </summary>
/// <since_tizen> 4 </since_tizen>
public partial class MediaController
{
/// <summary>
/// Occurs when the server is stopped.
/// </summary>
/// <since_tizen> 4 </since_tizen>
public event EventHandler ServerStopped;
internal void RaiseStoppedEvent()
{
IsStopped = true;
ServerStopped?.Invoke(this, EventArgs.Empty);
}
#region Updated event
/// <summary>
/// Occurs when the playback state is updated.
/// </summary>
/// <since_tizen> 4 </since_tizen>
public event EventHandler<PlaybackStateUpdatedEventArgs> 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.ToPublic(), (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);
}
}
/// <summary>
/// Occurs when the playlist is updated.
/// </summary>
/// <since_tizen> 5 </since_tizen>
public event EventHandler<PlaylistUpdatedEventArgs> PlaylistUpdated;
internal void RaisePlaylistUpdatedEvent(MediaControlPlaylistMode mode, string name, IntPtr playlistHandle)
{
PlaylistUpdated?.Invoke(this, new PlaylistUpdatedEventArgs(mode, name, new MediaControlPlaylist(playlistHandle)));
}
/// <summary>
/// Occurs when the metadata is updated.
/// </summary>
/// <since_tizen> 4 </since_tizen>
public event EventHandler<MetadataUpdatedEventArgs> 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);
}
}
/// <summary>
/// Occurs when the shuffle mode is updated.
/// </summary>
/// <since_tizen> 4 </since_tizen>
public event EventHandler<ShuffleModeUpdatedEventArgs> ShuffleModeUpdated;
internal void RaiseShuffleModeUpdatedEvent(MediaControllerNativeShuffleMode mode)
{
ShuffleModeUpdated?.Invoke(this, new ShuffleModeUpdatedEventArgs(mode == MediaControllerNativeShuffleMode.On));
}
/// <summary>
/// Occurs when the repeat mode is updated.
/// </summary>
/// <since_tizen> 4 </since_tizen>
public event EventHandler<RepeatModeUpdatedEventArgs> RepeatModeUpdated;
internal void RaiseRepeatModeUpdatedEvent(MediaControlRepeatMode mode)
{
RepeatModeUpdated?.Invoke(this, new RepeatModeUpdatedEventArgs(mode));
}
/// <summary>
/// Occurs when the subtitle mode is updated.
/// </summary>
/// <since_tizen> 6 </since_tizen>
public event EventHandler<SubtitleModeUpdatedEventArgs> SubtitleModeUpdated;
internal void RaiseSubtitleModeUpdatedEvent(bool isEnabled)
{
SubtitleModeUpdated?.Invoke(this, new SubtitleModeUpdatedEventArgs(isEnabled));
}
/// <summary>
/// Occurs when the 360 mode is updated.
/// </summary>
/// <since_tizen> 6 </since_tizen>
public event EventHandler<Mode360UpdatedEventArgs> Mode360Updated;
internal void RaiseMode360UpdatedEvent(bool isEnabled)
{
Mode360Updated?.Invoke(this, new Mode360UpdatedEventArgs(isEnabled));
}
/// <summary>
/// Occurs when the display mode is updated.
/// </summary>
/// <since_tizen> 6 </since_tizen>
public event EventHandler<DisplayModeUpdatedEventArgs> DisplayModeUpdated;
internal void RaiseDisplayModeUpdatedEvent(MediaControlNativeDisplayMode mode)
{
DisplayModeUpdated?.Invoke(this, new DisplayModeUpdatedEventArgs(mode.ToPublic()));
}
/// <summary>
/// Occurs when the display rotation is updated.
/// </summary>
/// <since_tizen> 6 </since_tizen>
public event EventHandler<DisplayRotationUpdatedEventArgs> DisplayRotationUpdated;
internal void RaiseDisplayRotationUpdatedEvent(MediaControlNativeDisplayRotation rotation)
{
DisplayRotationUpdated?.Invoke(this, new DisplayRotationUpdatedEventArgs(rotation.ToPublic()));
}
#endregion
#region Capability updated event
/// <summary>
/// Occurs when the playback capabilities are updated.
/// </summary>
/// <since_tizen> 5 </since_tizen>
public event EventHandler<PlaybackCapabilityUpdatedEventArgs> PlaybackCapabilityUpdated;
private PlaybackCapabilityUpdatedEventArgs CreatePlaybackCapabilityUpdatedEventArgs(IntPtr playbackCapaHandle)
{
var capabilities = new Dictionary<MediaControlPlaybackCommand, MediaControlCapabilitySupport>();
try
{
foreach (MediaControllerNativePlaybackAction action in Enum.GetValues(typeof(MediaControllerNativePlaybackAction)))
{
Native.GetPlaybackCapability(playbackCapaHandle, action, out MediaControlCapabilitySupport support);
capabilities.Add(action.ToPublic(), support);
}
return new PlaybackCapabilityUpdatedEventArgs(capabilities);
}
catch (Exception e)
{
Log.Error(GetType().FullName, e.ToString());
}
return null;
}
internal void RaisePlaybackCapabilityUpdatedEvent(IntPtr playbackCapaHandle)
{
var eventHandler = PlaybackCapabilityUpdated;
if (eventHandler == null)
{
return;
}
var args = CreatePlaybackCapabilityUpdatedEventArgs(playbackCapaHandle);
if (args != null)
{
eventHandler.Invoke(this, args);
}
}
/// <summary>
/// Occurs when the repeat mode capability is updated.
/// </summary>
/// <since_tizen> 5 </since_tizen>
public event EventHandler<RepeatModeCapabilityUpdatedEventArgs> RepeatModeCapabilityUpdated;
internal void RaiseRepeatModeCapabilityUpdatedEvent(MediaControlCapabilitySupport support)
{
RepeatModeCapabilityUpdated?.Invoke(this, new RepeatModeCapabilityUpdatedEventArgs(support));
}
/// <summary>
/// Occurs when the shuffle mode capability is updated.
/// </summary>
/// <since_tizen> 5 </since_tizen>
public event EventHandler<ShuffleModeCapabilityUpdatedEventArgs> ShuffleModeCapabilityUpdated;
internal void RaiseShuffleModeCapabilityUpdatedEvent(MediaControlCapabilitySupport support)
{
ShuffleModeCapabilityUpdated?.Invoke(this, new ShuffleModeCapabilityUpdatedEventArgs(support));
}
/// <summary>
/// Occurs when the playback position capability is updated.
/// </summary>
/// <since_tizen> 11 </since_tizen>
public event EventHandler<PlaybackPositionCapabilityUpdatedEventArgs> PlaybackPositionCapabilityUpdated;
internal void RaisePlaybackPositionCapabilityUpdatedEvent(MediaControlCapabilitySupport support)
{
PlaybackPositionCapabilityUpdated?.Invoke(this, new PlaybackPositionCapabilityUpdatedEventArgs(support));
}
/// <summary>
/// Occurs when the playlist capability is updated.
/// </summary>
/// <since_tizen> 11 </since_tizen>
public event EventHandler<PlaylistCapabilityUpdatedEventArgs> PlaylistCapabilityUpdated;
internal void RaisePlaylistCapabilityUpdatedEvent(MediaControlCapabilitySupport support)
{
PlaylistCapabilityUpdated?.Invoke(this, new PlaylistCapabilityUpdatedEventArgs(support));
}
/// <summary>
/// Occurs when the custom command capability is updated.
/// </summary>
/// <since_tizen> 11 </since_tizen>
public event EventHandler<CustomCommandCapabilityUpdatedEventArgs> CustomCommandCapabilityUpdated;
internal void RaiseCustomCommandCapabilityUpdatedEvent(MediaControlCapabilitySupport support)
{
CustomCommandCapabilityUpdated?.Invoke(this, new CustomCommandCapabilityUpdatedEventArgs(support));
}
/// <summary>
/// Occurs when the search capability is updated.
/// </summary>
/// <since_tizen> 11 </since_tizen>
public event EventHandler<SearchCapabilityUpdatedEventArgs> SearchCapabilityUpdated;
internal void RaiseSearchCapabilityUpdatedEvent(MediaControlCapabilitySupport support)
{
SearchCapabilityUpdated?.Invoke(this, new SearchCapabilityUpdatedEventArgs(support));
}
/// <summary>
/// Occurs when the subtitle capability is updated.
/// </summary>
/// <since_tizen> 11 </since_tizen>
public event EventHandler<SubtitleCapabilityUpdatedEventArgs> SubtitleCapabilityUpdated;
internal void RaiseSubtitleCapabilityUpdatedEvent(MediaControlCapabilitySupport support)
{
SubtitleCapabilityUpdated?.Invoke(this, new SubtitleCapabilityUpdatedEventArgs(support));
}
/// <summary>
/// Occurs when the mode360 capability is updated.
/// </summary>
/// <since_tizen> 11 </since_tizen>
public event EventHandler<Mode360CapabilityUpdatedEventArgs> Mode360CapabilityUpdated;
internal void RaiseMode360CapabilityUpdatedEvent(MediaControlCapabilitySupport support)
{
Mode360CapabilityUpdated?.Invoke(this, new Mode360CapabilityUpdatedEventArgs(support));
}
/// <summary>
/// Occurs when the display mode capability is updated.
/// </summary>
/// <since_tizen> 6 </since_tizen>
public event EventHandler<DisplayModeCapabilityUpdatedEventArgs> DisplayModeCapabilityUpdated;
internal void RaiseDisplayModeCapabilityUpdatedEvent(MediaControlNativeDisplayMode modes)
{
DisplayModeCapabilityUpdated?.Invoke(this, new DisplayModeCapabilityUpdatedEventArgs(modes.ToPublicList()));
}
/// <summary>
/// Occurs when the display rotation capability is updated.
/// </summary>
/// <since_tizen> 6 </since_tizen>
public event EventHandler<DisplayRotationCapabilityUpdatedEventArgs> DisplayRotationCapabilityUpdated;
internal void RaiseDisplayRotationCapabilityUpdatedEvent(MediaControlNativeDisplayRotation rotations)
{
DisplayRotationCapabilityUpdated?.Invoke(this, new DisplayRotationCapabilityUpdatedEventArgs(rotations.ToPublicList()));
}
#endregion
#region Command
/// <summary>
/// Occurs when the command is completed.
/// </summary>
/// <remarks>
/// User can match the command and this event using <see cref="CommandCompletedEventArgs.RequestId"/> field.
/// </remarks>
/// <since_tizen> 5 </since_tizen>
internal event EventHandler<CommandCompletedEventArgs> CommandCompleted;
internal void RaiseCommandCompletedEvent(string requestId, int result, IntPtr bundleHandle)
{
if (bundleHandle != IntPtr.Zero)
{
CommandCompleted?.Invoke(this, new CommandCompletedEventArgs(requestId, result, new Bundle(new SafeBundleHandle(bundleHandle, true))));
}
else
{
CommandCompleted?.Invoke(this, new CommandCompletedEventArgs(requestId, result));
}
}
/// <summary>
/// Occurs when a server sends custom event.
/// </summary>
/// <since_tizen> 5 </since_tizen>
public event EventHandler<CustomCommandReceivedEventArgs> CustomCommandReceived;
internal void RaiseCustomCommandReceivedEvent(CustomCommand command)
{
CustomCommandReceived?.Invoke(this, new CustomCommandReceivedEventArgs(command));
}
#endregion
}
}