-
Notifications
You must be signed in to change notification settings - Fork 903
Pause MediaPlayerElement when leaving the live tree #11670
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?
Changes from all commits
f0a5886
0962634
7a20557
15d06bc
532ce74
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -264,6 +264,7 @@ MediaPlayerElement::OnPropertyChanged2(_In_ const PropertyChangedParams& args) | |
| if (args.m_pDP->GetIndex() == KnownPropertyIndex::MediaPlayerElement_MediaPlayer) | ||
| { | ||
| IFC_RETURN(get_MediaPlayer(&m_spMediaPlayer)); | ||
| m_resumeMediaPlayerOnEnter = false; | ||
| IFC_RETURN(UpdateTransportControlsState()); | ||
| IFC_RETURN(UpdateAutoPlay()); | ||
| IFC_RETURN(UpdateSource()); | ||
|
|
@@ -700,6 +701,12 @@ MediaPlayerElement::EnterImpl( | |
| { | ||
| IFC_RETURN(UpdateAutoPlay()); | ||
|
|
||
| if (m_resumeMediaPlayerOnEnter && m_spMediaPlayer) | ||
| { | ||
| m_resumeMediaPlayerOnEnter = false; | ||
| LOG_IF_FAILED(m_spMediaPlayer->Play()); | ||
| } | ||
|
|
||
| IFC_RETURN(UpdateTimedTextSource()); | ||
| } | ||
|
|
||
|
|
@@ -721,8 +728,49 @@ MediaPlayerElement::LeaveImpl( | |
| IFC_RETURN(m_spTimedTextSource->SetMediaPlayer(nullptr)); | ||
| } | ||
|
|
||
| bool shouldPauseMediaPlayer = bLive && !bVisualTreeBeingReset; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| if (bLive && bVisualTreeBeingReset) | ||
| { | ||
| if (CContentRoot* contentRoot = VisualTree::GetContentRootForElement(GetHandle())) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If |
||
| { | ||
| shouldPauseMediaPlayer = contentRoot->IsShuttingDown(); | ||
| } | ||
| } | ||
|
|
||
| IFC_RETURN(__super::LeaveImpl(bLive, bSkipNameRegistration, bCoercedIsEnabled, bVisualTreeBeingReset)); | ||
|
|
||
| if (shouldPauseMediaPlayer && m_spMediaPlayer && !m_resumeMediaPlayerOnEnter) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since |
||
| { | ||
| ctl::ComPtr<wmp::IMediaPlayer3> spMediaPlayer3; | ||
| ctl::ComPtr<wmp::IMediaPlaybackSession> spPlaybackSession; | ||
| wmp::MediaPlaybackState playbackState{}; | ||
|
|
||
| HRESULT stateResult = m_spMediaPlayer.As(&spMediaPlayer3); | ||
| if (SUCCEEDED(stateResult)) | ||
| { | ||
| stateResult = spMediaPlayer3->get_PlaybackSession(&spPlaybackSession); | ||
| } | ||
| if (SUCCEEDED(stateResult) && spPlaybackSession) | ||
| { | ||
| stateResult = spPlaybackSession->get_PlaybackState(&playbackState); | ||
| } | ||
| else if (SUCCEEDED(stateResult)) | ||
| { | ||
| stateResult = E_UNEXPECTED; | ||
| } | ||
|
|
||
| if (SUCCEEDED(stateResult) && | ||
| (playbackState == wmp::MediaPlaybackState_Playing || | ||
| playbackState == wmp::MediaPlaybackState_Buffering)) | ||
| { | ||
| const HRESULT pauseResult = m_spMediaPlayer->Pause(); | ||
| if (SUCCEEDED(pauseResult)) | ||
| { | ||
| m_resumeMediaPlayerOnEnter = true; | ||
| } | ||
| } | ||
| } | ||
|
|
||
| return S_OK; | ||
| } | ||
|
|
||
|
|
||
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.
m_resumeMediaPlayerOnEnteris only cleared at line 267 for theMediaPlayerproperty and here at 706, so aSourcechange while the element is detached leaves it set and we force aPlay()on the newly bound content on re-entry - that is the recycled container case forListViewandItemsRepeater. It also bypassesAutoPlay="False", sinceUpdateAutoPlay()runs just before this, and it reverses aPause()the app or user performed while we were out of the tree. Please check whether we should clear the flag in theSourcecase too, and re-readPlaybackStatebefore resuming.