Esempio n. 1
0
 /// <summary>
 /// Initializes a new instance of the <see cref="MediaCommand" /> class.
 /// </summary>
 /// <param name="manager">The command manager.</param>
 /// <param name="commandType">Type of the command.</param>
 protected MediaCommand(MediaCommandManager manager, MediaCommandType commandType)
 {
     Manager       = manager;
     CommandType   = commandType;
     TaskCompleter = new TaskCompletionSource <bool>();
     Promise       = TaskCompleter.Task;
 }
Esempio n. 2
0
 /// <summary>
 /// Gets the pending count of the given command type.
 /// </summary>
 /// <param name="t">The t.</param>
 /// <returns>The amount of commands of the given type</returns>
 public int PendingCountOf(MediaCommandType t)
 {
     lock (SyncLock)
     {
         return(Commands.Count(c => c.CommandType == t));
     }
 }
Esempio n. 3
0
        /// <summary>
        /// Initializes a new instance of the <see cref="MediaCommand" /> class.
        /// </summary>
        /// <param name="manager">The command manager.</param>
        /// <param name="commandType">Type of the command.</param>
        protected MediaCommand(MediaCommandManager manager, MediaCommandType commandType)
        {
            Manager     = manager;
            CommandType = commandType;

            CancellableTask = new Task <Task>(ExecuteInternal, CancelTokenSource.Token);
            TaskContext     = CancellableTask.Unwrap();
        }
Esempio n. 4
0
 /// <summary>
 /// Initializes a new instance of the <see cref="MediaCommand" /> class.
 /// </summary>
 /// <param name="manager">The command manager.</param>
 /// <param name="commandType">Type of the command.</param>
 protected MediaCommand(MediaCommandManager manager, MediaCommandType commandType)
 {
     Manager     = manager;
     CommandType = commandType;
     TaskContext = new Task(ExecuteInternal, CancelTokenSource.Token);
 }
Esempio n. 5
0
        public MediaCommand(MusicService musicService, MediaCommandType type)
        {
            musicService.MediaPlaybackList.ItemFailed += OnMediaPlaybackListItemFailed;
            switch (type)
            {
            case MediaCommandType.PlayAndPause:
                ExecuteAction = async(object obj) =>
                {
                    if (IsMediaPlayingFailed)
                    {
                        await ShowPlayingErrorDialog();

                        return;
                    }
                    musicService.PlayPauseMusic();
                };
                break;

            case MediaCommandType.Next:
                ExecuteAction = (object obj) => musicService.NextMusic();
                break;

            case MediaCommandType.Previous:
                ExecuteAction = (object obj) => musicService.PreviousMusic();
                break;

            case MediaCommandType.Stop:
                ExecuteAction = (object obj) => musicService.StopMusic();
                break;

            case MediaCommandType.Repeat:
                ExecuteAction = (object obj) =>
                {
                    bool?parameter = false;
                    switch (obj as bool?)
                    {
                    case true:
                        parameter = false;
                        break;

                    case false:
                        parameter = true;
                        break;

                    case null:
                        parameter = null;
                        break;

                    default:
                        break;
                    }
                    musicService.RepeatMusic(parameter);
                };
                break;

            case MediaCommandType.Shuffle:
                ExecuteAction = (object obj) => musicService.ShuffleMusic();
                break;

            case MediaCommandType.Mute:
                ExecuteAction = (object obj) => musicService.MediaPlayer.IsMuted = musicService.MediaPlayer.IsMuted == false;
                break;

            case MediaCommandType.ChangePlayRate:
                ExecuteAction = (object obj) =>
                {
                    double rate;
                    switch (obj as string)
                    {
                    case "0.5x":
                        rate = 0.5;
                        break;

                    case "1x":
                        rate = 1;
                        break;

                    case "1.5x":
                        rate = 1.5;
                        break;

                    case "2x":
                        rate = 2;
                        break;

                    default:
                        rate = 1;
                        break;
                    }
                    musicService.SetMediaPlayerPlayRate(rate);
                };
                break;

            default:
                break;
            }
        }
Esempio n. 6
0
 /// <summary>
 /// Initializes a new instance of the <see cref="MediaCommand" /> class.
 /// </summary>
 /// <param name="manager">The command manager.</param>
 /// <param name="commandType">Type of the command.</param>
 protected MediaCommand(MediaCommandManager manager, MediaCommandType commandType)
 {
     Manager     = manager;
     CommandType = commandType;
     Promise     = new Task(Execute);
 }
Esempio n. 7
0
 /// <summary>
 /// Initializes a new instance of the <see cref="MediaCommand" /> class.
 /// </summary>
 /// <param name="manager">The command manager.</param>
 /// <param name="commandType">Type of the command.</param>
 protected MediaCommand(MediaCommandManager manager, MediaCommandType commandType)
 {
     Manager     = manager;
     CommandType = commandType;
 }