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())); }
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(); } } }