Skip to content

[video_player_platform_interface] Add setBandwidthLimit for adaptive bitrate streaming#11322

Closed
sheershtehri7 wants to merge 1 commit intoflutter:mainfrom
sheershtehri7:abr-platform-interface
Closed

[video_player_platform_interface] Add setBandwidthLimit for adaptive bitrate streaming#11322
sheershtehri7 wants to merge 1 commit intoflutter:mainfrom
sheershtehri7:abr-platform-interface

Conversation

@sheershtehri7
Copy link

Adds setBandwidthLimit(int playerId, int maxBandwidthBps) to VideoPlayerPlatform for controlling the maximum video bitrate during HLS/DASH adaptive bitrate streaming.

The method allows platform implementations to limit the maximum video bitrate the player selects. Passing 0 or a negative value removes the limit. The default implementation throws UnimplementedError, following the established pattern for platform interface methods.

Versioned as 6.7.0 — minor version bump for new API surface.

Part of flutter/flutter#183941

AI Disclosure: This PR was developed with assistance from AI tools (GitHub Copilot / Claude). All code has been reviewed, tested, and validated by the author.

Pre-Review Checklist

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

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

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 introduces a setBandwidthLimit method to the VideoPlayerPlatform interface, complete with documentation and tests. The implementation is solid. My main suggestion is to enhance the API by adding a corresponding isBandwidthLimitSupportAvailable() method for runtime feature detection. This would align with existing patterns in the API, such as isAudioTrackSupportAvailable(), and provide a more robust way for developers to handle platform differences. I have included specific suggestions for adding this method, its test, and updating the changelog.

## NEXT
## 6.7.0

* Adds `setBandwidthLimit` method for adaptive bitrate streaming control.

Choose a reason for hiding this comment

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

medium

If you add the suggested isBandwidthLimitSupportAvailable method, please update this changelog entry to include it for completeness.

Suggested change
* Adds `setBandwidthLimit` method for adaptive bitrate streaming control.
* Adds `setBandwidthLimit` and `isBandwidthLimitSupportAvailable` methods for adaptive bitrate streaming control.

Comment on lines +157 to +179
/// Sets the maximum bandwidth limit for adaptive bitrate streaming.
///
/// This method controls which HLS/DASH variant streams are selected by
/// limiting the maximum video bitrate the player will choose.
///
/// [playerId] identifies the video player instance.
/// [maxBandwidthBps] is the maximum bandwidth in bits per second.
/// Pass 0 or a negative value to remove the limit and allow the player
/// to select quality freely.
///
/// Common bandwidth values:
/// - 360p: 500000 bps (500 kbps)
/// - 480p: 800000 bps (800 kbps)
/// - 720p: 1200000 bps (1.2 Mbps)
/// - 1080p: 2500000 bps (2.5 Mbps)
///
/// Platform-specific behavior:
/// - **Android**: Uses ExoPlayer's `DefaultTrackSelector.setMaxVideoBitrate()`.
/// - **iOS/macOS**: Sets `AVPlayerItem.preferredPeakBitRate`.
/// - **Web**: Not implemented (throws [UnimplementedError]).
Future<void> setBandwidthLimit(int playerId, int maxBandwidthBps) {
throw UnimplementedError('setBandwidthLimit() has not been implemented.');
}

Choose a reason for hiding this comment

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

medium

Consider adding a capability-check method isBandwidthLimitSupportAvailable() to allow developers to check for support at runtime. This follows the pattern of isAudioTrackSupportAvailable() and provides a cleaner API for developers than relying on catching an UnimplementedError.

