Skip to content

[interactive_media_ads] Fixes Android IllegalStateException caused by uninitalized MediaPlayer - #9861

Merged
auto-submit[bot] merged 8 commits into
flutter:mainfrom
bparrishMines:catch_illegal_state
Aug 22, 2025
Merged

auto-submit[bot] merged 8 commits into
flutter:mainfrom
bparrishMines:catch_illegal_state

Conversation

@bparrishMines

@bparrishMines bparrishMines commented Aug 20, 2025 •

Copy link
Copy Markdown
Contributor

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
Copy Markdown
Contributor Author

/gemini review

@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 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.

@stuartmorgan-g stuartmorgan-g left a comment

Copy link
Copy Markdown
Collaborator

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
@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
creatorpiyush pushed a commit to creatorpiyush/packages that referenced this pull request Jun 10, 2026
… uninitalized `MediaPlayer` (flutter#9861)

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

**Note**: The Flutter team is currently trialing the use of [Gemini Code Assist for GitHub](https://developers.google.com/gemini-code-assist/docs/review-github-code). 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.

[^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.
Nakiha pushed a commit to Nakiha/VoidPlayer-Flutter that referenced this pull request Sep 28, 2026
flutter/packages@092d832...fe66130

2025-08-23 [email protected] Roll Flutter from
58e8a10 to 93a7c33 (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
27d34f2 to 58e8a10 (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