private void RegisterShuffleModeUpdatedEvent() { _shufflemodeUpdatedCallback = (serverName, shuffleMode, _) => { GetController(serverName)?.RaiseShuffleModeUpdatedEvent(shuffleMode); }; Native.SetShuffleModeUpdatedCb(Handle, _shufflemodeUpdatedCallback). ThrowIfError("Failed to init ShuffleModeUpdated event."); }
private void RegisterPlaybackCapabilitiesEvent() { _playbackCapabilityUpdatedCallback = (serverName, playbackCapaHandle, _) => { GetController(serverName)?.RaisePlaybackCapabilityUpdatedEvent(playbackCapaHandle); }; Native.SetPlaybackCapabilityUpdatedCb(Handle, _playbackCapabilityUpdatedCallback). ThrowIfError("Failed to init PlaybackCapabilityUpdated event."); }
private void RegisterRepeatModeCapabilitiesEvent() { _repeatModeCapabilityUpdatedCallback = (serverName, support, _) => { GetController(serverName)?.RaiseRepeatModeCapabilityUpdatedEvent(support); }; Native.SetRepeatCapabilityUpdatedCb(Handle, _repeatModeCapabilityUpdatedCallback). ThrowIfError("Failed to init RepeatModeCapabilityUpdated event."); }
private void RegisterRepeatModeUpdatedEvent() { _repeatmodeUpdatedCallback = (serverName, repeatMode, _) => { GetController(serverName)?.RaiseRepeatModeUpdatedEvent(repeatMode.ToPublic()); }; Native.SetRepeatModeUpdatedCb(Handle, _repeatmodeUpdatedCallback). ThrowIfError("Failed to init RepeatModeUpdated event."); }
private void RegisterDisplayRotationUpdateEvent() { _displayRotationUpdatedCallback = (serverName, rotation, _) => { GetController(serverName)?.RaiseDisplayRotationUpdatedEvent(rotation); }; Native.SetDisplayRotationUpdatedCb(Handle, _displayRotationUpdatedCallback). ThrowIfError("Failed to register DisplayRotationUpdated event."); }
private void RegisterMode360UpdateEvent() { _mode360UpdatedCallback = (serverName, isEnabled, _) => { GetController(serverName)?.RaiseMode360UpdatedEvent(isEnabled); }; Native.SetMode360UpdatedCb(Handle, _mode360UpdatedCallback). ThrowIfError("Failed to register Mode360Updated event."); }
private void RegisterServerUpdatedEvent() { _serverUpdatedCallback = (serverName, state, _) => { RaiseServerChangedEvent(state, HandleServerUpdated(serverName, state)); }; Native.SetServerUpdatedCb(Handle, _serverUpdatedCallback). ThrowIfError("Failed to register server changed event."); }
private void RegisterDisplayModeCapabilityUpdatedEvent() { _displayModeCapabilityUpdatedCallback = (serverName, modes, _) => { GetController(serverName)?.RaiseDisplayModeCapabilityUpdatedEvent( (MediaControlNativeDisplayMode)modes); }; Native.SetDisplayModeCapabilityUpdatedCb(Handle, _displayModeCapabilityUpdatedCallback). ThrowIfError("Failed to register DisplayModeCapabilityUpdated event."); }
private void RegisterCommandCompletedEvent() { _commandCompletedCallback = (serverName, requestId, result, bundleHandle, _) => { // SafeHandles cannot be marshaled from unmanaged to managed. // So we use IntPtr type for 'bundleHandle' in native callback. GetController(serverName)?.RaiseCommandCompletedEvent(requestId, result, bundleHandle); }; Native.SetCommandCompletedCb(Handle, _commandCompletedCallback). ThrowIfError("Failed to register CommandCompleted event."); }
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 MediaControlMetadata(IntPtr handle) { Debug.Assert(handle != IntPtr.Zero); Title = Native.GetMetadata(handle, MediaControllerAttribute.Title); Artist = Native.GetMetadata(handle, MediaControllerAttribute.Artist); Album = Native.GetMetadata(handle, MediaControllerAttribute.Album); Author = Native.GetMetadata(handle, MediaControllerAttribute.Author); Genre = Native.GetMetadata(handle, MediaControllerAttribute.Genre); Duration = Native.GetMetadata(handle, MediaControllerAttribute.Duration); Date = Native.GetMetadata(handle, MediaControllerAttribute.Date); Copyright = Native.GetMetadata(handle, MediaControllerAttribute.Copyright); Description = Native.GetMetadata(handle, MediaControllerAttribute.Description); TrackNumber = Native.GetMetadata(handle, MediaControllerAttribute.TrackNumber); AlbumArtPath = Native.GetMetadata(handle, MediaControllerAttribute.Picture); }
internal override string Request(NativeClientHandle clientHandle) { string requestId = null; if (Bundle != null) { NativeClient.SendCustomCommandBundle(clientHandle, ReceiverId, Action, Bundle.SafeBundleHandle, out requestId). ThrowIfError("Failed to send custom command."); } else { NativeClient.SendCustomCommand(clientHandle, ReceiverId, Action, IntPtr.Zero, out requestId). ThrowIfError("Failed to send custom command."); } return(requestId); }
private void RegisterSimpleCapabilityUpdatedEvent() { _categoryCapabilityUpdatedCallback = (serverName, category, support, _) => { switch (category) { case MediaControlNativeCapabilityCategory.Repeat: GetController(serverName)?.RaiseRepeatModeCapabilityUpdatedEvent(support); break; case MediaControlNativeCapabilityCategory.Shuffle: GetController(serverName)?.RaiseShuffleModeCapabilityUpdatedEvent(support); break; } }; Native.SetCategoryCapabilityUpdatedCb(Handle, _categoryCapabilityUpdatedCallback). ThrowIfError("Failed to register capability updated event."); }
/// <summary> /// Initializes a new instance of the <see cref="SearchCommand"/> class. /// </summary> /// <remarks>User can search maximum 20 items once.</remarks> /// <exception cref="ArgumentNullException"><paramref name="conditions"/> is not set.</exception> /// <exception cref="ArgumentException"> /// <paramref name="conditions.Count"/> is greater than maximum value(20).<br/> /// -or-<br/> /// <paramref name="conditions.Count"/> is less than 1. /// </exception> /// <exception cref="InvalidOperationException">An internal error occurs.</exception> /// <param name="conditions">The set of <see cref="MediaControlSearchCondition"/>.</param> /// <since_tizen> 5 </since_tizen> public SearchCommand(List <MediaControlSearchCondition> conditions) { if (conditions == null) { throw new ArgumentNullException(nameof(conditions)); } if (conditions.Count <= 0 || conditions.Count > 20) { var errMessage = $"Invalid number of search conditions. : {conditions.Count}. " + $"Valid range is 1 ~ 20."; throw new ArgumentException(errMessage); } NativeClient.CreateSearchHandle(out _searchHandle).ThrowIfError("Failed to create search handle."); try { foreach (var condition in conditions) { if (condition.Bundle != null) { NativeClient.SetSearchConditionBundle(_searchHandle, condition.ContentType, condition.Category, condition.Keyword, condition.Bundle.SafeBundleHandle). ThrowIfError("Failed to set search condition."); } else { NativeClient.SetSearchCondition(_searchHandle, condition.ContentType, condition.Category, condition.Keyword, IntPtr.Zero). ThrowIfError("Failed to set search condition."); } } } catch { if (_searchHandle != IntPtr.Zero) { NativeClient.DestroySearchHandle(_searchHandle).ThrowIfError("Failed to destroy search handle"); } throw; } }
private void LoadActivatedServers() { try { _lock.EnterWriteLock(); Native.ActivatedServerCallback serverCallback = (serverName, _) => { _activated.Add(serverName, new MediaController(this, serverName)); return(true); }; Native.ForeachActivatedServer(Handle, serverCallback, IntPtr.Zero). ThrowIfError("Failed to get activated servers."); } finally { _lock.ExitWriteLock(); } }
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); }
/// <summary> /// Returns the metadata set by the server. /// </summary> /// <returns>The metadata.</returns> /// <exception cref="InvalidOperationException"> /// The server has already been stopped.<br/> /// -or-<br/> /// An internal error occurs. /// </exception> /// <exception cref="ObjectDisposedException">The <see cref="MediaControllerManager"/> has already been disposed of.</exception> /// <seealso cref="MediaControlServer.SetMetadata(MediaControlMetadata)"/> /// <since_tizen> 4 </since_tizen> public MediaControlMetadata GetMetadata() { ThrowIfStopped(); IntPtr metadataHandle = IntPtr.Zero; try { Native.GetServerMetadata(Manager.Handle, ServerAppId, out metadataHandle). ThrowIfError("Failed to get metadata."); return(new MediaControlMetadata(metadataHandle)); } finally { if (metadataHandle != IntPtr.Zero) { Native.DestroyMetadata(metadataHandle); } } }
/// <summary> /// Returns the index of current playing media. /// </summary> /// <returns>The index of current playing media.</returns> /// <exception cref="InvalidOperationException"> /// The server has already been stopped.<br/> /// -or-<br/> /// An internal error occurs. /// </exception> /// <exception cref="ObjectDisposedException">The <see cref="MediaControllerManager"/> has already been disposed.</exception> /// <since_tizen> 5 </since_tizen> public string GetIndexOfCurrentPlayingMedia() { ThrowIfStopped(); IntPtr playbackHandle = IntPtr.Zero; try { Native.GetServerPlaybackHandle(Manager.Handle, ServerAppId, out playbackHandle).ThrowIfError("Failed to get playback."); var(name, index) = NativePlaylist.GetPlaylistInfo(playbackHandle); return(index); } finally { if (playbackHandle != IntPtr.Zero) { Native.DestroyPlayback(playbackHandle).ThrowIfError("Failed to destroy playback handle."); } } }
private void RegisterCustomCommandReceivedEvent() { _customCommandReceivedCallback = (serverName, requestId, customEvent, bundleHandle, _) => { CustomCommand command = null; if (bundleHandle != IntPtr.Zero) { command = new CustomCommand(customEvent, new Bundle(new SafeBundleHandle(bundleHandle, true))); } else { command = new CustomCommand(customEvent); } command.SetResponseInformation(serverName, requestId); GetController(serverName)?.RaiseCustomCommandReceivedEvent(command); }; Native.SetCustomEventCb(Handle, _customCommandReceivedCallback). ThrowIfError("Failed to register CustomCommandReceived event."); }
/// <summary> /// Returns the playback state set by the server. /// </summary> /// <returns>The playback state.</returns> /// <exception cref="InvalidOperationException"> /// The server has already been stopped.<br/> /// -or-<br/> /// An internal error occurs. /// </exception> /// <exception cref="ObjectDisposedException">The <see cref="MediaControllerManager"/> has already been disposed.</exception> /// <seealso cref="MediaControlServer.SetPlaybackState(MediaControlPlaybackState, long)"/> /// <since_tizen> 4 </since_tizen> public MediaControlPlaybackState GetPlaybackState() { ThrowIfStopped(); IntPtr playbackHandle = IntPtr.Zero; try { Native.GetServerPlaybackHandle(Manager.Handle, ServerAppId, out playbackHandle).ThrowIfError("Failed to get playback."); Native.GetPlaybackState(playbackHandle, out var playbackCode).ThrowIfError("Failed to get state."); return(playbackCode.ToPublic()); } finally { if (playbackHandle != IntPtr.Zero) { Native.DestroyPlayback(playbackHandle); } } }
/// <summary> /// Gets the age rating of current playing media. /// </summary> /// <returns>The Age rating of current playing media. The range is 0 to 19, inclusive.</returns> /// <exception cref="InvalidOperationException"> /// The server has already been stopped.<br/> /// -or-<br/> /// An internal error occurs. /// </exception> /// <exception cref="ObjectDisposedException">The <see cref="MediaControllerManager"/> has already been disposed.</exception> /// <since_tizen> 5 </since_tizen> public int GetAgeRatingOfCurrentPlayingMedia() { ThrowIfStopped(); IntPtr playbackHandle = IntPtr.Zero; try { Native.GetServerPlaybackHandle(Manager.Handle, ServerAppId, out playbackHandle).ThrowIfError("Failed to get playback."); Native.GetAgeRating(playbackHandle, out int ageRating).ThrowIfError("Failed to get age rating."); return(ageRating); } finally { if (playbackHandle != IntPtr.Zero) { Native.DestroyPlayback(playbackHandle); } } }
/// <summary> /// Returns the playback position set by the server. /// </summary> /// <returns>The playback position in milliseconds.</returns> /// <exception cref="InvalidOperationException"> /// The server has already been stopped.<br/> /// -or-<br/> /// An internal error occurs. /// </exception> /// <exception cref="ObjectDisposedException">The <see cref="MediaControllerManager"/> has already been disposed.</exception> /// <seealso cref="MediaControlServer.SetPlaybackState(MediaControlPlaybackState, long)"/> /// <since_tizen> 4 </since_tizen> public long GetPlaybackPosition() { ThrowIfStopped(); IntPtr playbackHandle = IntPtr.Zero; try { Native.GetServerPlaybackHandle(Manager.Handle, ServerAppId, out playbackHandle).ThrowIfError("Failed to get playback."); Native.GetPlaybackPosition(playbackHandle, out var position).ThrowIfError("Failed to get position."); return((long)position); } finally { if (playbackHandle != IntPtr.Zero) { Native.DestroyPlayback(playbackHandle); } } }
/// <summary> /// Gets the content type of current playing media. /// </summary> /// <returns>The <see cref="MediaControlContentType"/>.</returns> /// <exception cref="InvalidOperationException"> /// The server has already been stopped.<br/> /// -or-<br/> /// An internal error occurs. /// </exception> /// <exception cref="ObjectDisposedException">The <see cref="MediaControllerManager"/> has already been disposed.</exception> /// <since_tizen> 5 </since_tizen> public MediaControlContentType GetContentTypeOfCurrentPlayingMedia() { ThrowIfStopped(); IntPtr playbackHandle = IntPtr.Zero; try { Native.GetServerPlaybackHandle(Manager.Handle, ServerAppId, out playbackHandle).ThrowIfError("Failed to get playback."); Native.GetPlaybackContentType(playbackHandle, out MediaControlContentType type). ThrowIfError("Failed to get playback content type"); return(type); } finally { if (playbackHandle != IntPtr.Zero) { Native.DestroyPlayback(playbackHandle); } } }
/// <summary> /// Returns the playlist name of current playing media. /// </summary> /// <returns>The playlist name.</returns> /// <exception cref="InvalidOperationException"> /// The server has already been stopped.<br/> /// -or-<br/> /// An internal error occurs. /// </exception> /// <exception cref="ObjectDisposedException">The <see cref="MediaControllerManager"/> has already been disposed.</exception> /// <since_tizen> 5 </since_tizen> public MediaControlPlaylist GetPlaylistOfCurrentPlayingMedia() { ThrowIfStopped(); IntPtr playbackHandle = IntPtr.Zero; // Get the playlist name of current playing media. try { Native.GetServerPlaybackHandle(Manager.Handle, ServerAppId, out playbackHandle).ThrowIfError("Failed to get playback."); var(name, index) = NativePlaylist.GetPlaylistInfo(playbackHandle); return(GetPlaylists().FirstOrDefault(playlist => playlist.Name == name)); } finally { if (playbackHandle != IntPtr.Zero) { Native.DestroyPlayback(playbackHandle).ThrowIfError("Failed to destroy playback handle."); } } }
/// <summary> /// Gets the value whether the repeat mode is supported or not. /// </summary> /// <returns>A <see cref="MediaControlCapabilitySupport"/>.</returns> /// <exception cref="InvalidOperationException"> /// The server has already been stopped.<br/> /// -or-<br/> /// An internal error occurs. /// </exception> /// <exception cref="ObjectDisposedException">The <see cref="MediaControllerManager"/> has already been disposed of.</exception> /// <since_tizen> 5 </since_tizen> public MediaControlCapabilitySupport GetRepeatModeCapability() { ThrowIfStopped(); IntPtr playbackCapaHandle = IntPtr.Zero; try { Native.GetPlaybackCapabilityHandle(Manager.Handle, ServerAppId, out playbackCapaHandle). ThrowIfError("Failed to get playback capability handle."); Native.GetRepeatCapability(Manager.Handle, ServerAppId, out MediaControlCapabilitySupport support); return(support); } finally { if (playbackCapaHandle != IntPtr.Zero) { Native.DestroyCapability(playbackCapaHandle); } } }
/// <summary> /// Responses command to the server. /// </summary> /// <param name="clientHandle">The client handle.</param> /// <param name="result">The result of each command.</param> /// <param name="bundle">The extra data.</param> internal void Response(NativeClientHandle clientHandle, int result, Bundle bundle) { try { if (bundle != null) { NativeClient.SendCustomEventReplyBundle(clientHandle, ReceiverId, _requestId, result, bundle.SafeBundleHandle) .ThrowIfError("Failed to response event."); } else { NativeClient.SendCustomEventReply(clientHandle, ReceiverId, _requestId, result, IntPtr.Zero) .ThrowIfError("Failed to response event."); } } catch (ArgumentException) { throw new InvalidOperationException("Server is not running"); } finally { OnResponseCompleted(); } }