[video_player_android] Fix rendering freeze after full-screen transit…#11416
[video_player_android] Fix rendering freeze after full-screen transit…#11416moepanda wants to merge 2 commits intoflutter:mainfrom
Conversation
There was a problem hiding this comment.
Code Review
This pull request updates the video_player_android package to version 2.9.6 and addresses a bug where videos freeze after returning from full-screen transitions. The changes introduce a custom VideoSurfaceView that re-binds the ExoPlayer to the surface upon visibility changes and refactors surface management to use a manual binding process with a seek-based workaround for Android 9 rendering issues. Review feedback suggests optimizing the seek operation by checking if the player is already playing to avoid performance stutters and refining the visibility check in onVisibilityChanged with isShown() to prevent redundant surface bindings.
...oid/android/src/main/java/io/flutter/plugins/videoplayer/platformview/PlatformVideoView.java
Outdated
Show resolved
Hide resolved
...oid/android/src/main/java/io/flutter/plugins/videoplayer/platformview/PlatformVideoView.java
Outdated
Show resolved
Hide resolved
bb099a6 to
a04a4f7
Compare
| // Workaround for a rendering bug on Android 9 (API 28) where the decoder does not | ||
| // flush its output buffer when a new surface is attached while the player is paused, | ||
| // resulting in a black frame. A seek forces the codec to produce and display a frame. | ||
| if (!exoPlayer.getPlayWhenReady()) { |
There was a problem hiding this comment.
This changes the seekTo triggering - how sure are you that we want to do that?
There was a problem hiding this comment.
This changes the seekTo triggering - how sure are you that we want to do that?
Thanks, that’s a good callout.
I’ve narrowed this back down so that the Android 9 seekTo(...) workaround remains only in surfaceCreated, where that compatibility logic originally existed. onVisibilityChanged(...) now only rebinds the player to the current surface and does not trigger any extra seek.
The goal here is to fix the fullscreen-return case without broadening seekTo(...) behavior across other devices. In my testing, the surface rebind was sufficient on non-Android 9 devices, so I removed the extra seek from that path.
Fixes flutter/flutter#184241
Description
When using
PlatformViewmode on Android, the video freezes (frozen on a specific frame) after returning from a full-screen dialog or route transition. This happens because theSurfaceis destroyed when the view is hidden, andExoPlayerdoes not automatically re-attach to the newSurfacewhen it becomes visible again.Changes
VideoSurfaceViewsubclass that overridesonVisibilityChangedto re-bindExoPlayerto the currentSurfacewhenever the view becomes visible again.bindPlayerToSurfacehelper to centralize surface binding and the Android 9 seek workaround.clearVideoSurface(surface)insurfaceDestroyedto safely unbind only the current surface.PlatformVideoViewTestto use Robolectric'sShadowSurfaceViewAPI for lifecycle simulation.Pre-Review Checklist
[shared_preferences]///).