fix: pause dynamic video background when main window is minimized - #1932
Open
zzstar101 wants to merge 2 commits into
Open
fix: pause dynamic video background when main window is minimized#1932zzstar101 wants to merge 2 commits into
zzstar101 wants to merge 2 commits into
Conversation
zzstar101
marked this pull request as ready for review
August 30, 2026 04:16
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
问题
主窗口最小化后,动态视频背景仍然持续播放和解码。
MainWindow.WindowSubclassProc此前只处理了WM_ACTIVATE、WM_WTSSESSION_CHANGE等消息,没有处理
WM_SIZE。普通最小化(标题栏按钮、ShowWindow(SW_MINIMIZE)、启动游戏时的最小化动作)不会产生任何
MainWindowStateChangedMessage,AppBackground无从得知窗口已最小化,MediaPlayer继续解码。实测:
另外,现有的恢复逻辑本质是 event-toggle:
Hide → Pause、SessionLock → Pause、Activate → Play。单个恢复事件会无条件覆盖其他暂停条件,例如最小化 → 锁屏 → 还原时WM_ACTIVATE会导致在锁屏期间错误恢复播放。修改
不改动媒体管线(frame server / Win2D / 解码器均不动),只修窗口生命周期状态:
MainWindowStateChangedMessagebool? Minimized:true进入最小化 /false退出最小化 /null与最小化无关bool SessionUnlock:补上此前为空的WTS_SESSION_UNLOCK分支MainWindow.xaml.csWindowSubclassProc新增WM_SIZE分支:SIZE_MINIMIZED→Minimized = true,SIZE_RESTORED / SIZE_MAXIMIZED→Minimized = false(窗口本身IsMaximizable = false,MAXIMIZED 仅作防御)_isMinimized去抖,仅在状态翻转时发消息,避免SIZE_RESTORED噪音(DPI 变化、移动窗口等)流入其他消息消费者
WTS_SESSION_UNLOCK发送{ SessionUnlock = true }AppBackground.xaml.cs_windowHidden、_windowMinimized、_sessionLockedHide/Activate → hidden、WM_SIZE → minimized、WTS lock/unlock → sessionLockedActivate只清除 hidden,不再无条件恢复播放;暂停/恢复统一由ShouldPauseVideo = _windowHidden || _windowMinimized || _sessionLocked决策StartMediaPlayer末尾检查ShouldPauseVideo:若窗口此刻不可播放(如最小化期间背景下载完成),新建的播放器立即暂停,
避免错过已发生的状态消息
用户手动暂停(封面右上角按钮)走
StopVideo → DisposeVideoResource,播放器被释放为 null,生命周期消息对 null 播放器无操作,因此
"手动暂停 → 最小化 → 还原" 仍保持静态背景,不会被生命周期恢复覆盖。
行为对照
验证
dotnet build src/Starward/Starward.csproj -c Debug -p:Platform=x64:0 错误,触碰文件无新增警告
GameBannerAndPost、GameLauncherPage、GameSelector、MainView)语义不受影响