private void EnsureControlServiceIsAlive() { try { if (_controlService.State == CommunicationState.Closed || _controlService.State == CommunicationState.Faulted) { _controlService.Abort(); _controlService = new PlayerControlServiceClient(new InstanceContext(this)); _controlService.Subscribe(); } } catch (Exception) { } }
private void SubscribeToControlEvents() { try { _controlService = new PlayerControlServiceClient(new InstanceContext(this)); _controlService.Subscribe(); } catch (Exception) { _controlService.Abort(); Thread thread = new Thread(() => { Thread.Sleep(5000); Initialize(); }); thread.IsBackground = true; thread.Start(); } }
public void Pause() { if (IsPlaying) { EnsureControlServiceIsAlive(); PlayerControlServiceClient controlService = new PlayerControlServiceClient(new InstanceContext(this)); try { controlService.TogglePause(); controlService.Close(); } catch (Exception) { controlService.Abort(); } _isPaused = true; } }
public void Play() { if (_currentTrack == null) { return; } if (_isPaused) { EnsureControlServiceIsAlive(); PlayerControlServiceClient controlService = new PlayerControlServiceClient(new InstanceContext(this)); try { controlService.TogglePause(); controlService.Close(); } catch (Exception) { controlService.Abort(); } } else { TrackPlayerServiceClient trackPlayer = new TrackPlayerServiceClient(); try { trackPlayer.Play(_currentTrack.TrackId); trackPlayer.Close(); } catch (Exception) { trackPlayer.Abort(); throw; } } _isPaused = false; }