예제 #1
0
        public async Task <PlayerStatusModel> RequestAction(PlayerRequest playerRequest)
        {
            switch (playerRequest.RequestType)
            {
            case RequestType.Play:
                if (PlayerActor.PlaybackState == PlaybackState.Stopped)
                {
                    PlayerActor.Play(playerRequest.Identifier);
                }
                break;

            case RequestType.Pause:
                if (PlayerActor.PlaybackState == PlaybackState.Playing)
                {
                    PlayerActor.Pause();
                }
                break;

            case RequestType.Resume:
                if (PlayerActor.PlaybackState == PlaybackState.Paused)
                {
                    PlayerActor.Resume();
                }
                break;

            case RequestType.Stop:
                if (PlayerActor.PlaybackState == PlaybackState.Playing || PlayerActor.PlaybackState == PlaybackState.Paused)
                {
                    PlayerActor.Stop();
                }
                break;

            case RequestType.Enqueue:
                PlayerActor.Enqueue(playerRequest.Identifier);
                break;

            case RequestType.DeQueue:
                break;

            default:
                break;
            }
            await SendPlaybackStatus();

            return(await Task.FromResult(getPlayerStatus()));
        }
예제 #2
0
        public IActionResult RequestAction([FromBody] PlayerRequest playerRequest)
        {
            dynamic response = null;

            switch (playerRequest.RequestType)
            {
            case RequestType.Play:
                if (player.PlaybackState == PlaybackState.Stopped)
                {
                    var success = player.Play(playerRequest.Identifier);
                    if (success)
                    {
                        response = new { Status = success, Message = $"Started!", MediaItem = player.CurrentLibraryItem }
                    }
                    ;
                    else
                    {
                        response = new { Status = success, Message = "Unknown Error" }
                    };
                }
                else
                {
                    response = new { Status = false, Message = $"Invalid State!", State = player.PlaybackState.ToString() }
                };
                break;

            case RequestType.Pause:
                if (player.PlaybackState == PlaybackState.Playing)
                {
                    var success = player.Pause();
                    if (success)
                    {
                        response = new { Status = success, Message = $"Playback Paused!", MediaItem = player.CurrentLibraryItem }
                    }
                    ;
                    else
                    {
                        response = new { Status = success, Message = "Unknown Error" }
                    };
                }
                else
                {
                    response = new { Status = false, Message = $"Invalid State!", State = player.PlaybackState.ToString() }
                };
                break;

            case RequestType.Resume:
                if (player.PlaybackState == PlaybackState.Paused)
                {
                    var success = player.Resume();
                    if (success)
                    {
                        response = new { Status = success, Message = $"Playback Resuming!", MediaItem = player.CurrentLibraryItem }
                    }
                    ;
                    else
                    {
                        response = new { Status = success, Message = "Unknown Error" }
                    };
                }
                else
                {
                    response = new { Status = false, Message = $"Invalid State!", State = player.PlaybackState.ToString() }
                };
                break;

            case RequestType.Stop:
                if (player.PlaybackState == PlaybackState.Playing || player.PlaybackState == PlaybackState.Paused)
                {
                    var currentItem = player.CurrentLibraryItem;
                    var success     = player.Stop();
                    if (success)
                    {
                        //Todo: Add the capability to say which song was stopped
                        response = new { Status = success, Message = "Playback stopped!", MediaItem = currentItem };
                    }
                    else
                    {
                        response = new { Status = success, Message = "Unknown Error" }
                    };                                                                                                  //Todo: add ability to provide error message as well
                }
                else
                {
                    response = new { Status = false, Message = $"Invalid State", State = player.PlaybackState.ToString() }
                };
                break;

            case RequestType.Enqueue:
                break;

            case RequestType.DeQueue:
                break;

            default:
                return(BadRequest(new { Status = false, Message = "Unknown RequestType" }));
            }
            return(Ok(response));
        }