Repository navigation
Conversation
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.
|
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:
How to fix this
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 |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
VideoPlayerController.initialize()only completed its internal_creatingCompleteraftercreateWithOptionsreturned. When creating the player throws, the completer was never completed, so a laterdispose()awaited it forever: code afterawait controller.dispose()never ran, and the controller'sChangeNotifierandWidgetsBindingObserverwere never disposed.This happens with the endorsed iOS/macOS implementation for an asset that is not in the bundle, since
video_player_avfoundationthrows fromcreateWithOptionsin that case: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
finallyblock, and skips the platformdisposecall indispose()when no player was created.Tests:
createWithOptionsthrows checks thatinitialize()rethrows anddispose()completes without calling the platformdispose.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
[shared_preferences]///).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-assistbot 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
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