예제 #1
0
        // Gets the playlist handle by name.
        internal static IntPtr GetPlaylistHandle(string name)
        {
            Native.GetPlaylistHandle(Handle, name, out IntPtr playlistHandle)
            .ThrowIfError("Failed to get playlist handle by name");

            return(playlistHandle);
        }
예제 #2
0
        private static void Initialize()
        {
            Native.Create(out _handle).ThrowIfError("Failed to create media controller server.");

            try
            {
                RegisterPlaybackCommandReceivedEvent();
                RegisterPlaybackActionCommandReceivedEvent();
                RegisterPlaybackPositionCommandReceivedEvent();
                RegisterPlaylistCommandReceivedEvent();
                RegisterShuffleModeCommandReceivedEvent();
                RegisterRepeatModeCommandReceivedEvent();
                RegisterCustomCommandReceivedEvent();
                RegisterCommandCompletedEvent();
                RegisterSearchCommandReceivedEvent();

                _isRunning = true;
            }
            catch
            {
                Native.Destroy(_handle);
                _playbackCommandCallback = null;
                _handle = IntPtr.Zero;
                throw;
            }
        }
예제 #3
0
        /// <summary>
        /// Sets the <see cref="MediaControlCapabilitySupport"/> indicating whether subtitle mode is supported or not.
        /// </summary>
        /// <param name="support">A value indicating whether the subtitle mode is supported or not.</param>
        /// <exception cref="InvalidOperationException">
        ///     The server is not running .<br/>
        ///     -or-<br/>
        ///     An internal error occurs.
        /// </exception>
        /// <exception cref="ArgumentException"><paramref name="support"/> is invalid.</exception>
        /// <since_tizen> 6 </since_tizen>
        public static void SetSubtitleModeCapability(MediaControlCapabilitySupport support)
        {
            ValidationUtil.ValidateEnum(typeof(MediaControlCapabilitySupport), support, nameof(support));

            Native.SetSimpleCapability(Handle, MediaControlNativeCapabilityCategory.Subtitle, support).
            ThrowIfError("Failed to set subtitle mode capability.");
        }
예제 #4
0
        private static void Initialize()
        {
            Native.Create(out _handle).ThrowIfError("Failed to create media controller server.");

            try
            {
                RegisterPlaybackActionCommandReceivedEvent();
                RegisterPlaybackPositionCommandReceivedEvent();
                RegisterPlaylistCommandReceivedEvent();
                RegisterShuffleModeCommandReceivedEvent();
                RegisterRepeatModeCommandReceivedEvent();
                RegisterSubtitleModeCommandReceivedEvent();
                RegisterMode360CommandReceivedEvent();
                RegisterDisplayModeCommandReceivedEvent();
                RegisterDisplayRotationCommandReceivedEvent();
                RegisterCustomCommandReceivedEvent();
                RegisterCommandCompletedEvent();
                RegisterSearchCommandReceivedEvent();

                _serverName = Application.Current.ApplicationInfo.ApplicationId;
                _isRunning  = true;
            }
            catch
            {
                Native.Destroy(_handle);
                _handle     = IntPtr.Zero;
                _serverName = null;
                throw;
            }
        }
예제 #5
0
 private static void SetMetadata(MediaControllerNativeAttribute attribute, string value)
 {
     if (value != null)
     {
         Native.SetMetadata(Handle, attribute, value).ThrowIfError($"Failed to set metadata({attribute}).");
     }
 }
예제 #6
0
        /// <summary>
        /// Sets the content type of latest played media.
        /// </summary>
        /// <param name="type">A value indicating the content type of the latest played media.</param>
        /// <exception cref="InvalidOperationException">
        ///     The server is not running .<br/>
        ///     -or-<br/>
        ///     An internal error occurs.
        /// </exception>
        /// <exception cref="ArgumentException"><paramref name="type"/> is invalid.</exception>
        /// <since_tizen> 5 </since_tizen>
        public static void SetPlaybackContentType(MediaControlContentType type)
        {
            ValidationUtil.ValidateEnum(typeof(MediaControlContentType), type, nameof(type));

            Native.SetPlaybackContentType(Handle, type).ThrowIfError("Failed to set playback content type.");

            Native.UpdatePlayback(Handle).ThrowIfError("Failed to set playback.");
        }
