Skip to content

[video_player]: reduce video player position update interval from 500ms to 100ms #8346

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Conversation

abdelaziz-mahdy
Copy link
Contributor

@abdelaziz-mahdy abdelaziz-mahdy commented Dec 26, 2024

Description
reduce video player position update interval from 500ms to 100ms to fix the issue of fast captions not showing for their intended time

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

Pre-launch Checklist

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

@stuartmorgan-g
Copy link
Contributor

Per discussion linked from flutter/flutter#90080 (comment) I'm skeptical that this is API we want to add. If subtitles don't work reliably at the current update frequency, and higher update frequencies don't have noticeable performance impact, then we should simply increase the frequency. If it does have performance issues, then we should figure out a different way of triggering subtitle changes. Either way, I would expect that we should be able to resolve the issue without new public API and without requiring extra configuration.

@abdelaziz-mahdy
Copy link
Contributor Author

I kept searching for the previous discussions but couldn't find them. Thank you for providing the link.

Would an update frequency of 100ms work? I think it would be very effective for subtitles and not frequent enough to cause a high load on devices.

if you agree, i can open a new pr with that change and add a test to make sure captions are included in the timer consideration

@abdelaziz-mahdy
Copy link
Contributor Author

note: this is how i override it from the app side, i didnt like the approach this is why i opened this pr

  void startPositionUpdaterForcer() {
    _positionUpdaterForcerTimer?.cancel();
    _positionUpdaterForcerTimer =
        Timer.periodic(Duration(milliseconds: 100), (timer) {
      _positionUpdaterForcer();
    });
  }

  void stopPositionUpdaterForcer() {
    _positionUpdaterForcerTimer?.cancel();
  }
  /// These parts exists in the video_player package but slightly edited to be called from outside of the class
  Future<void> _positionUpdaterForcer() async {
    Duration? position = await controller.position;
    if (position == null) {
      return;
    }
    VideoPlayerValue value = controller.value;
    if (position > value.duration) {
      position = value.duration;
    }
    value = value.copyWith(
      position: position,
      caption: await _getCaptionAt(position),
      isCompleted: position == value.duration,
    );
  }

  Future<Caption> _getCaptionAt(Duration position) async {
    /// the internal [ClosedCaptionFile]
    ClosedCaptionFile? closedCaptionFile;
    closedCaptionFile = await controller.closedCaptionFile;
    if (closedCaptionFile == null) {
      return Caption.none;
    }

    VideoPlayerValue value = controller.value;
    final Duration delayedPosition = position + value.captionOffset;
    // TODO(johnsonmh): This would be more efficient as a binary search.
    for (final Caption caption in (closedCaptionFile).captions) {
      if (caption.start <= delayedPosition && caption.end >= delayedPosition) {
        return caption;
      }
    }

    return Caption.none;
  }

@abdelaziz-mahdy
Copy link
Contributor Author

i updated the pr to be an update to value from 500 to 100 ms, and the test case. hope thats okay

@abdelaziz-mahdy abdelaziz-mahdy changed the title [video_player]: add setVideoPositionUpdatesInterval method to allow setting position updates periodic intervals [video_player]: reduce video player position update interval from 500ms to 100ms Dec 28, 2024
@stuartmorgan-g stuartmorgan-g self-requested a review January 21, 2025 20:55
await intervalUpdateCompleter.future.timeout(const Duration(seconds: 5));

// Verify that the intervals between updates are approximately correct
expect(positions[1] - positions[0], greaterThanOrEqualTo(customInterval));
Copy link
Contributor

Choose a reason for hiding this comment

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

Wouldn't this test as written pass without the rest of the PR?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

just tested using 500 ms for the updates and it failed, but i will add another test related to the captions since its the more related to this pr

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I added the other test and I hope its shows the problem more, let me know if there anything else I can fix.

Thank you.

Copy link
Contributor

@stuartmorgan-g stuartmorgan-g left a comment

Choose a reason for hiding this comment

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

LGTM with one change. @tarrinneal for second review.

Copy link
Contributor

@tarrinneal tarrinneal left a comment

Choose a reason for hiding this comment

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

lgtm, with some clarity in the changelog.

@stuartmorgan-g stuartmorgan-g added the autosubmit Merge PR when tree becomes green via auto submit App label Mar 18, 2025
Copy link
Contributor

auto-submit bot commented Mar 18, 2025

autosubmit label was removed for flutter/packages/8346, because - The status or check suite Linux dart_unit_test_shard_1 master has failed. Please fix the issues identified (or deflake) before re-applying this label.

@auto-submit auto-submit bot removed the autosubmit Merge PR when tree becomes green via auto submit App label Mar 18, 2025
@stuartmorgan-g
Copy link
Contributor

This is hitting the known camerax flake; it's unrelated to the PR.

@stuartmorgan-g stuartmorgan-g added the autosubmit Merge PR when tree becomes green via auto submit App label Mar 18, 2025
@auto-submit auto-submit bot merged commit a1c3689 into flutter:main Mar 18, 2025
82 checks passed
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Mar 19, 2025
github-merge-queue bot pushed a commit to flutter/flutter that referenced this pull request Mar 19, 2025
flutter/packages@d450e1b...dd781d4

2025-03-19 robert.odrowaz@leancode.pl [camera_avfoundation] Tests
backfilling - part 4 (flutter/packages#8854)
2025-03-18 robert.odrowaz@leancode.pl [camera_avfoundation] Tests
backfilling - part 5 (flutter/packages#8873)
2025-03-18 zezohassam@gmail.com [video_player]: reduce video player
position update interval from 500ms to 100ms (flutter/packages#8346)
2025-03-18 joonas.kerttula@codemate.com [google_maps_flutter] Support
for Ground Overlay (flutter/packages#8432)
2025-03-18 joonas.kerttula@codemate.com [google_maps_flutter] Ground
overlay support - platform impls (flutter/packages#8563)

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 flutter-ecosystem@google.com 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
androidseb pushed a commit to androidseb/packages that referenced this pull request Jun 8, 2025
…ms to 100ms (flutter#8346)

Description
reduce video player position update interval from 500ms to 100ms to fix the issue of fast captions not showing for their intended time

*List which issues are fixed by this PR. You must list at least one issue.*
flutter/flutter#160855
zhangyuang pushed a commit to zhangyuang/flutter-fork that referenced this pull request Jun 9, 2025
…r#165489)

flutter/packages@d450e1b...dd781d4

2025-03-19 robert.odrowaz@leancode.pl [camera_avfoundation] Tests
backfilling - part 4 (flutter/packages#8854)
2025-03-18 robert.odrowaz@leancode.pl [camera_avfoundation] Tests
backfilling - part 5 (flutter/packages#8873)
2025-03-18 zezohassam@gmail.com [video_player]: reduce video player
position update interval from 500ms to 100ms (flutter/packages#8346)
2025-03-18 joonas.kerttula@codemate.com [google_maps_flutter] Support
for Ground Overlay (flutter/packages#8432)
2025-03-18 joonas.kerttula@codemate.com [google_maps_flutter] Ground
overlay support - platform impls (flutter/packages#8563)

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 flutter-ecosystem@google.com 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
FMorschel pushed a commit to FMorschel/packages that referenced this pull request Jun 9, 2025
…ms to 100ms (flutter#8346)

Description
reduce video player position update interval from 500ms to 100ms to fix the issue of fast captions not showing for their intended time

*List which issues are fixed by this PR. You must list at least one issue.*
flutter/flutter#160855
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: video_player
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants