Skip to content

[video_player] Complete dispose after a failed player creation - #13759

Open
a1rwulf wants to merge 1 commit into
flutter:mainfrom
a1rwulf:upstream_video-player-dispose-after-failed-create
Open

a1rwulf wants to merge 1 commit into
flutter:mainfrom
a1rwulf:upstream_video-player-dispose-after-failed-create

Conversation

@a1rwulf

@a1rwulf a1rwulf commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

VideoPlayerController.initialize() only completed its internal _creatingCompleter after createWithOptions returned. When creating the player throws, the completer was never completed, so a later dispose() awaited it forever: code after await controller.dispose() never ran, and the controller's ChangeNotifier and WidgetsBindingObserver were never disposed.

This happens with the endorsed iOS/macOS implementation for an asset that is not in the bundle, since video_player_avfoundation throws from createWithOptions in that case:

final controller = VideoPlayerController.asset('assets/missing.mp4');
await controller.initialize(); // throws PlatformException("Asset ... not found")
await controller.dispose();    // never completes

On Android creation succeeds for a missing asset and the error arrives later as a video event, so that path is not affected, but any implementation whose create call throws would be.

This PR completes the completer in a finally block, and skips the platform dispose call in dispose() when no player was created.

Tests:

  • A unit test with a platform whose createWithOptions throws checks that initialize() rethrows and dispose() completes without calling the platform dispose.
  • A new integration test, failed_initialize_test.dart, runs the code above with the real plugins. On the iOS simulator it fails without this change (dispose() has not completed after 10 seconds) and passes with it; it passes on Android both with and without it.

Fixes flutter/flutter#197204

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

initialize() only completed _creatingCompleter after createWithOptions
returned, so when creating the player threw, dispose() waited on it forever
and the lifecycle observer and ChangeNotifier were never disposed.

This happens with the endorsed iOS/macOS implementation for an asset that
is not in the bundle: video_player_avfoundation's createWithOptions throws
"Asset ... not found", so

  final controller = VideoPlayerController.asset('assets/missing.mp4');
  await controller.initialize(); // throws PlatformException
  await controller.dispose();    // never completes

On Android creation succeeds and the failure arrives later as an error
event, so that path was not affected.

The completer now completes in a finally block, and dispose() skips the
platform dispose when no player was created. The new integration test
fails on iOS without the fix (dispose times out) and passes on iOS and
Android with it.
@github-actions
github-actions Bot marked this pull request as draft November 23, 2026 08:43
@github-actions github-actions Bot added the waiting for response The Flutter team cannot make further progress on this PR until the author responds label Nov 23, 2026
@github-actions

Copy link
Copy Markdown

Hi @a1rwulf, thank you for your contribution!

This pull request has been converted to a draft because it does not appear to follow our pull request template:

  • Unchecked checklist items (3 of 11): All items in the Pre-Review Checklist must be completed and checked off (- [x]) before the PR can be reviewed:
    • - [ ] I read the [Contributor Guide] and followed the process outlined there for submitting PRs.
    • - [ ] I read the [Tree Hygiene] page, which explains my responsibilities.
    • - [ ] I updated/added any relevant documentation (doc comments with `///`).

How to fix this

  1. Click the ... menu in the top-right corner of your PR description above and select Edit.
  2. Address the issues listed above. Make sure every item in the Pre-Review Checklist is present without modifications and checked off (- [x]).
  3. Save your changes, then click the "Ready for review" button at the bottom of the PR.
Click here for the raw Markdown of the Pre-Review Checklist to copy and paste
## 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[^1].
- [ ] 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[^1].
- [ ] All existing and new tests are passing.

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](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.

<!-- Links -->
[Contributor Guide]: https://github.com/flutter/packages/blob/main/CONTRIBUTING.md
[AI contribution guidelines]: https://github.com/flutter/flutter/blob/master/CONTRIBUTING.ai.md#pull-requests
[Tree Hygiene]: https://github.com/flutter/flutter/blob/master/docs/contributing/Tree-hygiene.md
[relevant style guides]: https://github.com/flutter/packages/blob/main/CONTRIBUTING.md#style
[the auto-formatter]: https://github.com/flutter/packages/blob/main/script/tool/README.md#format-code
[CLA]: https://cla.developers.google.com/
[Discord]: https://github.com/flutter/flutter/blob/master/docs/contributing/Chat.md
[linked to at least one issue that this PR fixes]: https://github.com/flutter/flutter/blob/master/docs/contributing/Tree-hygiene.md#overview
[the version and CHANGELOG instructions]: https://github.com/flutter/flutter/blob/master/docs/ecosystem/contributing/README.md#version-and-changelog-updates
[semantic versioning]: https://dart.dev/tools/pub/versioning#semantic-versions
[repository CHANGELOG style]: https://github.com/flutter/flutter/blob/master/docs/ecosystem/contributing/README.md#changelog-style
[test exemption]: https://github.com/flutter/flutter/blob/master/docs/contributing/Tree-hygiene.md#tests

@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 package to version 2.14.2, ensuring that VideoPlayerController.dispose completes successfully even if initialize fails during player creation. This is achieved by wrapping the platform creation calls in a try-finally block to guarantee that _creatingCompleter completes, and by conditionally calling _videoPlayerPlatform.dispose only when a valid player ID exists. Additionally, integration and unit tests have been added to verify this behavior. There are no review comments, and I have no feedback to provide.

@a1rwulf
a1rwulf marked this pull request as ready for review November 23, 2026 10:22

@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 package to version 2.14.2. It ensures that VideoPlayerController.dispose completes even if native player creation fails during initialization. This is achieved by wrapping the player creation in a try-finally block to guarantee that _creatingCompleter completes, and by conditionally calling the platform dispose method only when a valid player ID is present. Unit and integration tests have been added to verify this behavior. There are no review comments, and I have no feedback to provide.

@github-actions github-actions Bot removed the waiting for response The Flutter team cannot make further progress on this PR until the author responds label Nov 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[video_player] dispose() never completes if initialize() fails to create the player

1 participant