예제 #7
0
        /// <summary>
        /// Sets the capabilities by <see cref="MediaControlPlaybackCommand"/>.
        /// </summary>
        /// <param name="action">A playback command.</param>
        /// <param name="support">A value indicating whether the <paramref name="action"/> is supported or not.</param>
        /// <exception cref="InvalidOperationException">
        ///     The server is not running .<br/>
        ///     -or-<br/>
        ///     An internal error occurs.
        /// </exception>
        /// <exception cref="ArgumentException"><paramref name="action"/> or <paramref name="support"/> is invalid.</exception>
        /// <since_tizen> 5 </since_tizen>
        public static void SetPlaybackCapability(MediaControlPlaybackCommand action, MediaControlCapabilitySupport support)
        {
            ValidationUtil.ValidateEnum(typeof(MediaControlPlaybackCommand), action, nameof(action));
            ValidationUtil.ValidateEnum(typeof(MediaControlCapabilitySupport), support, nameof(support));

            Native.SetPlaybackCapability(Handle, action.ToNative(), support).ThrowIfError("Failed to set playback capability.");

            Native.SaveAndNotifyPlaybackCapabilityUpdated(Handle).ThrowIfError("Failed to update playback capability.");
        }
예제 #8
0
        /// <summary>
        /// Stops the media control server.
        /// </summary>
        /// <remarks>
        /// When the server stops, <see cref="MediaControllerManager.ServerStopped"/> will be raised.
        /// </remarks>
        /// <exception cref="InvalidOperationException">
        ///     The server is not running .<br/>
        ///     -or-<br/>
        ///     An internal error occurs.
        /// </exception>
        /// <seealso cref="MediaControllerManager.ServerStopped"/>
        /// <since_tizen> 4 </since_tizen>
        public static void Stop()
        {
            EnsureInitializedIfRunning();

            Native.Destroy(_handle).ThrowIfError("Failed to stop the server.");

            _handle    = IntPtr.Zero;
            _isRunning = false;
        }
예제 #9
0
 private static void RegisterPlaybackCommandReceivedEvent()
 {
     _playbackCommandCallback = (clientName, playbackCode, _) =>
     {
         PlaybackCommandReceived?.Invoke(null, new PlaybackCommandReceivedEventArgs(clientName, playbackCode.ToPublic()));
     };
     Native.SetPlaybackStateCommandReceivedCb(Handle, _playbackCommandCallback).
     ThrowIfError("Failed to init PlaybackStateCommandReceived event.");
 }
예제 #10
0
        /// <summary>
        /// Sets the path of icon.
        /// </summary>
        /// <param name="path">The path of icon.</param>
        /// <exception cref="InvalidOperationException">
        ///     The server is not running .<br/>
        ///     -or-<br/>
        ///     An internal error occurs.
        /// </exception>
        /// <exception cref="ArgumentNullException"><paramref name="path"/> is invalid.</exception>
        /// <since_tizen> 5 </since_tizen>
        public static void SetIconPath(string path)
        {
            if (path == null)
            {
                throw new ArgumentNullException(nameof(path));
            }

            Native.SetIconPath(Handle, path).ThrowIfError("Failed to set uri path.");
        }
예제 #11
0
        /// <summary>
        /// Delete playlist.
        /// </summary>
        /// <remarks>Currently, only server can remove the playlist.</remarks>
        /// <param name="playlist">The name of playlist.</param>
        /// <exception cref="ArgumentNullException"><paramref name="playlist"/> is null.</exception>
        /// <exception cref="InvalidOperationException">
        ///     The server is not running .<br/>
        ///     -or-<br/>
        ///     An internal error occurs.
        /// </exception>
        /// <since_tizen> 5 </since_tizen>
        public static void RemovePlaylist(MediaControlPlaylist playlist)
        {
            if (playlist == null)
            {
                throw new ArgumentNullException(nameof(playlist));
            }

            Native.DeletePlaylist(Handle, playlist.Handle);
            playlist.Dispose();
        }
예제 #12
0
        /// <summary>
        /// Sets the age rating of latest played media.
        /// </summary>
        /// <param name="ageRating">
        /// The Age rating of latest played media. The valid range is 0 to 19, inclusive.
        /// Especially, 0 means that media is suitable for all ages.
        /// </param>
        /// <exception cref="ArgumentOutOfRangeException">The specified <paramref name="ageRating"/> is not valid.</exception>
        /// <exception cref="InvalidOperationException">
        ///     The server is not running .<br/>
        ///     -or-<br/>
        ///     An internal error occurs.
        /// </exception>
        /// <since_tizen> 5 </since_tizen>
        public static void SetAgeRating(int ageRating)
        {
            if (ageRating < 0 || ageRating > 19)
            {
                throw new ArgumentOutOfRangeException(nameof(ageRating));
            }

            Native.SetAgeRating(Handle, ageRating).ThrowIfError("Failed to set age rating.");

            Native.UpdatePlayback(Handle).ThrowIfError("Failed to set playback.");
        }