This would make the API more robust and easier to use when building UIs that adapt to platform capabilities.

  /// Sets the maximum bandwidth limit for adaptive bitrate streaming.
  ///
  /// This method controls which HLS/DASH variant streams are selected by
  /// limiting the maximum video bitrate the player will choose.
  ///
  /// [playerId] identifies the video player instance.
  /// [maxBandwidthBps] is the maximum bandwidth in bits per second.
  /// Pass 0 or a negative value to remove the limit and allow the player
  /// to select quality freely.
  ///
  /// Common bandwidth values:
  ///   - 360p:  500000 bps (500 kbps)
  ///   - 480p:  800000 bps (800 kbps)
  ///   - 720p:  1200000 bps (1.2 Mbps)
  ///   - 1080p: 2500000 bps (2.5 Mbps)
  ///
  /// Platform-specific behavior:
  /// - **Android**: Uses ExoPlayer's `DefaultTrackSelector.setMaxVideoBitrate()`.
  /// - **iOS/macOS**: Sets `AVPlayerItem.preferredPeakBitRate`.
  /// - **Web**: Not implemented (throws [UnimplementedError]).
  Future<void> setBandwidthLimit(int playerId, int maxBandwidthBps) {
    throw UnimplementedError('setBandwidthLimit() has not been implemented.');
  }

  /// Returns whether bandwidth limit setting is supported on this platform.
  ///
  /// This method allows developers to query at runtime whether the current
  /// platform supports setting a bandwidth limit.
  ///
  /// Returns `true` if [setBandwidthLimit] is supported, `false` otherwise.
  ///
  /// The default implementation returns `false`. Platform implementations
  /// should override this to return `true` if they support setting a bandwidth limit.
  bool isBandwidthLimitSupportAvailable() {
    return false;
  }

Comment on lines +44 to +52
test(
'default implementation setBandwidthLimit throws unimplemented',
() async {
await expectLater(
() => initialInstance.setBandwidthLimit(1, 5000000),
throwsUnimplementedError,
);
},
);

Choose a reason for hiding this comment

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

medium

If you add the suggested isBandwidthLimitSupportAvailable method, please also add a test for its default implementation. This ensures test coverage for the new API surface.

  test(
    'default implementation setBandwidthLimit throws unimplemented',
    () async {
      await expectLater(
        () => initialInstance.setBandwidthLimit(1, 5000000),
        throwsUnimplementedError,
      );
    },
  );

  test('default implementation isBandwidthLimitSupportAvailable returns false', () {
    expect(initialInstance.isBandwidthLimitSupportAvailable(), false);
  });

@sheershtehri7
Copy link
Author

sheershtehri7 commented Mar 22, 2026

ABR PR Chain

This is the first of 4 PRs adding adaptive bitrate streaming support to video_player. Merge order:

  1. [video_player_platform_interface] Add setBandwidthLimit for adaptive bitrate streaming #11322video_player_platform_interface (this PR) — adds setBandwidthLimit API
  2. [video_player_android] Add adaptive bitrate streaming support #11323video_player_android — ExoPlayer implementation
  3. [video_player_avfoundation] Add adaptive bitrate streaming support #11324video_player_avfoundation — AVFoundation implementation (can merge in parallel with [video_player_android] Add adaptive bitrate streaming support #11323)
  4. [video_player] Add adaptive bitrate streaming support #11325video_player — app-facing API + AdaptiveBitrateManager

Tracking issue: flutter/flutter#183941
Design doc: https://docs.google.com/document/d/1g3RSytVLgWtheZO1ZFKvSfpFjh2_GstLv4SIwJMmYdw/edit?usp=sharing

Adds a new setBandwidthLimit(int playerId, int maxBandwidthBps) method
to VideoPlayerPlatform for adaptive bitrate streaming control.

This method allows platform implementations to limit the maximum
video bitrate the player selects during HLS/DASH playback.

Part of flutter/flutter#183941
@sheershtehri7 sheershtehri7 force-pushed the abr-platform-interface branch from b5007ac to 72bb14b Compare March 22, 2026 09:09
@stuartmorgan-g
Copy link
Collaborator

Please see https://github.com/flutter/flutter/blob/master/docs/ecosystem/contributing/README.md#changing-federated-plugins for our process for changing plugins. Once the design doc has been reviewed and approved (which hasn't happened yet) the first step for review is step one in that process, not steps three through five.

I'm closing these individual PRs for now, as they should not be created at this stage.

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.

2 participants