Pause MediaPlayerElement when its Window closes - #11670
Open
Hemant Kumar (Hemantxk) wants to merge 7 commits into
Open
Pause MediaPlayerElement when its Window closes#11670Hemant Kumar (Hemantxk) wants to merge 7 commits into
Hemant Kumar (Hemantxk) wants to merge 7 commits into
Conversation
Pause a playing MediaPlayer when its element leaves the live tree and resume only when that element initiated the pause. Cover remove/re-entry and retained Window-close lifecycles. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: a3043399-4002-4d60-b928-b71920a36bf0
|
Azure Pipelines: There may be pipelines that require an authorized user to comment /azp run to run. |
Pause only when the element leaves because its ContentRoot is shutting down. Remove resume state and retain focused Window-close coverage. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: a3043399-4002-4d60-b928-b71920a36bf0
Keep a source token after the final event macro expansion without retaining the temporary undef directives. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: a3043399-4002-4d60-b928-b71920a36bf0
Pause playing media on live-tree leave and resume when the same element re-enters after initiating that pause. Restore both focused lifecycle tests. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: a3043399-4002-4d60-b928-b71920a36bf0
Hemant Kumar (Hemantxk)
marked this pull request as ready for review
August 27, 2026 13:22
|
Azure Pipelines: There may be pipelines that require an authorized user to comment /azp run to run. |
Collaborator
Author
|
/azp run |
|
Azure Pipelines: 1 pipeline(s) were filtered out due to trigger conditions. |
Preserve the original trailing blank line after the final event macro expansion. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: a3043399-4002-4d60-b928-b71920a36bf0
|
/azp run |
|
Azure Pipelines: 1 pipeline(s) were filtered out due to trigger conditions. |
Saharsh Ananta Jaiswal (Saharsh979)
left a comment
There was a problem hiding this comment.
Is this gated? It changes playback behaviour for existing apps with no velocity or RuntimeEnabledFeature check - ComboBox_Partial.cpp:942 and Slider_Partial.cpp:147 are the pattern in this folder.
Check the ContentRoot lifetime on every live leave, pause only during terminal shutdown, and remove the re-entry resume state. Keep only the Window-close test and make it resistant to stale playback events. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: a3043399-4002-4d60-b928-b71920a36bf0
Query the current ad-break session when checking playback state before pausing during terminal shutdown. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: a3043399-4002-4d60-b928-b71920a36bf0
Collaborator
Author
We don't gate changes in main branch, and RuntimeEnabledFeature is an historic artifact and not recommended for new changes. |
Collaborator
Author
|
/azp run |
|
Azure Pipelines: 1 pipeline(s) were filtered out due to trigger conditions. |
Saharsh Ananta Jaiswal (Saharsh979)
approved these changes
Sep 1, 2026
Contributor
|
LGTM |
Abhijeet Jha (iamAbhi-916)
approved these changes
Sep 1, 2026
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.
Fixes
Related work item: ADO Bug 40049143
PR Type
Description
Current Behavior
When a
Windowcontaining a playingMediaPlayerElementis closed, its visual tree is torn down. Until the GC fully collects the closedWindowand its content, the underlyingMediaPlayerremains alive and can keep playing. The video surface disappears with the Window, but its audio continues in the background.New Behavior
During a live-tree leave,
MediaPlayerElementchecks itsContentRootbefore the element is detached. If theContentRootis shutting down and the player is playing or buffering, the player is paused.The shutdown check is made regardless of
bVisualTreeBeingReset.Window.Close()marks the ContentRoot asPreparingToClosebefore clearing the Window content, while the resulting leave arrives withbVisualTreeBeingReset == false.Playback state is read from
MediaPlayer_GetCurrentPlaybackSession(), so an active media-break session is considered instead of always reading the main playback session.Ordinary removal, navigation, recycling, and reparenting do not put the ContentRoot into a shutdown state, so they do not pause playback. No resume-on-re-entry state is needed for this terminal path.
Customer Impact
Closing a playback Window no longer leaves invisible media continuing in the background while the closed Window is waiting to be fully collected by the GC.
There is no public API change.
Regression Potential
The change is limited to live-tree leave during ContentRoot shutdown. It pauses only the active playback session when it is playing or buffering and does not change transport state for ordinary live-tree removal.
How Has This Been Tested?
Manual sample validation confirmed that audio pauses when the playback Window closes while the closed Window is still waiting to be fully collected by the GC.
PausesMediaPlayerWhenWindowClosespreviously passed in the focused WPF TAEF run. The final revision strengthens it by enabling looping and resetting the paused event immediately before close.I have performed a self-review of my own code
I have added tests to cover my changes
Existing tests pass locally