PowerToys icon indicating copy to clipboard operation
PowerToys copied to clipboard

Fix Peek persisting as media player after window closed

Open ThanhNguyxn opened this issue 3 weeks ago • 2 comments

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:

  1. The video/audio source is set to null
  2. The media player is paused
  3. However, the CommandManager remains 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:

  1. FilePreview.xaml.cs:

    • Disables CommandManager.IsEnabled when clearing the video source in OnPreviewerChanging()
    • Re-enables it when a new source is loaded via SourceChanged event handler
  2. AudioControl.xaml.cs:

    • Disables CommandManager.IsEnabled when audio source is set to null
    • Re-enables it when a new audio source is set

Testing

  1. Open Peek and preview a video file → video plays and appears in SMTC
  2. Close Peek window → Peek no longer appears in SMTC panel ✅
  3. Open Peek and preview an audio file → audio plays and appears in SMTC
  4. Close Peek window → Peek no longer appears in SMTC panel ✅
  5. Re-open Peek with another media file → transport controls work normally ✅

ThanhNguyxn avatar Dec 03 '25 03:12 ThanhNguyxn

@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 CVS

To 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.txt file 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.txt file.

    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.

github-actions[bot] avatar Dec 03 '25 03:12 github-actions[bot]

@microsoft-github-policy-service agree

ThanhNguyxn avatar Dec 03 '25 03:12 ThanhNguyxn