Skip to content

[video_player_avfoundation] Add adaptive bitrate streaming support#11324

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

[video_player_avfoundation] Add adaptive bitrate streaming support#11324
sheershtehri7 wants to merge 1 commit intoflutter:mainfrom
sheershtehri7:abr-avfoundation

Conversation

@sheershtehri7
Copy link

Implements adaptive bitrate streaming support for the iOS/macOS video player.

Changes

  • setBandwidthLimit — Implements the platform interface method via AVPlayerItem.preferredPeakBitRate. A value of 0 tells AVFoundation to use its default (no cap), letting the player choose quality freely. Positive values limit the peak bitrate in bits per second.

This is the idiomatic AVFoundation approach — preferredPeakBitRate is a first-class property on AVPlayerItem that controls which HLS/DASH variant the player selects.

Versioned as 2.10.0 — minor version bump. Requires video_player_platform_interface ^6.7.0.

Depends on PR #11322 (platform interface setBandwidthLimit).

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 adds support for adaptive bitrate streaming on iOS and macOS by implementing the setBandwidthLimit method. This is achieved by setting the preferredPeakBitRate property on AVPlayerItem. The changes include updates to the Pigeon interface definition, the native Objective-C implementation, the Dart plugin code, and associated tests. One review comment has been added regarding error handling in the native implementation.

- (void)setBandwidthLimit:(NSInteger)maxBandwidthBps
error:(FlutterError *_Nullable __autoreleasing *_Nonnull)error {
AVPlayerItem *currentItem = _player.currentItem;
NSAssert(currentItem, @"currentItem should not be nil");

Choose a reason for hiding this comment

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

high

Using NSAssert is great for debugging, but it's disabled in release builds. If currentItem is nil in a release build, this method will silently do nothing, which could lead to unexpected behavior. It would be more robust to check for a nil currentItem and return an error, ensuring consistent behavior across build configurations.

if (!currentItem) {
  *error = [FlutterError errorWithCode:@"no_player_item"
                               message:@"The player has no current item."
                               details:nil];
  return;
}

Implements setBandwidthLimit via AVPlayerItem.preferredPeakBitRate.

A value of 0 removes the bandwidth cap, letting AVFoundation select
quality freely. Positive values limit the peak bitrate in bps.

Requires video_player_platform_interface ^6.7.0.
Part of flutter/flutter#183941
@stuartmorgan-g
Copy link
Collaborator

Closing per #11322 (comment)

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