From 0d3f687aef692c663b9cfbfd377bf19aa5e2519f Mon Sep 17 00:00:00 2001 From: ashpynov Date: Mon, 27 May 2024 22:01:23 +0300 Subject: [PATCH] Better handling of video splash --- MediaElementsMonitor.cs | 5 +++-- PlayniteSounds.cs | 20 +++++++++++++------- PlayniteSounds.yaml | 7 +++++++ extension.yaml | 6 +++++- 4 files changed, 28 insertions(+), 10 deletions(-) diff --git a/MediaElementsMonitor.cs b/MediaElementsMonitor.cs index 7503e90..c075a3b 100644 --- a/MediaElementsMonitor.cs +++ b/MediaElementsMonitor.cs @@ -47,7 +47,7 @@ static public void Attach(IPlayniteAPI api, PlayniteSoundsSettings settings) EventManager.RegisterClassHandler(typeof(MediaElement), MediaElement.MediaOpenedEvent, new RoutedEventHandler(MediaElement_Opened)); timer = new DispatcherTimer(); - timer.Interval = TimeSpan.FromTicks(100); + timer.Interval = TimeSpan.FromMilliseconds(10); timer.Tick += Timer_Tick; } @@ -73,7 +73,6 @@ public static List GetAllMediaElements(DependencyObject parent) } static private void Timer_Tick(object sender, EventArgs e) { - bool someIsPlaying = false; var mediaElements = GetAllMediaElements(Application.Current.MainWindow); @@ -120,11 +119,13 @@ static private void Timer_Tick(object sender, EventArgs e) if (mediaElementPositions.Count == 0) { timer.Stop(); + settings.VideoIsPlaying = false; } } static private void MediaElement_Opened(object sender, RoutedEventArgs e) { + Timer_Tick(sender, e); timer.Start(); } } diff --git a/PlayniteSounds.cs b/PlayniteSounds.cs index e37861f..9f21b64 100644 --- a/PlayniteSounds.cs +++ b/PlayniteSounds.cs @@ -162,7 +162,9 @@ public PlayniteSounds(IPlayniteAPI api) : base(api) { SourceName = "Sounds", SettingsRoot = $"{nameof(SettingsModel)}.{nameof(SettingsModel.Settings)}" - }); + }); + if (SettingsModel.Settings.PauseOnTrailer) + MediaElementsMonitor.Attach(PlayniteApi, SettingsModel.Settings); } catch (Exception e) @@ -266,9 +268,6 @@ public override void OnApplicationStarted(OnApplicationStartedEventArgs args) Application.Current.MainWindow.StateChanged += OnWindowStateChanged; Application.Current.Deactivated += OnApplicationDeactivate; Application.Current.Activated += OnApplicationActivate; - - if (SettingsModel.Settings.PauseOnTrailer) - MediaElementsMonitor.Attach(PlayniteApi, SettingsModel.Settings); } public override void OnApplicationStopped(OnApplicationStoppedEventArgs args) @@ -598,9 +597,16 @@ private void PlayMusicFromFiles(string[] musicFiles) private void ResumeMusic() { - if (ShouldPlayMusic() && _musicPlayer.Clock != null) - { - Try(_musicPlayer.Clock.Controller.Resume); + if (ShouldPlayMusic()) + { + if (_musicPlayer.Clock != null) + { + Try(_musicPlayer.Clock.Controller.Resume); + } + else + { + PlayMusicBasedOnSelected(); + } } } diff --git a/PlayniteSounds.yaml b/PlayniteSounds.yaml index f325eb7..0120d8f 100644 --- a/PlayniteSounds.yaml +++ b/PlayniteSounds.yaml @@ -1,5 +1,12 @@ AddonId: 'Playnite.Sounds.Mod.baf1744c-72f6-4bc1-92cc-474403b279fb' Packages: + - Version: 5.7.4 + RequiredApiVersion: 6.11.0 + ReleaseDate: 2024-05-27 + PackageUrl: https://github.com/ashpynov/PlayniteSound/releases/download/v5.7.3/Playnite.Sounds.Mod.baf1744c-72f6-4bc1-92cc-474403b279fb_5_7_4.pext + Changelog: + - Better handling startup splash video + - Reduced monitoring workload and better keeping music muted - Version: 5.7.3 RequiredApiVersion: 6.11.0 ReleaseDate: 2024-05-23 diff --git a/extension.yaml b/extension.yaml index c9294ba..211e1ed 100644 --- a/extension.yaml +++ b/extension.yaml @@ -1,7 +1,7 @@ Id: Playnite.Sounds.Mod.baf1744c-72f6-4bc1-92cc-474403b279fb Name: Playnite Sounds Mod Author: ashpynov, cnapolit, Joyrider3774 -Version: 5.7.3 +Version: 5.7.4 Module: PlayniteSounds.dll Type: GenericPlugin Icon: icon.png @@ -14,3 +14,7 @@ Links: Url: https://discord.com/channels/365863063296933888/808419165311467630 - Name: Bug tracker Url: https://github.com/ashpynov/PlayniteSound/issues + - Name: Ko-fi for Tips + Url: https://ko-fi.com/ashpynov + - Name: Boosty for Tips + Url: https://boosty.to/ashpynov/donate