Repository navigation
Conversation
2afe303 to
b0a4aa6
Compare
There was a problem hiding this comment.
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.
ce1bb95 to
0db81a5
Compare
0db81a5 to
2b0f2e6
Compare
| @@ -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. | |||
There was a problem hiding this comment.
it doesn't seem like anything changed in this sub package, so a version bump and changelog aren't needed
There was a problem hiding this comment.
This still hasn't been addressed
|
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. |
3a072a0 to
9c2b92e
Compare
|
@Zubii12 could you resolve conflict and rebase? |
6b7dbbb to
84368c8
Compare
9ba3d43 to
68f1ec4
Compare
|
cc @hellohuanlin from triage! |
…orm API and players
…ferredAudioLanguage
68f1ec4 to
9e20c3c
Compare
| _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; | ||
| } | ||
| } | ||
| } |
There was a problem hiding this comment.
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.
| for (AVMediaSelectionOption *option in audioGroup.options) { | ||
| NSString *optionLanguageCode = option.locale.languageCode; | ||
| if (optionLanguageCode && [optionLanguageCode isEqualToString:preferredLanguage]) { | ||
| [currentItem selectMediaOption:option inMediaSelectionGroup:audioGroup]; | ||
| break; | ||
| } | ||
| } |
There was a problem hiding this comment.
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`. |
There was a problem hiding this comment.
## 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).
| /// Ignored on platforms that do not support controlling the back buffer. | ||
| final int? backBufferDurationMs; | ||
|
|
||
| /// Preferred audio language for the video. | ||
| final String? preferredAudioLanguage; |
There was a problem hiding this comment.
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
left a comment
There was a problem hiding this comment.
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: SinceVideoPlayerPluginTestmocksPlatformViewVideoPlayer.create/TextureVideoPlayer.createstatically, could we also add a unit test inVideoPlayerTest.javaverifying thatVideoPlayerupdatesexoPlayer.setTrackSelectionParameters(...)whenoptions.preferredAudioLanguageis non-null?packages/video_player/video_player_avfoundation/darwin/RunnerTests/VideoPlayerTests.swift: Please add a native unit test indarwin/RunnerTests/VideoPlayerTests.swiftverifying thatpreferredAudioLanguageis passed to the native player and selects the matching audio option upon initialization.
Adds preferredAudioLanguage to platform interface options and forwards it during player creation
Fixes flutter/flutter#166411
Pre-Review Checklist
[shared_preferences]///).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-assistbot 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
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