Skip to content

[video_player_android] Fix rendering freeze after full-screen transit…#11416

Merged
auto-submit[bot] merged 6 commits into
flutter:mainfrom
moepanda:fix_184241_videoplayer_platformview
Jun 24, 2026
Merged

[video_player_android] Fix rendering freeze after full-screen transit…#11416
auto-submit[bot] merged 6 commits into
flutter:mainfrom
moepanda:fix_184241_videoplayer_platformview

Conversation

@moepanda

@moepanda moepanda commented Apr 2, 2026

Copy link
Copy Markdown
Contributor

Fixes flutter/flutter#184241

Description

When using PlatformView mode on Android, the video freezes (frozen on a specific frame) after returning from a full-screen dialog or route transition. This happens because the Surface is destroyed when the view is hidden, and ExoPlayer does not automatically re-attach to the new Surface when it becomes visible again.

Changes

  • Introduced a custom VideoSurfaceView subclass that overrides onVisibilityChanged to re-bind ExoPlayer to the current Surface whenever the view becomes visible again.
  • Extracted a bindPlayerToSurface helper to centralize surface binding and the Android 9 seek workaround.
  • Used clearVideoSurface(surface) in surfaceDestroyed to safely unbind only the current surface.
  • Updated PlatformVideoViewTest to use Robolectric's ShadowSurfaceView API for lifecycle simulation.

Pre-Review Checklist

  • I read the Contributor Guide and followed the process outlined there for submitting PRs.
  • I read the AI contribution guidelines and understand my responsibilities, or I am not using AI tools.
  • I read the Tree Hygiene page, which explains my responsibilities.
  • I read and followed the relevant style guides and ran the auto-formatter.
  • I signed the CLA.
  • The title of the PR starts with the name of the package surrounded by square brackets, e.g. [shared_preferences]
  • I linked to at least one issue that this PR fixes in the description above.
  • I followed the version and CHANGELOG instructions, using semantic versioning and the repository CHANGELOG style, or I have commented below to indicate which documented exception this PR falls under.
  • I updated/added any relevant documentation (doc comments with ///).
  • I added new tests to check the change I am making, or I have commented below to indicate which test exemption this PR falls under.
  • All existing and new tests are passing.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

// 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()) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This changes the seekTo triggering - how sure are you that we want to do that?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@camsim99 camsim99 requested a review from mboetger April 14, 2026 17:57
@reidbaker reidbaker added the CICD Run CI/CD label Apr 28, 2026
@github-actions github-actions Bot removed the CICD Run CI/CD label Apr 29, 2026
@jesswrd jesswrd added the CICD Run CI/CD label May 5, 2026
@github-actions github-actions Bot removed the CICD Run CI/CD label May 6, 2026
@moepanda moepanda force-pushed the fix_184241_videoplayer_platformview branch from 7b08be3 to ae174bf Compare May 20, 2026 00:33
@moepanda

Copy link
Copy Markdown
Contributor Author

Hi @mboetger — I rebased and force-pushed (latest: ae174bf). CI workflows are awaiting approval on this fork PR. Could you please approve the workflows and re-review when you have a moment? Thanks!

@mboetger mboetger left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry I didn't get to this sooner - thank you for the PR

@mboetger mboetger added the CICD Run CI/CD label Jun 2, 2026
@mboetger

mboetger commented Jun 2, 2026

Copy link
Copy Markdown
Contributor

Looks like some formatting issues with the code.

@github-actions github-actions Bot removed the CICD Run CI/CD label Jun 3, 2026
@moepanda

moepanda commented Jun 4, 2026

Copy link
Copy Markdown
Contributor Author

Looks like some formatting issues with the code.

Please take a look.

@stuartmorgan-g

Copy link
Copy Markdown
Collaborator

@mboetger Could you add a secondary reviewer from the Android team, since this only involves the Android implementation internals?

@camsim99 camsim99 self-requested a review June 9, 2026 18:54

@camsim99 camsim99 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks for the fixes! I think a versioning bump is needed, though.

Comment thread packages/video_player/video_player_android/CHANGELOG.md
@camsim99 camsim99 added the CICD Run CI/CD label Jun 16, 2026
@github-actions github-actions Bot removed the CICD Run CI/CD label Jun 17, 2026
@moepanda moepanda force-pushed the fix_184241_videoplayer_platformview branch from 6aff617 to 86fe0b8 Compare June 17, 2026 03:46
@moepanda moepanda force-pushed the fix_184241_videoplayer_platformview branch from 86fe0b8 to 46bc007 Compare June 24, 2026 00:57
@camsim99 camsim99 added autosubmit Merge PR when tree becomes green via auto submit App CICD Run CI/CD labels Jun 24, 2026
@auto-submit auto-submit Bot merged commit 7ff3e1f into flutter:main Jun 24, 2026
87 checks passed
harryterkelsen pushed a commit to Ortes/flutter that referenced this pull request Jun 25, 2026
…#188565)

flutter/packages@af136cc...7ff3e1f

2026-06-24 14008334+moepanda@users.noreply.github.com
[video_player_android] Fix rendering freeze after full-screen transit…
(flutter/packages#11416)

If this roll has caused a breakage, revert this CL and stop the roller
using the controls here:
https://autoroll.skia.org/r/flutter-packages-flutter-autoroll
Please CC flutter-ecosystem@google.com on the revert to ensure that a
human
is aware of the problem.

To file a bug in Flutter:
https://github.com/flutter/flutter/issues/new/choose

To report a problem with the AutoRoller itself, please file a bug:
https://issues.skia.org/issues/new?component=1389291&template=1850622

Documentation for the AutoRoller is here:
https://skia.googlesource.com/buildbot/+doc/main/autoroll/README.md
rwrz added a commit to RealLifeGlobal/packages that referenced this pull request Jun 26, 2026
Resolves video_player conflicts between the fork's custom work and upstream:

- Pigeon API (video_player_instance_messages): union of the fork's ABR
  control (PlatformVideoQuality, getAvailableQualities/getCurrentQuality/
  setMaxBitrate/setMaxResolution) and upstream's video track selection
  (flutter#11476: MediaSelection/Asset/NativeVideoTrackData, getVideoTracks/
  selectVideoTrack). Generated .g.dart/.g.m/.g.h regenerated via pigeon.
- avfoundation_video_player.dart: kept both override sets.
- PlatformVideoView.java: took upstream's VideoSurfaceView fix (flutter#11416) and
  kept the fork's exoPlayer field used by dispose().
- pubspec.yaml (avf/web/example): kept path: dependency on the local
  video_player_platform_interface (fork has unpublished interface methods);
  took upstream version bump 2.10.0 and web: ^1.0.0.
- CHANGELOG: folded the fork's backgrounding-crash fix into 2.10.0.
- pkg_web_tweaks.dart: aligned with upstream (flutter#11820) to reduce divergence.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

autosubmit Merge PR when tree becomes green via auto submit App CICD Run CI/CD p: video_player platform-android triage-android Should be looked at in Android triage

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[video_player][android] Video player can't render video view but can play audio

6 participants