Skip to content

Conversation

@nateshmbhat
Copy link
Contributor

@nateshmbhat nateshmbhat commented Aug 29, 2025

Description

This PR adds comprehensive audio track retrieval and selection support to the video_player package, enabling developers to access detailed information about available audio tracks and switch between them during playback.

Breakout PRs:

  1. Platform interface : [video_player] Add audio track management support to platform interface #10171
  2. Andrioid : feat(android): add audio track selection for ExoPlayer #10312
  3. ios : feat(ios): add audio track selection support for AVFoundation #10313

Changes Made

Core Features

  • Added VideoAudioTrack model with comprehensive metadata fields: id, label, language, isSelected, bitrate, sampleRate, channelCount, codec
  • Added getAudioTracks() method to retrieve all available audio tracks with real metadata
  • Added selectAudioTrack() method to switch between audio tracks during playback
  • Updated VideoPlayerController to expose audio track functionality

Platform Implementations

  • Android:
    • Real metadata extraction using ExoPlayer's getCurrentTracks() API
    • Robust track selection using TrackSelectionOverride with proper error handling
    • Support for multiple audio formats (AAC, AC3, EAC3, MP3, etc.)
  • iOS:
    • Metadata extraction from AVFoundation using AVAssetTrack for regular videos
    • HLS stream support using AVMediaSelectionGroup for adaptive streams
    • Proper track selection for both asset tracks and media selection options

Technical Infrastructure

  • Updated Pigeon interfaces for both Android and iOS with new data structures:
    • AudioTrackMessage, ExoPlayerAudioTrackData, AssetAudioTrackData, MediaSelectionAudioTrackData, NativeAudioTrackData
  • Enhanced platform interface with new methods and data classes
  • Has native unit tests for both Android and iOS platforms
  • Created demo screen showcasing audio track functionality with interactive UI

Demo Features

  • Interactive video player with audio track selection
  • Real-time metadata display (bitrate, sample rate, channels, codec)
  • Support for multiple video sources including HLS streams
  • Visual indicators for currently selected tracks

Related Issues

Fixes flutter/flutter#59437

Testing

  • Added native unit tests for both Android and iOS
  • Tested with various video formats and HLS streams
  • Verified backward compatibility with existing functionality
  • Demo screen widget for manual testing and validation

Breaking Changes

None - all changes are additive and backward compatible.

