public async Task <PlayerStatusModel> ControlAction(PlayerControlRequest playerControlRequest) { switch (playerControlRequest.ControlRequest) { case ControlRequest.VolumeAbsolute: var volume = (byte)playerControlRequest.RequestData; PlayerActor.Volume(volume); break; case ControlRequest.RepeatToggle: PlayerActor.ToggleRepeat(); break; case ControlRequest.Seek: PlayerActor.Seek(playerControlRequest.RequestData); break; case ControlRequest.VolumeRelative: var volumeStep = (byte)playerControlRequest.RequestData; var oldVolume = PlayerActor.BassActor.CurrentVolume; var newVolume = (byte)(oldVolume + volumeStep); PlayerActor.Volume(newVolume); break; case ControlRequest.Random: default: break; } await SendPlaybackStatus(); return(await Task.FromResult(getPlayerStatus())); }
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 IActionResult PlayerControlAction([FromBody] PlayerControlRequest playerControlRequest) { dynamic response = null; switch (playerControlRequest.ControlRequest) { case ControlRequest.VolumeAbsolute: var volume = (byte)playerControlRequest.RequestData; if (player.Volume(volume)) { response = new { Status = true, Message = $"Set Volume!", Values = new { Scale1 = player.BassActor.CurrentVolume, Scale2 = (float)player.BassActor.CurrentVolume / 100f } } } ; else { response = new { Status = false, Message = $"Unknown Error!" } }; break; case ControlRequest.RepeatToggle: var result = player.ToggleRepeat(); response = new { Status = result, Message = result ? $"Success! Repeat: {player.BassActor.Repeat}" : $"Failed! {player.PlaybackState.ToString()}", player.BassActor.Repeat }; break; case ControlRequest.Seek: result = player.Seek(playerControlRequest.RequestData); response = new { Status = result, Message = result ? $"Success! Seek: {playerControlRequest.RequestData}" : $"Failed to seek to: {playerControlRequest.RequestData.ToString()}!", player.BassActor.CurrentPositionBytes, player.BassActor.CurrentPositionSeconds, player.BassActor.CurrentPositionString }; break; case ControlRequest.VolumeRelative: var volumeStep = (byte)playerControlRequest.RequestData; var oldVolume = player.BassActor.CurrentVolume; var newVolume = (byte)(oldVolume + volumeStep); if (player.Volume(newVolume)) { response = new { Status = true, Message = $"Set Volume!", Values = new { Scale1 = player.BassActor.CurrentVolume, Scale2 = (float)player.BassActor.CurrentVolume / 100f } } } ; else { response = new { Status = false, Message = $"Unknown Error!" } }; break; case ControlRequest.Random: default: break; } return(Ok(response)); }