From 5b08f9138b9c993e4a530fd998978b90dced0a2e Mon Sep 17 00:00:00 2001 From: glax Date: Thu, 22 Feb 2024 03:46:19 +0100 Subject: [PATCH] Fix crash when object not ready --- DiscordMediaRP/DisMediaRP.cs | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/DiscordMediaRP/DisMediaRP.cs b/DiscordMediaRP/DisMediaRP.cs index 28bbd27..4613a0a 100644 --- a/DiscordMediaRP/DisMediaRP.cs +++ b/DiscordMediaRP/DisMediaRP.cs @@ -52,7 +52,15 @@ public class DisMediaRP : IDisposable if (this._mediaManager.GetFocusedSession() is not null) { - this.MediaPropertyChanged(this._mediaManager.GetFocusedSession(), this._mediaManager.GetFocusedSession().ControlSession.TryGetMediaPropertiesAsync().GetResults()); + try + { + this.MediaPropertyChanged(this._mediaManager.GetFocusedSession(), + this._mediaManager.GetFocusedSession().ControlSession.TryGetMediaPropertiesAsync().GetResults()); + } + catch (System.Runtime.InteropServices.COMException e) + { + this._logger?.LogError("Could not fetch MediaProperties\n{e}", e); + } this.PlaybackStateChanged(this._mediaManager.GetFocusedSession(), this._mediaManager.GetFocusedSession().ControlSession.GetPlaybackInfo()); this.TimelinePropertyChanged(this._mediaManager.GetFocusedSession(), this._mediaManager.GetFocusedSession().ControlSession.GetTimelineProperties()); }