Пример #1
0
        public Task StartAsync(CancellationToken stoppingToken)
        {
            logger.Log(LogLevel.Information, "Started monitor");
            var libraryItem = new LibraryItem(-1, Path.Combine(AppDirectory, StartupFileName), bassActor);

            if (playerActor.PlaybackState == PlaybackState.Stopped)
            {
                playerActor.Play(libraryItem);
            }

            Pi.Init <BootstrapWiringPi>();
            pin         = Pi.Gpio[BcmPin.Gpio03];
            pin.PinMode = GpioPinDriveMode.Input;
            pin.RegisterInterruptCallback(EdgeDetection.FallingEdge, ISRCallback);
            return(Task.CompletedTask);
        }
Пример #2
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()));
        }
Пример #3
0
 public void Initiate(ShutdownType shutdownType)
 {
     //debounce
     if (!_isShutdownRequested)
     {
         _isShutdownRequested = true;
         _logger.Log(LogLevel.Information, $"{shutdownType} signal received");
         var libraryItem = new LibraryItem(-1, Path.Combine(_appDirectory, ShutdownFileName), _bassActor);
         if (_playerActor.PlaybackState == PlaybackState.Playing || _playerActor.PlaybackState == PlaybackState.Paused)
         {
             _playerActor.Stop();
         }
         if (_playerActor.PlaybackState == PlaybackState.Stopped)
         {
             _playerActor.Play(libraryItem);
         }
         Thread.Sleep(2000);
         var operation = shutdownType == ShutdownType.RestartImmediate ? "reboot" : "shutdown";
         Process.Start(new ProcessStartInfo()
         {
             FileName = "sudo", Arguments = $"{operation} now"
         });
     }
 }
Пример #4
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));
        }