Skip to content

Commit 72bb14b

Browse files
committed
Add setBandwidthLimit to VideoPlayerPlatform
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
1 parent 8dcfd11 commit 72bb14b

4 files changed

Lines changed: 59 additions & 2 deletions

File tree

packages/video_player/video_player_platform_interface/CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
## NEXT
1+
## 6.7.0
22

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

56
## 6.6.0

packages/video_player/video_player_platform_interface/lib/video_player_platform_interface.dart

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,45 @@ abstract class VideoPlayerPlatform extends PlatformInterface {
153153
bool isAudioTrackSupportAvailable() {
154154
return false;
155155
}
156+
157+
/// Sets the maximum bandwidth limit for adaptive bitrate streaming.
158+
///
159+
/// This method controls which HLS/DASH variant streams are selected by
160+
/// limiting the maximum video bitrate the player will choose.
161+
///
162+
/// [playerId] identifies the video player instance.
163+
/// [maxBandwidthBps] is the maximum bandwidth in bits per second.
164+
/// Pass 0 or a negative value to remove the limit and allow the player
165+
/// to select quality freely.
166+
///
167+
/// Common bandwidth values:
168+
/// - 360p: 500000 bps (500 kbps)
169+
/// - 480p: 800000 bps (800 kbps)
170+
/// - 720p: 1200000 bps (1.2 Mbps)
171+
/// - 1080p: 2500000 bps (2.5 Mbps)
172+
///
173+
/// Platform-specific behavior:
174+
/// - **Android**: Uses ExoPlayer's `DefaultTrackSelector.setMaxVideoBitrate()`.
175+
/// - **iOS/macOS**: Sets `AVPlayerItem.preferredPeakBitRate`.
176+
/// - **Web**: Not implemented (throws [UnimplementedError]).
177+
Future<void> setBandwidthLimit(int playerId, int maxBandwidthBps) {
178+
throw UnimplementedError('setBandwidthLimit() has not been implemented.');
179+
}
180+
181+
/// Returns whether bandwidth limit setting is supported on this platform.
182+
///
183+
/// This method allows developers to query at runtime whether the current
184+
/// platform supports setting a bandwidth limit for adaptive bitrate
185+
/// streaming. This follows the same pattern as
186+
/// [isAudioTrackSupportAvailable].
187+
///
188+
/// Returns `true` if [setBandwidthLimit] is supported, `false` otherwise.
189+
///
190+
/// The default implementation returns `false`. Platform implementations
191+
/// should override this to return `true` if they support bandwidth limiting.
192+
bool isBandwidthLimitSupportAvailable() {
193+
return false;
194+
}
156195
}
157196

158197
class _PlaceholderImplementation extends VideoPlayerPlatform {}

packages/video_player/video_player_platform_interface/pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ repository: https://github.com/flutter/packages/tree/main/packages/video_player/
44
issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+video_player%22
55
# NOTE: We strongly prefer non-breaking changes, even at the expense of a
66
# less-clean API. See https://flutter.dev/go/platform-interface-breaking-changes
7-
version: 6.6.0
7+
version: 6.7.0
88

99
environment:
1010
sdk: ^3.9.0

packages/video_player/video_player_platform_interface/test/video_player_platform_interface_test.dart

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,4 +40,21 @@ void main() {
4040
test('default implementation isAudioTrackSupportAvailable returns false', () {
4141
expect(initialInstance.isAudioTrackSupportAvailable(), false);
4242
});
43+
44+
test(
45+
'default implementation setBandwidthLimit throws unimplemented',
46+
() async {
47+
await expectLater(
48+
() => initialInstance.setBandwidthLimit(1, 5000000),
49+
throwsUnimplementedError,
50+
);
51+
},
52+
);
53+
54+
test(
55+
'default implementation isBandwidthLimitSupportAvailable returns false',
56+
() {
57+
expect(initialInstance.isBandwidthLimitSupportAvailable(), false);
58+
},
59+
);
4360
}

0 commit comments

Comments
 (0)