Skip to content

Conversation

@bparrishMines
Copy link
Contributor

@bparrishMines bparrishMines commented Aug 20, 2025

The AndroidAdDisplayContainer wasn't handling the callback of VideoAdPlayer.release. It looks like the IMA SDK calls
VideoAdPlayer.release -> VideoAdPlayer.pauseAd -> VideoAdPlayer.stopAd when AdsManager.destroy is called.

The AdDisplayContainer now resets state on release and pauseAd only calls pause when media player is not null.

Also fixes race condition where AndroidAdDisplayContainer._adDuration would be set to null while retrieving the current position of the VideoView.

Fixes flutter/flutter#173537
Fixes flutter/flutter#174194

Pre-Review Checklist

If you need help, consider asking for advice on the #hackers-new channel on Discord.

Note: The Flutter team is currently trialing the use of Gemini Code Assist for GitHub. Comments from the gemini-code-assist bot should not be taken as authoritative feedback from the Flutter team. If you find its comments useful you can update your code accordingly, but if you are unsure or disagree with the feedback, please feel free to wait for a Flutter team member's review for guidance on which automated comments should be addressed.

Footnotes

  1. Regular contributors who have demonstrated familiarity with the repository guidelines only need to comment if the PR is not auto-exempted by repo tooling. 2 3

@bparrishMines bparrishMines changed the title handle release on android [interactive_media_ads] Fixes Android IllegalStateException caused by uninitalized MediaPlayer Aug 20, 2025
@bparrishMines bparrishMines marked this pull request as ready for review August 20, 2025 22:26
@bparrishMines
Copy link
Contributor Author

/gemini review

Copy link

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

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 addresses a critical IllegalStateException on Android by correctly handling the VideoAdPlayer.release callback, which now resets the ad container's state. A null check has been added to the pauseAd method to prevent calls on an uninitialized MediaPlayer. Additionally, a race condition in _startAdProgressTracking is resolved by ensuring ad duration is available before use. The changes are well-supported by new, targeted unit tests that validate the fixes.

Copy link
Collaborator

@stuartmorgan-g stuartmorgan-g left a comment

Choose a reason for hiding this comment

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

LGTM

@bparrishMines bparrishMines added the autosubmit Merge PR when tree becomes green via auto submit App label Aug 22, 2025
@auto-submit auto-submit bot merged commit edb7913 into flutter:main Aug 22, 2025
80 checks passed
@bparrishMines bparrishMines deleted the catch_illegal_state branch August 22, 2025 20:00
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Aug 25, 2025
github-merge-queue bot pushed a commit to flutter/flutter that referenced this pull request Aug 25, 2025
flutter/packages@092d832...fe66130

2025-08-23 [email protected] Roll Flutter from
26bb33b to edd434a (14 revisions) (flutter/packages#9874)
2025-08-23 [email protected] [google_maps_flutter_web] Fix
consumeTapEvents for Circles, Polygons & Polylines (#173921)
(flutter/packages#9838)
2025-08-22 [email protected]
[interactive_media_ads] Fixes Android IllegalStateException caused by
uninitalized `MediaPlayer` (flutter/packages#9861)
2025-08-22 [email protected] Roll Flutter from
d2ac021 to 26bb33b (20 revisions) (flutter/packages#9872)

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 [email protected] 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
mboetger pushed a commit to mboetger/flutter that referenced this pull request Sep 18, 2025
flutter/packages@092d832...fe66130

2025-08-23 [email protected] Roll Flutter from
26bb33b to edd434a (14 revisions) (flutter/packages#9874)
2025-08-23 [email protected] [google_maps_flutter_web] Fix
consumeTapEvents for Circles, Polygons & Polylines (flutter#173921)
(flutter/packages#9838)
2025-08-22 [email protected]
[interactive_media_ads] Fixes Android IllegalStateException caused by
uninitalized `MediaPlayer` (flutter/packages#9861)
2025-08-22 [email protected] Roll Flutter from
d2ac021 to 26bb33b (20 revisions) (flutter/packages#9872)

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 [email protected] 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
korca0220 pushed a commit to korca0220/flutter that referenced this pull request Sep 22, 2025
flutter/packages@092d832...fe66130

2025-08-23 [email protected] Roll Flutter from
26bb33b to edd434a (14 revisions) (flutter/packages#9874)
2025-08-23 [email protected] [google_maps_flutter_web] Fix
consumeTapEvents for Circles, Polygons & Polylines (flutter#173921)
(flutter/packages#9838)
2025-08-22 [email protected]
[interactive_media_ads] Fixes Android IllegalStateException caused by
uninitalized `MediaPlayer` (flutter/packages#9861)
2025-08-22 [email protected] Roll Flutter from
d2ac021 to 26bb33b (20 revisions) (flutter/packages#9872)

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 [email protected] 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
Jaineel-Mamtora pushed a commit to Jaineel-Mamtora/flutter_forked that referenced this pull request Sep 24, 2025
flutter/packages@092d832...fe66130

2025-08-23 [email protected] Roll Flutter from
26bb33b to edd434a (14 revisions) (flutter/packages#9874)
2025-08-23 [email protected] [google_maps_flutter_web] Fix
consumeTapEvents for Circles, Polygons & Polylines (flutter#173921)
(flutter/packages#9838)
2025-08-22 [email protected]
[interactive_media_ads] Fixes Android IllegalStateException caused by
uninitalized `MediaPlayer` (flutter/packages#9861)
2025-08-22 [email protected] Roll Flutter from
d2ac021 to 26bb33b (20 revisions) (flutter/packages#9872)

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 [email protected] 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
lucaantonelli pushed a commit to lucaantonelli/flutter that referenced this pull request Nov 21, 2025
flutter/packages@092d832...fe66130

2025-08-23 [email protected] Roll Flutter from
26bb33b to edd434a (14 revisions) (flutter/packages#9874)
2025-08-23 [email protected] [google_maps_flutter_web] Fix
consumeTapEvents for Circles, Polygons & Polylines (flutter#173921)
(flutter/packages#9838)
2025-08-22 [email protected]
[interactive_media_ads] Fixes Android IllegalStateException caused by
uninitalized `MediaPlayer` (flutter/packages#9861)
2025-08-22 [email protected] Roll Flutter from
d2ac021 to 26bb33b (20 revisions) (flutter/packages#9872)

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 [email protected] 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
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 p: interactive_media_ads Plugin for IMA SDK platform-android platform-ios

Projects

None yet

2 participants