private void InterpretStatus(string statusXml) { if (!_timeSource.CheckAccess()) { try { _timeSource.Dispatcher.Invoke(() => InterpretStatus(statusXml)); } catch (Exception e) { Debug.WriteLine("Exception in McpTimeSource.InterpretStatus: " + e.Message); } return; } try { MpcStatus newStatus = new MpcStatus(statusXml); if (newStatus.IsValid) { if (!_previousStatus.IsValid || _previousStatus.FilePath != newStatus.FilePath) { OnFileOpened(newStatus.FilePath); } if (!_previousStatus.IsValid || _previousStatus.State != newStatus.State) { if (newStatus.State == MpcPlaybackState.Playing) { _timeSource.Play(); } else { _timeSource.Pause(); } } if (!_previousStatus.IsValid || _previousStatus.Duration != newStatus.Duration) { _timeSource.SetDuration(TimeSpan.FromMilliseconds(newStatus.Duration)); } if (!_previousStatus.IsValid || _previousStatus.Position != newStatus.Position) { _timeSource.SetPosition(TimeSpan.FromMilliseconds(newStatus.Position)); } } _previousStatus = newStatus; } catch (Exception exception) { Debug.WriteLine("Couldn't interpret MPC Status: " + exception.Message); } }
public MpcTimeSource(ISampleClock clock, MpcConnectionSettings connectionSettings) { _connectionSettings = connectionSettings; _previousStatus = new MpcStatus { IsValid = false }; _timeSource = new ManualTimeSource(clock, TimeSpan.FromMilliseconds(35)); _timeSource.DurationChanged += TimeSourceOnDurationChanged; _timeSource.IsPlayingChanged += TimeSourceOnIsPlayingChanged; _timeSource.ProgressChanged += TimeSourceOnProgressChanged; _timeSource.PlaybackRateChanged += TimeSourceOnPlaybackRateChanged; _clientLoop = new Thread(ClientLoop); _clientLoop.Start(); }