[video_player_platform_interface] Add setBandwidthLimit for adaptive bitrate streaming#11322
[video_player_platform_interface] Add setBandwidthLimit for adaptive bitrate streaming#11322sheershtehri7 wants to merge 1 commit intoflutter:mainfrom
Conversation
There was a problem hiding this comment.
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. |
There was a problem hiding this comment.
If you add the suggested isBandwidthLimitSupportAvailable method, please update this changelog entry to include it for completeness.
| * Adds `setBandwidthLimit` method for adaptive bitrate streaming control. | |
| * Adds `setBandwidthLimit` and `isBandwidthLimitSupportAvailable` methods for adaptive bitrate streaming control. |
| /// 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.'); | ||
| } |
There was a problem hiding this comment.
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;
}| test( | ||
| 'default implementation setBandwidthLimit throws unimplemented', | ||
| () async { | ||
| await expectLater( | ||
| () => initialInstance.setBandwidthLimit(1, 5000000), | ||
| throwsUnimplementedError, | ||
| ); | ||
| }, | ||
| ); |
There was a problem hiding this comment.
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);
});
ABR PR ChainThis is the first of 4 PRs adding adaptive bitrate streaming support to
Tracking issue: flutter/flutter#183941 |
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
b5007ac to
72bb14b
Compare
|
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. |
Adds
setBandwidthLimit(int playerId, int maxBandwidthBps)toVideoPlayerPlatformfor 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
0or a negative value removes the limit. The default implementation throwsUnimplementedError, 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
[shared_preferences]///).Footnotes
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