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.
18 using Tizen.Applications;
19 using Native = Interop.MediaControllerClient;
21 namespace Tizen.Multimedia.Remoting
24 /// Provides a means to to send commands to and handle events from media control server.
26 /// <since_tizen> 4 </since_tizen>
27 public partial class MediaController
30 /// Occurs when the server is stopped.
32 /// <since_tizen> 4 </since_tizen>
33 public event EventHandler ServerStopped;
35 internal void RaiseStoppedEvent()
38 ServerStopped?.Invoke(this, EventArgs.Empty);
42 /// Occurs when the playback state is updated.
44 /// <since_tizen> 4 </since_tizen>
45 public event EventHandler<PlaybackStateUpdatedEventArgs> PlaybackStateUpdated;
47 private PlaybackStateUpdatedEventArgs CreatePlaybackUpdatedEventArgs(IntPtr playbackHandle)
51 Native.GetPlaybackState(playbackHandle, out var playbackCode).ThrowIfError("Failed to get state.");
53 Native.GetPlaybackPosition(playbackHandle, out var position).ThrowIfError("Failed to get position.");
55 return new PlaybackStateUpdatedEventArgs(playbackCode.ToPublic(), (long)position);
59 Log.Error(GetType().FullName, e.ToString());
64 internal void RaisePlaybackUpdatedEvent(IntPtr playbackHandle)
66 var eventHandler = PlaybackStateUpdated;
68 if (eventHandler == null)
73 var args = CreatePlaybackUpdatedEventArgs(playbackHandle);
77 eventHandler.Invoke(this, args);
82 /// Occurs when the metadata is updated.
84 /// <since_tizen> 4 </since_tizen>
85 public event EventHandler<MetadataUpdatedEventArgs> MetadataUpdated;
87 private MetadataUpdatedEventArgs CreateMetadataUpdatedEventArgs(IntPtr metadataHandle)
91 return new MetadataUpdatedEventArgs(new MediaControlMetadata(metadataHandle));
95 Log.Error(GetType().FullName, e.ToString());
100 internal void RaiseMetadataUpdatedEvent(IntPtr metadataHandle)
102 var eventHandler = MetadataUpdated;
104 if (eventHandler == null)
109 var args = CreateMetadataUpdatedEventArgs(metadataHandle);
113 eventHandler.Invoke(this, args);
118 /// Occurs when the shuffle mode is updated.
120 /// <since_tizen> 4 </since_tizen>
121 public event EventHandler<ShuffleModeUpdatedEventArgs> ShuffleModeUpdated;
123 internal void RaiseShuffleModeUpdatedEvent(MediaControllerNativeShuffleMode mode)
125 ShuffleModeUpdated?.Invoke(this, new ShuffleModeUpdatedEventArgs(mode == MediaControllerNativeShuffleMode.On));
129 /// Occurs when the repeat mode is updated.
131 /// <since_tizen> 4 </since_tizen>
132 public event EventHandler<RepeatModeUpdatedEventArgs> RepeatModeUpdated;
134 internal void RaiseRepeatModeUpdatedEvent(MediaControlRepeatMode mode)
136 RepeatModeUpdated?.Invoke(this, new RepeatModeUpdatedEventArgs(mode));
140 /// Occurs when the playlist is updated.
142 /// <since_tizen> 5 </since_tizen>
143 public event EventHandler<PlaylistUpdatedEventArgs> PlaylistUpdated;
145 internal void RaisePlaylistUpdatedEvent(MediaControlPlaylistMode mode, string name)
147 PlaylistUpdated?.Invoke(this, new PlaylistUpdatedEventArgs(mode, name));
151 /// Occurs when the command is completed.
154 /// User can match the command and this event using <see cref="CommandCompletedEventArgs.RequestId"/> field.
156 /// <since_tizen> 5 </since_tizen>
157 internal event EventHandler<CommandCompletedEventArgs> CommandCompleted;
159 internal void RaiseCommandCompletedEvent(string requestId, MediaControllerError result, IntPtr bundleHandle)
161 if (bundleHandle != IntPtr.Zero)
163 CommandCompleted?.Invoke(this, new CommandCompletedEventArgs(requestId, result, new Bundle(new SafeBundleHandle(bundleHandle, true))));
167 CommandCompleted?.Invoke(this, new CommandCompletedEventArgs(requestId, result));