/// <summary> /// Handle a close message from the device. /// </summary> /// <param name="closeMessage">the close message</param> private void OnReceiveCloseMessage(PayloadMessageBase closeMessage) { if (applicationLogic == null) { return; } var deviceState = device.GetDeviceState(); var previousState = deviceState; // Restart? if (device.WasPlayingWhenStopped() || (applicationLogic.GetAutoRestart() && (previousState == DeviceState.Playing))) { ResumePlaying(); } else { if (deviceState == DeviceState.Playing || deviceState == DeviceState.Buffering || deviceState == DeviceState.Paused || deviceState == DeviceState.LoadingMedia) { Stop(); } device.SetDeviceState(DeviceState.Closed, null); Connected = false; Task.Run(() => { Task.Delay(2000).Wait(); GetReceiverStatus(); }); } }
private void OnReceiveCloseMessage(PayloadMessageBase closeMessage) { var deviceState = getDeviceState(); var previousState = deviceState; if (deviceState == DeviceState.Playing || deviceState == DeviceState.Buffering || deviceState == DeviceState.Paused || deviceState == DeviceState.LoadingMedia) { Stop(); } setDeviceState(DeviceState.Closed, null); Connected = false; // Restart if (wasPlayingWhenStopped() || (applicationLogic.GetAutoRestart() && (previousState == DeviceState.Playing || previousState == DeviceState.ConnectError))) { Task.Run(() => { Task.Delay(5000).Wait(); OnPlayPause_Click(); }); } else { Task.Run(() => { Task.Delay(2000).Wait(); GetReceiverStatus(); }); } }
/// <summary> /// Handle a close message from the device. /// </summary> /// <param name="closeMessage">the close message</param> private void OnReceiveCloseMessage(PayloadMessageBase closeMessage) { if (applicationLogic == null || device == null || IsDisposed) { return; } if (!(applicationLogic.GetAutoRestart())) { userMode = UserMode.Stopped; } var deviceState = device.GetDeviceState(); if (deviceState == DeviceState.Playing || deviceState == DeviceState.Buffering || deviceState == DeviceState.Paused || deviceState == DeviceState.LoadingMedia || deviceState == DeviceState.LoadingMediaCheckFirewall) { Stop(); } device.SetDeviceState(DeviceState.Closed, null); Connected = false; var cancellationTokeSource = new CancellationTokenSource(); applicationLogic.StartTask(() => { for (int i = 0; i < 20; i++) { Task.Delay(100).Wait(); if (cancellationTokeSource.IsCancellationRequested) { return; } } GetReceiverStatus(); }, cancellationTokeSource); }