-
Notifications
You must be signed in to change notification settings - Fork 7.5k
Fix Peek persisting as media player after window closed #44043
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Fix Peek persisting as media player after window closed #44043
Conversation
This comment has been minimized.
This comment has been minimized.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR fixes an issue where Peek persists in Windows System Media Transport Controls (SMTC) after closing the window. The solution disables MediaPlayer.CommandManager.IsEnabled when clearing media sources and re-enables it when new sources are loaded.
Key Changes:
- Properly unregister media players from SMTC by disabling
CommandManager.IsEnabledwhen sources are cleared - Re-enable
CommandManager.IsEnabledwhen new media sources are loaded to restore transport controls functionality - Implement proper event handler lifecycle management for video media player
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| src/modules/peek/Peek.FilePreviewer/FilePreview.xaml.cs | Adds SourceChanged event handler to re-enable CommandManager after video source changes, disables CommandManager in OnPreviewerChanging when clearing video source, and properly unsubscribes event handler in Dispose |
| src/modules/peek/Peek.FilePreviewer/Controls/AudioControl.xaml.cs | Disables CommandManager when audio source is null and re-enables it when a non-null source is set in SourcePropertyChanged callback |
| else | ||
| { | ||
| // Re-enable CommandManager when a new source is set so transport controls work | ||
| mediaPlayer.CommandManager.IsEnabled = true; | ||
| } |
Copilot
AI
Dec 3, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Setting CommandManager.IsEnabled = true when Source is not null may occur before the MediaPlayer's source is actually set. The Source property is of type AudioPreviewData, and the actual MediaSource is bound via XAML binding (Source.MediaSource). This means the XAML binding hasn't necessarily evaluated yet when this code executes.
Consider using a SourceChanged event handler on PlayerElement.MediaPlayer (similar to how it's done in FilePreview.xaml.cs for video) to ensure the CommandManager is re-enabled only after the MediaPlayer source is actually set:
public AudioControl()
{
this.InitializeComponent();
PlayerElement.MediaPlayer.SourceChanged += AudioMediaPlayer_SourceChanged;
}
private void AudioMediaPlayer_SourceChanged(Windows.Media.Playback.MediaPlayer sender, object args)
{
if (sender.Source != null)
{
sender.CommandManager.IsEnabled = true;
}
}Don't forget to unsubscribe from this event if a Dispose method is added.
|
@microsoft-github-policy-service agree |
5c3208a to
3ecd669
Compare
Fixes microsoft#26755 When previewing video or audio files in Peek and closing the window, the app would persist in Windows System Media Transport Controls (SMTC) media player panel. This happened because the MediaPlayer was only paused and source cleared, but not properly unregistered from SMTC. The fix disables MediaPlayer.CommandManager.IsEnabled when clearing the source to remove the app from SMTC. The CommandManager is re-enabled when a new media source is loaded to restore transport controls functionality.
… expand SMTC abbreviation
3ecd669 to
788991d
Compare
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
Technical Details
Root Cause
The
MediaPlayerin WinUI 3 automatically integrates with Windows System Media Transport Controls (SMTC). When the Peek window is closed:nullCommandManagerremains registered with SMTC, causing the player to persist in the media controls panelSolution
According to Microsoft documentation, setting
CommandManager.IsEnabled = falseproperly unregisters the media player from SMTC.This PR:
FilePreview.xaml.cs:
CommandManager.IsEnabledwhen clearing the video source inOnPreviewerChanging()SourceChangedevent handlerAudioControl.xaml.cs:
CommandManager.IsEnabledwhen audio source is set tonullTesting