Pre-Review Checklist

  • I read the [Contributor Guide] and followed the process outlined there for submitting PRs.
  • I read the [Tree Hygiene] page, which explains my responsibilities.
  • I read and followed the [relevant style guides] and ran [the auto-formatter].
  • I signed the [CLA].
  • The title of the PR starts with the name of the package surrounded by square brackets, e.g. [video_player]
  • I [linked to at least one issue that this PR fixes] in the description above.
  • I updated pubspec.yaml with an appropriate new version according to the [pub versioning philosophy], or I have commented below to indicate which [version change exemption] this PR falls under[^1].
  • I updated CHANGELOG.md to add a description of the change, [following repository CHANGELOG style], or I have commented below to indicate which [CHANGELOG exemption] this PR falls under[^1].
  • I updated/added any relevant documentation (doc comments with ///).
  • I added new tests to check the change I am making, or I have commented below to indicate which [test exemption] this PR falls under[^1].
  • All existing and new tests are passing.

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 introduces a valuable feature for fetching and selecting audio tracks in the video_player package. The changes are comprehensive, touching the platform interface, Android (ExoPlayer) and iOS (AVFoundation) implementations, and adding a new demo screen.

My review has identified several critical and high-severity issues that should be addressed:

  • The new native unit tests for both Android and iOS appear to be broken due to type mismatches and incorrect method calls, and will not compile in their current state.
  • The Dart implementation code for both Android and iOS contains unsafe null assertions on data coming from the native side, which could lead to runtime crashes.
  • The Android implementation has been updated to use a milestone version of Gradle, which is not recommended for production packages.
  • The new audio track selection feature has not been implemented for the web platform, which will lead to UnimplementedError on web.
  • There is a minor issue in the new example app where context is used after an await without checking if the widget is still mounted.

Addressing these points will significantly improve the robustness and completeness of this new feature.

@nateshmbhat
Copy link
Contributor Author

I updated native andorid tests and ran the tests and verified that all native android tests are passing.

@nateshmbhat
Copy link
Contributor Author

@stuartmorgan-g @ash2moon can you please comment on this PR and lemme know if there are any concerns ?

@stuartmorgan-g stuartmorgan-g added triage-ios Should be looked at in iOS triage triage-android Should be looked at in Android triage labels Sep 2, 2025
@nateshmbhat
Copy link
Contributor Author

native PRs are merged. I have removed the dependency overrides with the new version of the packages. anything else needed from my side ?

ivan-vanyusho pushed a commit to ivan-vanyusho/packages that referenced this pull request Jan 26, 2026
- Implemented getAudioTracks() and selectAudioTrack() methods for Android video player

Android PR for : flutter#9925

## Pre-Review Checklist
@isra60
Copy link

isra60 commented Jan 26, 2026

Is there any plans to support also subtitle (text) selection? And maybe styles of them?

@nateshmbhat nateshmbhat requested a review from ash2moon January 26, 2026 15:17
@camsim99 camsim99 removed the request for review from ash2moon January 26, 2026 15:39
@stuartmorgan-g stuartmorgan-g dismissed ash2moon’s stale review January 26, 2026 18:17

Changes addressed in sub-PR

@stuartmorgan-g stuartmorgan-g removed the triage-ios Should be looked at in iOS triage label Jan 26, 2026
) {
return VideoAudioTrack(
id: platformTrack.id,
label: platformTrack.label ?? 'Unknown',
Copy link
Collaborator

Choose a reason for hiding this comment

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

This comment has not been addressed. I don't think this is just a nit; the fact that this is making up placeholder values rather than returning null when nothing is available would be a breaking change to fix if shipped this way.

nateshmbhat and others added 4 commits January 27, 2026 16:55
Co-authored-by: LongCatIsLooong <31859944+LongCatIsLooong@users.noreply.github.com>
- Make VideoAudioTrack label and language nullable to match platform API
- Remove normalization of null values ('Unknown', 'und') in favor of nullable fields
- Update audio tracks demo to handle nullable fields properly
- Replace Exception with StateError for disposed/uninitialized controller states
- Improve listener cleanup and null safety in demo
- Add comment clarifying menu dismissal behavior
Copy link
Collaborator

@stuartmorgan-g stuartmorgan-g left a comment

Choose a reason for hiding this comment

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

Just minor comments left.

@tarrinneal please re-review the final state, since there have been changes.

import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:video_player_platform_interface/video_player_platform_interface.dart';
import 'package:video_player_platform_interface/video_player_platform_interface.dart'
Copy link
Collaborator

Choose a reason for hiding this comment

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

There should not be two imports of the same file with different prefixes. If we need prefixing, the other import needs to be removed.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

i think option here is to either replace every usage of all the classes that are used from platform interface with platform_interface. prefix or to rename the VideoAudioTrack to something else in video_player.dart to avoid the naming conflict. what would you prefer ? here's a summary of options we have.

Options for handling duplicate imports

Option 1: Keep both imports (current approach)

import 'package:video_player_platform_interface/video_player_platform_interface.dart';
import 'package:video_player_platform_interface/video_player_platform_interface.dart'
    as platform_interface;

Pros: Minimal code changes - use unprefixed types everywhere except where disambiguation is needed (platform_interface.VideoAudioTrack)
Cons: Two imports of the same file looks redundant
Option 2: Single prefixed import with show clause

import 'package:video_player_platform_interface/video_player_platform_interface.dart'
    as platform_interface show VideoAudioTrack, DataSource, ...;

Option 3: Rename the local VideoAudioTrack class
Rename to something like VideoAudioTrackInfo or AudioTrack to avoid the naming collision.

Pros: No duplicate imports; cleaner code
Cons: API change

Option 4: Use hide + prefixed show
dart
import 'package:video_player_platform_interface/video_player_platform_interface.dart'
hide VideoAudioTrack;
import 'package:video_player_platform_interface/video_player_platform_interface.dart'
as platform_interface show VideoAudioTrack;

…rminology

- Add blank lines after doc comment opening lines for better readability
- Change "exception" to "error" in documentation to match StateError usage
- Improve consistency in documentation style across VideoAudioTrack properties
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.

[video_player] Allow audio track selection

10 participants