public async Task Refresh(bool stopPlayer) { if (stopPlayer) { if (PlayerActor.PlaybackState == PlaybackState.Playing || PlayerActor.PlaybackState == PlaybackState.Paused) { PlayerActor.Stop(); } } bool result = PlayerActor.LibraryActor.Refresh(); var items = PlayerActor.LibraryActor.LibraryItems; var model = BuildModel(items, result); await SendLibraryStatus(model); }
private void DoWork(object state) { var time = DateTime.Now; var shouldTrigger = time.Hour == AlarmConfiguration.AlarmTime.Hours && time.Minute >= AlarmConfiguration.AlarmTime.Minutes && time.Minute <= time.Minute + AlarmConfiguration.AlarmMissThreshold.Minutes && !alarmTriggered; if (shouldTrigger) { logger.LogInformation("Raising alarm"); alarmTriggered = true; if (playerActor.PlaybackState == PlaybackState.Playing || playerActor.PlaybackState == PlaybackState.Paused) { playerActor.Stop(); } if (!playerActor.Repeat) { playerActor.ToggleRepeat(); } playerActor.NowPlaying.Clear(); this.previousVolume = playerActor.BassActor.CurrentVolume; playerActor.Volume(100); playerActor.Enqueue(AlarmConfiguration.MediaItemId); } else if (time.Hour == AlarmConfiguration.AlarmAutoTurnOffCheckTime.Hours && time.Minute >= AlarmConfiguration.AlarmAutoTurnOffCheckTime.Minutes && alarmTriggered) { logger.LogInformation("Disarming alarm"); playerActor.Volume(previousVolume); alarmTriggered = false; if (playerActor.PlaybackState == PlaybackState.Playing || playerActor.PlaybackState == PlaybackState.Paused) { playerActor.Stop(); } } }
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())); }
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" }); } }
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)); }