From abca9ae5fbd490d987b29de3c3cc8cc45f6ccd4f Mon Sep 17 00:00:00 2001 From: Zhe Fang Date: Sat, 3 Jan 2026 12:50:33 -0500 Subject: [PATCH] fix: auto-play in music gallery wont show song title and artist when first play --- .../BetterLyrics.WinUI3/Controls/NowPlayingBar.xaml | 1 + .../Services/GSMTCService/GSMTCService.cs | 12 ++++++------ .../Views/MusicGalleryPage.xaml.cs | 6 +++++- 3 files changed, 12 insertions(+), 7 deletions(-) diff --git a/BetterLyrics.WinUI3/BetterLyrics.WinUI3/Controls/NowPlayingBar.xaml b/BetterLyrics.WinUI3/BetterLyrics.WinUI3/Controls/NowPlayingBar.xaml index 0422b50..9d7c737 100644 --- a/BetterLyrics.WinUI3/BetterLyrics.WinUI3/Controls/NowPlayingBar.xaml +++ b/BetterLyrics.WinUI3/BetterLyrics.WinUI3/Controls/NowPlayingBar.xaml @@ -4,6 +4,7 @@ xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" + xmlns:dev="using:DevWinUI" xmlns:interactivity="using:Microsoft.Xaml.Interactivity" xmlns:local="using:BetterLyrics.WinUI3.Controls" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" diff --git a/BetterLyrics.WinUI3/BetterLyrics.WinUI3/Services/GSMTCService/GSMTCService.cs b/BetterLyrics.WinUI3/BetterLyrics.WinUI3/Services/GSMTCService/GSMTCService.cs index 8dfa8e0..7e1fe74 100644 --- a/BetterLyrics.WinUI3/BetterLyrics.WinUI3/Services/GSMTCService/GSMTCService.cs +++ b/BetterLyrics.WinUI3/BetterLyrics.WinUI3/Services/GSMTCService/GSMTCService.cs @@ -198,7 +198,7 @@ namespace BetterLyrics.WinUI3.Services.GSMTCService private void MediaManager_OnAnyTimelinePropertyChanged(MediaManager.MediaSession? mediaSession, GlobalSystemMediaTransportControlsSessionTimelineProperties? timelineProperties) { - _dispatcherQueue.TryEnqueue(DispatcherQueuePriority.Low, () => + _dispatcherQueue.TryEnqueue(() => { if (!_mediaManager.IsStarted) return; if (mediaSession == null) @@ -230,7 +230,7 @@ namespace BetterLyrics.WinUI3.Services.GSMTCService private void MediaManager_OnAnyPlaybackStateChanged(MediaManager.MediaSession? mediaSession, GlobalSystemMediaTransportControlsSessionPlaybackInfo? playbackInfo) { - _dispatcherQueue.TryEnqueue(DispatcherQueuePriority.Low, (() => + _dispatcherQueue.TryEnqueue(() => { if (!_mediaManager.IsStarted) return; if (mediaSession == null) @@ -264,14 +264,14 @@ namespace BetterLyrics.WinUI3.Services.GSMTCService { _scrobbleStopwatch.Stop(); } - })); + }); } private void MediaManager_OnAnyMediaPropertyChanged(MediaManager.MediaSession? mediaSession, GlobalSystemMediaTransportControlsSessionMediaProperties? mediaProperties) { _onMediaPropsChangedTimer?.Debounce(() => { - _dispatcherQueue.TryEnqueue(DispatcherQueuePriority.Low, async () => + _dispatcherQueue.TryEnqueue(async () => { if (!_mediaManager.IsStarted) return; if (mediaSession == null) @@ -419,13 +419,13 @@ namespace BetterLyrics.WinUI3.Services.GSMTCService } } - private void MediaManager_OnAnySessionOpened(MediaManager.MediaSession mediaSession) + private async void MediaManager_OnAnySessionOpened(MediaManager.MediaSession mediaSession) { if (!_mediaManager.IsStarted) return; if (mediaSession == null) return; RecordMediaSourceProviderInfo(mediaSession); - SendFocusedMessagesAsync().ConfigureAwait(false); + await SendFocusedMessagesAsync(); } private MediaManager.MediaSession? GetCurrentSession() diff --git a/BetterLyrics.WinUI3/BetterLyrics.WinUI3/Views/MusicGalleryPage.xaml.cs b/BetterLyrics.WinUI3/BetterLyrics.WinUI3/Views/MusicGalleryPage.xaml.cs index b7ae0d0..e5eedc2 100644 --- a/BetterLyrics.WinUI3/BetterLyrics.WinUI3/Views/MusicGalleryPage.xaml.cs +++ b/BetterLyrics.WinUI3/BetterLyrics.WinUI3/Views/MusicGalleryPage.xaml.cs @@ -180,7 +180,11 @@ namespace BetterLyrics.WinUI3.Views var settings = ViewModel.AppSettings.MusicGallerySettings; if (settings.AutoPlay) { - _ = _smtcService.PlayTrackAtAsync(settings.PlayQueueIndex); + Task.Run(async () => + { + await Task.Delay(1000); + _ = _smtcService.PlayTrackAtAsync(settings.PlayQueueIndex); + }); } }