public static void Reload() { if (_smtcManager != null) { _smtcManager.CurrentSessionChanged -= SmtcManagerOnCurrentSessionChanged; _smtcManager.SessionsChanged -= SmtcManagerOnSessionsChanged; } if (_smtc != null) { _smtc.MediaPropertiesChanged -= SmtcOnMediaPropertiesChanged; _smtc.TimelinePropertiesChanged -= SmtcOnTimelinePropertiesChanged; } //TODO: Implement automatic switching to new playing smtc _smtcManager = GlobalSystemMediaTransportControlsSessionManager.RequestAsync().GetAwaiter().GetResult(); _smtcManager.SessionsChanged += SmtcManagerOnSessionsChanged; _smtcManager.CurrentSessionChanged += SmtcManagerOnCurrentSessionChanged; _smtc = _smtcManager.GetCurrentSession(); if (_smtc != null) { _smtc.MediaPropertiesChanged += SmtcOnMediaPropertiesChanged; _smtc.TimelinePropertiesChanged += SmtcOnTimelinePropertiesChanged; _mediaProperties = _smtc.TryGetMediaPropertiesAsync().GetAwaiter().GetResult(); UpdateMediaProperties(); } }
//TODO: this does not trigger private static void SmtcManagerOnCurrentSessionChanged(GlobalSystemMediaTransportControlsSessionManager sender, CurrentSessionChangedEventArgs args) { if (_smtc != null) { _smtc.MediaPropertiesChanged -= SmtcOnMediaPropertiesChanged; _smtc.TimelinePropertiesChanged -= SmtcOnTimelinePropertiesChanged; } _smtc = sender.GetCurrentSession(); if (_smtc != null) { _smtc.MediaPropertiesChanged += SmtcOnMediaPropertiesChanged; _mediaProperties = _smtc.TryGetMediaPropertiesAsync().GetAwaiter().GetResult(); } }