Skip to content
This repository was archived by the owner on Feb 22, 2023. It is now read-only.

[video_player]fix video play() not update VideoPlayerValue when isInitialized is false #4295

Conversation

jerryzhoujw
Copy link
Contributor

@jerryzhoujw jerryzhoujw commented Sep 1, 2021

Before VideoPlayerController.initialize() finished.
Client maybe call VideoPlayerController.play().
It's better to notify the VideoPlayerValue to client.

To make this work:

  Future<void> play() async {
    if (value.position == value.duration) {
      await seekTo(const Duration());              // <--- so seeTo() need to avoid exception before initialize() finished. 
    }
    value = value.copyWith(isPlaying: true);  // <--- this value better to update and notify. so 
    await _applyPlayPause();
  }

The exception on my android devices is:

  PlatformException (PlatformException(NullPointerException, java.lang.NullPointerException: Attempt to invoke virtual method 'void io.flutter.plugins.videoplayer.VideoPlayer.seekTo(int)' on a null object reference, null, null))

List which issues are fixed by this PR. You must list at least one issue.

flutter/flutter#89259

Pre-launch Checklist

  • I read the Contributor Guide and followed the process outlined there for submitting PRs.
  • I read the Tree Hygiene wiki page, which explains my responsibilities.
  • I read and followed the relevant style guides and ran the auto-formatter. (Note that unlike the flutter/flutter repo, the flutter/plugins repo does use dart format.)
  • I signed the CLA.
  • The title of the PR starts with the name of the plugin surrounded by square brackets, e.g. [shared_preferences]
  • I listed at least one issue that this PR fixes in the description above.
  • I updated pubspec.yaml with an appropriate new version according to the pub versioning philosophy.
  • I updated CHANGELOG.md to add a description of the change.
  • I updated/added relevant documentation (doc comments with ///).
  • I added new tests to check the change I am making or feature I am adding, or Hixie said the PR is test exempt.
  • All existing and new tests are passing.

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

Copy link
Contributor

@stuartmorgan stuartmorgan left a comment

Choose a reason for hiding this comment

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

Thanks for the submission! I've left an initial review comment, but this will also need the missing items in the checklist addressed before moving forward.


try {
await _videoPlayerPlatform.seekTo(_textureId, position);
} catch (e) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Silently discarding all exceptions is not a fix, it's hiding the problem—and a variety of other possible problems as well, which is not okay.

seekTo isn't doing the same up-front isInitialized check that other methods are doing, which seems like the actual bug here. It looks like this flow throwing is a regression from #3727 (@cc @KyleFin)

Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks @stuartmorgan! Yes, this issue was mentioned in #3727 (comment). @jerryzhoujw let me know if there's anything I can do to help. Thanks!

Copy link
Contributor

Choose a reason for hiding this comment

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

Instead of this change I believe you could just change line 397 to be
if (value.position == value.duration && value.isInitialized) {

Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks

Copy link
Contributor Author

Choose a reason for hiding this comment

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

close this since #4300 much better.

@jerryzhoujw
Copy link
Contributor Author

close this since #4300 much better.

@jerryzhoujw jerryzhoujw closed this Sep 2, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants