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

[video_player] fix Timer Leak #3119

Conversation

creativecreatorormaybenot
Copy link
Contributor

Description

Currently, when play is called twice, i.e. play is called again before pause, the _timer leaks, which can create very frequent calls of listener and more importantly will never stop notifying, even when the video is paused.

I would say that this is a pretty severe issue as calling play on a controller can easily happen more than once and should not have side effects.

Tests

I tried to add the following integration test:

testWidgets('cancels timers', (WidgetTester tester) async {
      await _controller.initialize();

      var eventCount = 0;
      final listener = () => eventCount++;
      _controller.addListener(listener);

      // Play for a second, then pause, and then wait a second.
      await _controller.play();
      // Call play twice to test if timers leak.
      await _controller.play();
      await tester.pumpAndSettle(_playDuration);

      final prePauseEventCount = eventCount;
      await _controller.pause();
      await tester.pumpAndSettle(_playDuration);

      // If timers were properly canceled, there should only be one new event
      // (from pausing). If timers were not canceled, there will be more events.
      expect(eventCount, prePauseEventCount + 1);

      _controller.removeListener(listener);
    }, skip: Platform.isIOS);

However, I was not able to get the existing integration tests to succeed, which is why I figured that this can do without a regression test for now.

Checklist

  • I read the Contributor Guide and followed the process outlined there for submitting PRs.
  • My PR includes unit or integration tests for all changed/updated/fixed behaviors (See Contributor Guide). (more below)
  • All existing and new tests are passing.
  • I updated/added relevant documentation (doc comments with ///).
  • The analyzer (flutter analyze) does not report any problems on my PR.
  • I read and followed the Flutter Style Guide.
  • The title of the PR starts with the name of the plugin surrounded by square brackets, e.g. [shared_preferences]
  • 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 signed the CLA.
  • I am willing to follow-up on review comments in a timely manner.

Breaking Change

Does your PR require plugin users to manually update their apps to accommodate your change?

  • No, this is not a breaking change.

@creativecreatorormaybenot
Copy link
Contributor Author

(I have the feeling that the failing smoke test has nothing to do with my PR)

Copy link
Member

@Ehesp Ehesp left a comment

Choose a reason for hiding this comment

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

LGTM - replicated & confirmed this fix works.

Copy link
Contributor

@iskakaushik iskakaushik left a comment

Choose a reason for hiding this comment

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

LGTM

@iskakaushik iskakaushik merged commit 454658b into flutter:master Oct 12, 2020
@creativecreatorormaybenot
Copy link
Contributor Author

@Ehesp @iskakaushik Thanks a lot for taking the time ❤

PS will the video_player update be pushed to Pub? I am just wondering as I know it is not automated for flutter/plugins.

blasten pushed a commit that referenced this pull request Oct 15, 2020
* Android Code Inspection and Clean up (#3117)

* [in_app_purchase] Android Code Inspection and Clean up (#3120)

* Android Code Inspection and Clean up

* Format

* [video_player] Fix SSLProtocolException for low API version (#3122)

* [camera] Set audio encoding bitrate when recording video (#3124)

Fixes flutter/flutter#38787

* Fix links in package example readmes (#3130)

http://flutter.io/ -> https://flutter.dev/

* [integration_test] Add watchPerformance (#3116)

* add watchPerformance

* [wifi_info_flutter] [wifi_info_flutter_platform_interface] Initial commit for `wifi_info_flutter` plugin and platform interface (#3129)

* [video_player] fix Timer Leak (#3119)

* [in_app_purchase] Add example test target to Podfile, add OCMock dependency (#3145)

* Add linux directory to examples (#3064)

When Linux support was added to these plugins, the app template wasn't
yet stabilized, so was not checked in. Now that it is stable, this adds
them so that the plugin_tools workaround that created them on each run
can be removed.

Other than CHANGELOG.md updates and updating the verison in
pubspec.yaml, this is purely the result of running 'flutter create .' in
the example/ folders and adding the resulting linux/ directories.

* [wifi_info_flutter_plugin_interface] implement wifi platform interface (#3134)

* [share] Replace deprecated Environment.getExternalStorageDirectory() call on Android. (#3152)

* Android API 29 & 30

* Update Version

* Update android sdk version to 29 for all mobile plugins. (#3042)

* [google_sign_in]  fix merge error in CHANGELOG (#3153)

Co-authored-by: Hamdi Kahloun <32666446+hamdikahloun@users.noreply.github.com>
Co-authored-by: Maurits van Beusekom <maurits@baseflow.com>
Co-authored-by: Kevin Moore <kevmoo@users.noreply.github.com>
Co-authored-by: Ming Lyu (CareF) <minglyu@google.com>
Co-authored-by: Maurice Parrish <bmparr@google.com>
Co-authored-by: creativecreatorormaybenot <creativecreatorormaybenot@gmail.com>
Co-authored-by: Jenn Magder <magder@google.com>
Co-authored-by: stuartmorgan <stuartmorgan@google.com>
Co-authored-by: Chris Yang <ychris@google.com>
FlutterSu pushed a commit to FlutterSu/flutter-plugins that referenced this pull request Nov 20, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants