Skip to content

[video_player] Issue 166411 preferred audio language support for player creation - #12152

Open
Zubii12 wants to merge 11 commits into
flutter:mainfrom
Zubii12:issue-166411-preferred-audio-language
Open

Zubii12 wants to merge 11 commits into
flutter:mainfrom
Zubii12:issue-166411-preferred-audio-language

Conversation

@Zubii12

@Zubii12 Zubii12 commented Jul 8, 2026

Copy link
Copy Markdown
Contributor

Adds preferredAudioLanguage to platform interface options and forwards it during player creation

Fixes flutter/flutter#166411

Pre-Review Checklist

If you need help, consider asking for advice on the #hackers-new channel on Discord.

Note: The Flutter team is currently trialing the use of Gemini Code Assist for GitHub. Comments from the gemini-code-assist bot should not be taken as authoritative feedback from the Flutter team. If you find its comments useful you can update your code accordingly, but if you are unsure or disagree with the feedback, please feel free to wait for a Flutter team member's review for guidance on which automated comments should be addressed.

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

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

Copy link
Copy Markdown
Contributor

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 support for configuring a preferred audio language during player creation via VideoPlayerOptions.preferredAudioLanguage across the video_player federated packages. The changes update the platform interface, forward the option during player initialization, and implement native track selection for Android (ExoPlayer) and iOS/macOS (AVFoundation). Unit tests and changelogs are updated accordingly. There are no review comments, so no additional feedback is provided.

@Zubii12
Zubii12 force-pushed the issue-166411-preferred-audio-language branch 4 times, most recently from ce1bb95 to 0db81a5 Compare July 10, 2026 18:15
@stuartmorgan-g stuartmorgan-g added the federated: all_changes PR that contains changes for all packages for a federated plugin change label Jul 14, 2026
@Zubii12
Zubii12 force-pushed the issue-166411-preferred-audio-language branch from 0db81a5 to 2b0f2e6 Compare July 14, 2026 20:42
@@ -1,3 +1,7 @@
## 2.14.0

* Forwards `VideoPlayerOptions.preferredAudioLanguage` during player creation so platform implementations can apply the preferred audio language per player instance.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

it doesn't seem like anything changed in this sub package, so a version bump and changelog aren't needed

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This still hasn't been addressed

@tarrinneal tarrinneal added triage-ios Should be looked at in iOS triage triage-android Should be looked at in Android triage labels Jul 15, 2026
@Zubii12
Zubii12 requested a review from tarrinneal July 15, 2026 09:03
@gmackall
gmackall requested a review from mboetger August 4, 2026 21:02
@hellohuanlin hellohuanlin added the CICD Run CI/CD label Aug 20, 2026
@flutter-dashboard

Copy link
Copy Markdown

This pull request is not mergeable in its current state, likely because of a merge conflict. Pre-submit CI jobs were not triggered. Pushing a new commit to this branch that resolves the issue will result in pre-submit jobs being scheduled.

@Zubii12
Zubii12 force-pushed the issue-166411-preferred-audio-language branch from 3a072a0 to 9c2b92e Compare August 25, 2026 16:12
@flutter-dashboard flutter-dashboard Bot removed the CICD Run CI/CD label Aug 25, 2026
@hellohuanlin

Copy link
Copy Markdown
Contributor

@Zubii12 could you resolve conflict and rebase?

@Zubii12
Zubii12 force-pushed the issue-166411-preferred-audio-language branch from 6b7dbbb to 84368c8 Compare September 29, 2026 09:50
@cbracken cbracken added the CICD Run CI/CD label Oct 1, 2026
@Zubii12
Zubii12 force-pushed the issue-166411-preferred-audio-language branch from 9ba3d43 to 68f1ec4 Compare October 3, 2026 11:48
@flutter-dashboard flutter-dashboard Bot removed the CICD Run CI/CD label Oct 3, 2026
@LouiseHsu

Copy link
Copy Markdown
Contributor

cc @hellohuanlin from triage!

hellohuanlin
hellohuanlin previously approved these changes Oct 11, 2026

@hellohuanlin hellohuanlin left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The iOS part LGTM

@vashworth vashworth removed the triage-ios Should be looked at in iOS triage label Oct 14, 2026
@Zubii12
Zubii12 force-pushed the issue-166411-preferred-audio-language branch from 68f1ec4 to 9e20c3c Compare October 19, 2026 10:35
Comment on lines 425 to +459
_isInitialized = YES;
[self selectPreferredAudioLanguage];
[self.eventListener videoPlayerDidInitializeWithDuration:self.duration
size:currentItem.presentationSize];
}

/// Selects the audio track whose locale language code matches self.preferredAudioLanguage.
/// Does nothing if preferredAudioLanguage is nil, the player is not yet initialized, or no
/// matching track is found.
- (void)selectPreferredAudioLanguage {
if (!self.preferredAudioLanguage || !_isInitialized) {
return;
}

NSString *preferredLanguage = self.preferredAudioLanguage;

AVPlayerItem *currentItem = _player.currentItem;
if (!currentItem) {
return;
}

AVMediaSelectionGroup *audioGroup =
[currentItem.asset mediaSelectionGroupForMediaCharacteristic:AVMediaCharacteristicAudible];
if (!audioGroup) {
return;
}

for (AVMediaSelectionOption *option in audioGroup.options) {
NSString *optionLanguageCode = option.locale.languageCode;
if (optionLanguageCode && [optionLanguageCode isEqualToString:preferredLanguage]) {
[currentItem selectMediaOption:option inMediaSelectionGroup:audioGroup];
break;
}
}
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

video_player_avfoundation on main has since migrated FVPVideoPlayer.m and pigeons/video_player_plugin_messages.dart to Swift (VideoPlayer.swift and pigeons/messages.dart), which is causing the merge conflict. When moving selectPreferredAudioLanguage into VideoPlayer.swift (inside reportInitialized() async), please use try await asset.loadMediaSelectionGroup(for: .audible) and check if disposed { return } after the await (matching selectAudioTrack(atIndex:)), since synchronous mediaSelectionGroup(forMediaCharacteristic:) is deprecated.

Comment on lines +452 to +458
for (AVMediaSelectionOption *option in audioGroup.options) {
NSString *optionLanguageCode = option.locale.languageCode;
if (optionLanguageCode && [optionLanguageCode isEqualToString:preferredLanguage]) {
[currentItem selectMediaOption:option inMediaSelectionGroup:audioGroup];
break;
}
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Comparing option.locale.languageCode with exact string equality only matches bare lowercase language subtags (e.g. "es"), so regional BCP-47 tags like "es-MX" or "pt-BR" (which ExoPlayer supports on Android) won't match because locale.languageCode strips region/script subtags.

Consider using AVMediaSelectionGroup.mediaSelectionOptions(from: audioGroup.options, filteredAndSortedAccordingToPreferredLanguages: [preferredLanguage]).first instead, which handles BCP-47 tags, regional fallback, and extendedLanguageTag automatically.


## 6.10.0

* Adds support for setting a preferred audio language during player creation via `VideoPlayerOptions preferredAudioLanguage`.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

## 6.10.0 should replace ## NEXT at the top of CHANGELOG.md (combining both bullets under ## 6.10.0), and VideoPlayerOptions preferredAudioLanguage is missing a dot (VideoPlayerOptions.preferredAudioLanguage).

Comment on lines 506 to +510
/// Ignored on platforms that do not support controlling the back buffer.
final int? backBufferDurationMs;

/// Preferred audio language for the video.
final String? preferredAudioLanguage;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Nit: Consider expanding the doc comment to mention the expected format (e.g. an ISO 639 / BCP-47 language tag like 'en' or 'es') and that the default audio track is used if no matching track is found or on platforms that do not support audio track selection (such as web).

@tarrinneal tarrinneal left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks for working on this! A couple of notes on native unit tests in files not touched by the diff:

  • packages/video_player/video_player_android/android/src/test/java/io/flutter/plugins/videoplayer/VideoPlayerTest.java: Since VideoPlayerPluginTest mocks PlatformViewVideoPlayer.create / TextureVideoPlayer.create statically, could we also add a unit test in VideoPlayerTest.java verifying that VideoPlayer updates exoPlayer.setTrackSelectionParameters(...) when options.preferredAudioLanguage is non-null?
  • packages/video_player/video_player_avfoundation/darwin/RunnerTests/VideoPlayerTests.swift: Please add a native unit test in darwin/RunnerTests/VideoPlayerTests.swift verifying that preferredAudioLanguage is passed to the native player and selects the matching audio option upon initialization.

@okorohelijah okorohelijah added the waiting for response The Flutter team cannot make further progress on this PR until the author responds label Nov 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

federated: all_changes PR that contains changes for all packages for a federated plugin change p: video_player platform-android platform-ios platform-macos platform-web triage-android Should be looked at in Android triage waiting for response The Flutter team cannot make further progress on this PR until the author responds

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[video_player] Add support for preferred audio language

9 participants