Fix Peek persisting as media player after window closed
Summary of the Pull Request
Fixes #26755
When previewing video or audio files in Peek and then closing the window, Peek continues to appear in the Windows System Media Transport Controls (SMTC) media player panel. This PR fixes this issue by properly unregistering the MediaPlayer from SMTC when media sources are cleared.
PR Checklist
- [x] Closes #26755
- [x] Communication: I've discussed this with core contributors already. If work hasn't been discussed, please file an issue with a proposal.
- [x] Tests: Added/updated and all pass. (No new tests needed - this is a behavioral fix for media player cleanup)
- [x] Localization: All end-user facing strings can be localized.
- [x] Dev docs: It's not applicable
- [x] New binaries: I've not introduced any new dependencies or binary files
- [x] Changelog: I've not added a one-liner to the CHANGELOG about this
Technical Details
Root Cause
The MediaPlayer in WinUI 3 automatically integrates with Windows System Media Transport Controls (SMTC). When the Peek window is closed:
- The video/audio source is set to
null - The media player is paused
- However, the
CommandManagerremains registered with SMTC, causing the player to persist in the media controls panel
Solution
According to Microsoft documentation, setting CommandManager.IsEnabled = false properly unregisters the media player from SMTC.
This PR:
-
FilePreview.xaml.cs:
- Disables
CommandManager.IsEnabledwhen clearing the video source inOnPreviewerChanging() - Re-enables it when a new source is loaded via
SourceChangedevent handler
- Disables
-
AudioControl.xaml.cs:
- Disables
CommandManager.IsEnabledwhen audio source is set tonull - Re-enables it when a new audio source is set
- Disables
Testing
- Open Peek and preview a video file → video plays and appears in SMTC
- Close Peek window → Peek no longer appears in SMTC panel ✅
- Open Peek and preview an audio file → audio plays and appears in SMTC
- Close Peek window → Peek no longer appears in SMTC panel ✅
- Re-open Peek with another media file → transport controls work normally ✅
@check-spelling-bot Report
:red_circle: Please review
See the :open_file_folder: files view, the :scroll:action log, or :memo: job summary for details.
Unrecognized words (1)
SMTC
These words are not needed and should be removed
CVSTo accept these unrecognized words as correct and remove the previously acknowledged and now absent words, you could run the following commands
... in a clone of the [email protected]:ThanhNguyxn/PowerToys.git repository
on the fix/peek-media-player-smtc branch (:information_source: how do I use this?):
curl -s -S -L 'https://raw.githubusercontent.com/check-spelling/check-spelling/c635c2f3f714eec2fcf27b643a1919b9a811ef2e/apply.pl' |
perl - 'https://github.com/microsoft/PowerToys/actions/runs/19881472298/attempts/1' &&
git commit -m 'Update check-spelling metadata'
If the flagged items are :exploding_head: false positives
If items relate to a ...
-
binary file (or some other file you wouldn't want to check at all).
Please add a file path to the
excludes.txtfile matching the containing file.File paths are Perl 5 Regular Expressions - you can test yours before committing to verify it will match your files.
^refers to the file's path from the root of the repository, so^README\.md$would exclude README.md (on whichever branch you're using). -
well-formed pattern.
If you can write a pattern that would match it, try adding it to the
patterns.txtfile.Patterns are Perl 5 Regular Expressions - you can test yours before committing to verify it will match your lines.
Note that patterns can't match multiline strings.
@microsoft-github-policy-service agree