VideoPlayerViewController: Fix frozen video on external display after backgrounding - #464
Open
pavellunev wants to merge 1 commit into
Open
pavellunev wants to merge 1 commit into
pavellunev wants to merge 1 commit into
Conversation
… backgrounding When playing on a wired external screen, sending the app to the background and returning to the foreground left the picture frozen on the external display while audio and the timeline kept advancing. The video output layer hosted in the external window has its render surface invalidated while backgrounded, and nothing on foreground forces it to be recreated, so only physically reconnecting the display recovered playback. When the app becomes active again while playing on an external screen (and not casting to a renderer), re-attach the video output by toggling it off and back on. This tears the output view out of the external window and re-inserts it, forcing the vout surface to be recreated.
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.
Summary
Playing video on a wired external display (USB-C/HDMI) freezes after the app
is sent to the background and brought back to the foreground: the picture
stays on the last frame on the external monitor while audio and the timeline
keep advancing. Only physically reconnecting the display restores the picture.
Cause
The video output view that hosts the vout render surface lives inside the
external
UIWindow. While the app is backgrounded, that surface isinvalidated (GPU rendering is not allowed in the background). On foreground
nothing re-attaches or recreates it, so the external display keeps showing
the stale frame. Reconnecting the cable works only because iOS recreates the
external scene/window, which re-runs the attach path.
Fix
In
playerControllerApplicationBecameActive, when the app becomes activeagain while playing on an external screen (and not casting to a renderer,
with an external window present), toggle the video output off and back on
(
videoOutputView = nilthen the view again). This removes the output viewfrom the external window and re-inserts it, forcing the vout surface to be
recreated.
The new branch is guarded so it is only entered for a wired external display:
isPlayingOnExternalScreen()together withrenderer == nilexcludesChromecast, and
externalWindow != nilexcludes the local-screen case, whichkeeps following the existing code path unchanged.
Testing
Verified on a physical device with a wired external monitor: play video →
background → return to foreground → the picture resumes in sync with audio
without reconnecting the display.