Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
## NEXT
## 6.7.0

* Adds `setBandwidthLimit` and `isBandwidthLimitSupportAvailable` methods for adaptive bitrate streaming control.
* Updates minimum supported SDK version to Flutter 3.35/Dart 3.9.

## 6.6.0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,45 @@ abstract class VideoPlayerPlatform extends PlatformInterface {
bool isAudioTrackSupportAvailable() {
return false;
}

/// 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.');
}
Comment on lines +157 to +179

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;
  }


/// 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 for adaptive bitrate
/// streaming. This follows the same pattern as
/// [isAudioTrackSupportAvailable].
///
/// Returns `true` if [setBandwidthLimit] is supported, `false` otherwise.
///
/// The default implementation returns `false`. Platform implementations
/// should override this to return `true` if they support bandwidth limiting.
bool isBandwidthLimitSupportAvailable() {
return false;
}
}

class _PlaceholderImplementation extends VideoPlayerPlatform {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ repository: https://github.com/flutter/packages/tree/main/packages/video_player/
issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+video_player%22
# NOTE: We strongly prefer non-breaking changes, even at the expense of a
# less-clean API. See https://flutter.dev/go/platform-interface-breaking-changes
version: 6.6.0
version: 6.7.0

environment:
sdk: ^3.9.0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,21 @@ void main() {
test('default implementation isAudioTrackSupportAvailable returns false', () {
expect(initialInstance.isAudioTrackSupportAvailable(), false);
});

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

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);
  });


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