예제 #13
0
        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.");
        }
예제 #14
0
        public static void SetIndexOfCurrentPlayingMedia(string index)
        {
            if (index == null)
            {
                throw new ArgumentNullException(nameof(index));
            }

            Native.SetIndexOfCurrentPlayingMedia(Handle, index)
            .ThrowIfError("Failed to set the index of current playing media");

            Native.UpdatePlayback(Handle).ThrowIfError("Failed to set playback.");
        }
        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 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.");
        }
예제 #17
0
        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.");
        }
예제 #18
0
        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.");
        }
예제 #19
0
        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.");
        }
예제 #20
0
        /// <summary>
        /// Sets the <paramref name="rotation"/> is supported or not.
        /// </summary>
        /// <remarks>
        /// <see cref="MediaControlCapabilitySupport.NotDecided"/> is not allowed in display rotation capability.<br/>
        /// The default value of each <see cref="Rotation"/> is not supported.
        /// </remarks>
        /// <param name="rotation">The <see cref="Rotation"/>.</param>
        /// <param name="support">A value indicating whether the <paramref name="rotation"/> is supported or not..</param>
        /// <exception cref="InvalidOperationException">
        ///     The server is not running .<br/>
        ///     -or-<br/>
        ///     An internal error occurs.
        /// </exception>
        /// <exception cref="ArgumentException"><paramref name="rotation"/> or <paramref name="support"/> is invalid.</exception>
        /// <since_tizen> 6 </since_tizen>
        public static void SetDisplayRotationCapability(Rotation rotation, MediaControlCapabilitySupport support)
        {
            ValidationUtil.ValidateEnum(typeof(Rotation), rotation, nameof(rotation));
            ValidationUtil.ValidateEnum(typeof(MediaControlCapabilitySupport), support, nameof(support));

            if (support == MediaControlCapabilitySupport.NotDecided)
            {
                throw new ArgumentException($"NotDecided is not allowed in {rotation} capability.");
            }

            Native.SetDisplayRotationCapability(Handle, (uint)rotation.ToNative(), support).
            ThrowIfError("Failed to set display rotation capability.");
        }
예제 #21
0
        /// <summary>
        /// Sets the <paramref name="mode"/> is supported or not.
        /// </summary>
        /// <remarks>
        /// <see cref="MediaControlCapabilitySupport.NotDecided"/> is not allowed in display mode capability.<br/>
        /// The default value of each <see cref="MediaControlDisplayMode"/> is not supported.
        /// </remarks>
        /// <param name="mode">The <see cref="MediaControlDisplayMode"/>.</param>
        /// <param name="support">A value indicating whether the <paramref name="mode"/> is supported or not.</param>
        /// <exception cref="InvalidOperationException">
        ///     The server is not running .<br/>
        ///     -or-<br/>
        ///     An internal error occurs.
        /// </exception>
        /// <exception cref="ArgumentException"><paramref name="mode"/> or <paramref name="support"/> is invalid.</exception>
        /// <since_tizen> 6 </since_tizen>
        public static void SetDisplayModeCapability(MediaControlDisplayMode mode, MediaControlCapabilitySupport support)
        {
            ValidationUtil.ValidateEnum(typeof(MediaControlDisplayMode), mode, nameof(mode));
            ValidationUtil.ValidateEnum(typeof(MediaControlCapabilitySupport), support, nameof(support));

            if (support == MediaControlCapabilitySupport.NotDecided)
            {
                throw new ArgumentException($"NotDecided is not allowed in {mode} capability.");
            }

            Native.SetDisplayModeCapability(Handle, (uint)mode.ToNative(), support).
            ThrowIfError("Failed to set display mode capability.");
        }
예제 #22
0
        /// <summary>
        /// Sets the capabilities by <see cref="MediaControlPlaybackCommand"/>.
        /// </summary>
        /// <param name="capabilities">The set of <see cref="MediaControlPlaybackCommand"/> and <see cref="MediaControlCapabilitySupport"/>.</param>
        /// <exception cref="InvalidOperationException">
        ///     The server is not running .<br/>
        ///     -or-<br/>
        ///     An internal error occurs.
        /// </exception>
        /// <exception cref="ArgumentException"><paramref name="capabilities"/> is invalid.</exception>
        /// <since_tizen> 5 </since_tizen>
        public static void SetPlaybackCapabilities(Dictionary <MediaControlPlaybackCommand, MediaControlCapabilitySupport> capabilities)
        {
            foreach (var pair in capabilities)
            {
                ValidationUtil.ValidateEnum(typeof(MediaControlPlaybackCommand), pair.Key, nameof(pair.Key));
                ValidationUtil.ValidateEnum(typeof(MediaControlCapabilitySupport), pair.Value, nameof(pair.Value));

                SetPlaybackCapability(pair.Key, pair.Value);
                Native.SetPlaybackCapability(Handle, pair.Key.ToNative(), pair.Value).
                ThrowIfError("Failed to set playback capability.");
            }

            Native.SaveAndNotifyPlaybackCapabilityUpdated(Handle).ThrowIfError("Failed to update playback capability.");
        }
예제 #23
0
        /// <summary>
        /// Gets the active clients.
        /// </summary>
        /// <exception cref="InvalidOperationException">
        ///     The server is not running .<br/>
        ///     -or-<br/>
        ///     An internal error occurs.
        /// </exception>
        /// <returns>the activated client ids.</returns>
        /// <since_tizen> 5 </since_tizen>
        public static IEnumerable <string> GetActivatedClients()
        {
            var clientIds = new List <string>();

            Native.ActivatedClientCallback activatedClientCallback = (name, _) =>
            {
                clientIds.Add(name);
                return(true);
            };

            Native.ForeachActivatedClient(Handle, activatedClientCallback).
            ThrowIfError("Failed to get activated client.");

            return(clientIds.AsReadOnly());
        }
예제 #24
0
        /// <summary>
        /// Updates playback state and playback position.</summary>
        /// <param name="state">The playback state.</param>
        /// <param name="position">The playback position in milliseconds.</param>
        /// <exception cref="ArgumentException"><paramref name="state"/> is not valid.</exception>
        /// <exception cref="ArgumentOutOfRangeException"><paramref name="position"/> is less than zero.</exception>
        /// <exception cref="InvalidOperationException">
        ///     The server is not running .<br/>
        ///     -or-<br/>
        ///     An internal error occurs.
        /// </exception>
        /// <since_tizen> 4 </since_tizen>
        public static void SetPlaybackState(MediaControlPlaybackState state, long position)
        {
            ValidationUtil.ValidateEnum(typeof(MediaControlPlaybackState), state, nameof(state));

            if (position < 0)
            {
                throw new ArgumentOutOfRangeException(nameof(position), position, "position can't be less than zero.");
            }

            Native.SetPlaybackState(Handle, state.ToNative()).ThrowIfError("Failed to set playback state.");

            Native.SetPlaybackPosition(Handle, (ulong)position).ThrowIfError("Failed to set playback position.");

            Native.UpdatePlayback(Handle).ThrowIfError("Failed to set playback.");
        }
예제 #25
0
 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.");
 }
예제 #26
0
        private static void Initialize()
        {
            Native.Create(out _handle).ThrowIfError("Failed to create media controller server.");

            try
            {
                RegisterPlaybackCommandReceivedEvent();
                _isRunning = true;
            }
            catch
            {
                Native.Destroy(_handle);
                _playbackCommandCallback = null;
                _handle = IntPtr.Zero;
                throw;
            }
        }
예제 #27
0
        internal override string Request(IntPtr serverHandle)
        {
            string requestId = null;

            if (Bundle != null)
            {
                NativeServer.SendCustomEventBundle(serverHandle, ReceiverId, Action, Bundle.SafeBundleHandle, out requestId)
                .ThrowIfError("Failed to send costom event.");
            }
            else
            {
                NativeServer.SendCustomEvent(serverHandle, ReceiverId, Action, IntPtr.Zero, out requestId)
                .ThrowIfError("Failed to send costom event.");
            }

            return(requestId);
        }
예제 #28
0
        private static void RegisterPlaybackActionCommandReceivedEvent()
        {
            _playbackActionCommandCallback = (clientName, requestId, playbackCommand, _) =>
            {
                // SendPlaybackCommand doesn't use requestId. It'll be removed in Level 7.
                if (requestId == null)
                {
                    PlaybackCommandReceived?.Invoke(null, new PlaybackCommandReceivedEventArgs(clientName, playbackCommand.ToPublic()));
                }
                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.");
        }
예제 #29
0
        private static bool GetRunningState()
        {
            IntPtr handle = IntPtr.Zero;

            try
            {
                Native.ConnectDb(out handle).ThrowIfError("Failed to retrieve the running state.");

                Native.CheckServerExist(handle, Applications.Application.Current.ApplicationInfo.ApplicationId,
                                        out var value).ThrowIfError("Failed to retrieve the running state.");

                return(value);
            }
            finally
            {
                if (handle != IntPtr.Zero)
                {
                    Native.DisconnectDb(handle);
                }
            }
        }
예제 #30
0
        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.");
        }