Skip to content

Conversation

@nateshmbhat
Copy link
Contributor

@nateshmbhat nateshmbhat commented Nov 7, 2025

feat(video_player_platform_interface): refactor audio track API to use track objects

Summary

Refactors the audio track identification and selection API to use separate groupIndex and trackIndex integers instead of encoded string IDs, and updates selectAudioTrack to accept a VideoAudioTrack object for improved type safety and developer experience.

Breaking Changes

Version: 7.0.0 (major version bump)

1. VideoAudioTrack Structure Change

Before:

class VideoAudioTrack {
  final String id;  // Encoded as "groupIndex_trackIndex"
  final String label;
  final String language;
  // ...
}

Motivation :
The previous string-based track ID system had several issues:

Lack of Type Safety: String encoding/decoding of track indices was error-prone
Poor Developer Experience: Required developers to manually construct or parse track IDs
Platform Inconsistency: Different platforms (ExoPlayer vs AVFoundation) handle track groups differently, but this was hidden in string encoding
Unintuitive API: Users had to remember the format and construction of track IDs

Interface Breakout PR From : #9925

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. [shared_preferences]
  • 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.

feat(video_player): add platform check for audio track selection support
- Added new data classes for audio track management (PlaybackState, AudioTrackMessage, ExoPlayerAudioTrackData, NativeAudioTrackData)
- Implemented getAudioTracks() and selectAudioTrack() methods in VideoPlayerInstanceApi
- Fixed Map comparison in deepEquals to use containsKey instead of contains
- Added message codec handling for new audio track data classes
- Updated Android video player implementation to support audio track selection
- Updated video_player_platform_interface dependency from ^6.3.0 to ^6.6.0 across all video_player packages
- Removed temporary dependency_overrides for video_player_platform_interface that were used for testing
- Reformatted dependency override paths for better readability in remaining overrides
- Reduced sample video URLs from 3 to 2 by removing redundant examples
- Changed primary video source to flutter.github.io butterfly video for better reliability
- Simplified audio track data construction in Android native code by using direct constructor instead of builder pattern
- Fixed code formatting and line wrapping in audio tracks demo UI
- Removed unnecessary builder pattern usage in NativeAudioTrackData creation
- Removed fully qualified class names (Messages.ExoPlayerAudioTrackData) in favor of direct class names for better readability
- Updated getter method name from getIsSelected() to isSelected() to follow Java boolean getter conventions
- Maintained same test coverage and assertions while making code more concise
- No functional changes to the test behavior or validation logic
- Upgraded video_player_platform_interface dependency from ^6.4.0 to ^6.6.0 in video_player_web package
- Maintains compatibility with web platform support while incorporating latest interface updates
…he code formatting changes:

style(video_player): improve code formatting and line wrapping

- Fixed line wrapping and indentation in audio_tracks_demo.dart for better readability
- Simplified import statements and removed fully qualified class names in AudioTracksTest.java
- Improved code formatting and line breaks in avfoundation_video_player files
- Adjusted indentation and line breaks in example files to follow consistent style
feat(video): improve audio track selection handling

- Removed manual delay for Android track selection and implemented event-based completion tracking
- Added AudioTrackChangedEvent to notify when selected audio track changes
- Enhanced ExoPlayerEventListener to detect and report audio track changes
- Added timeout handling for audio track selection to prevent indefinite waits
- Updated message codecs and interfaces to support new audio track change
- Added caching for audio selection options to avoid repeated media group queries
- Simplified current audio track selection by using direct item method
- Optimized selectAudioTrack to use cached options instead of re-fetching media group
- Added cleanup of cached options in dispose method to prevent memory leaks
- Simplified mock format descriptions in VideoPlayerTests to prevent Core Media crashes
- Removed unnecessary mock format description setup that could cause test instability
- Updated format description validation to only accept genuine Core Media objects, removing NSObject fallback
- Fixed potential crash when accessing format descriptions in test environment
…S compatibility

- Added macOS 10.13 availability check alongside iOS 11.0
- Updated to use currentMediaSelection property instead of deprecated selectedMediaOptionInMediaSelectionGroup method
- Changed VideoAudioTrack to use groupIndex and trackIndex instead of a single string ID
- Updated selectAudioTrack to accept VideoAudioTrack object instead of string trackId
- Modified UI to display track indices in format "Track {groupIndex}_{trackIndex}"
…ect instead of ID

- Modified selectAudioTrack to accept VideoAudioTrack object instead of string trackId
- Replaced single id field with groupIndex and trackIndex integers in VideoAudioTrack
- Updated equality, hashCode, and toString methods to reflect new track identification structure
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 refactors the audio track API for the video_player_platform_interface package. It introduces a VideoAudioTrack class that uses groupIndex and trackIndex integers for track identification, replacing the previous string-based ID. The selectAudioTrack method is updated to accept a VideoAudioTrack object, improving type safety. This is a breaking change, reflected by a major version bump to 7.0.0. The CHANGELOG.md and tests have been updated accordingly.

Comment on lines +1 to 10
## 7.0.0

* **BREAKING CHANGE**: Refactors audio track identification system:
* `VideoAudioTrack.id` (String) replaced with separate `groupIndex` (int) and `trackIndex` (int) properties.
* `selectAudioTrack(int playerId, String trackId)` changed to `selectAudioTrack(int playerId, VideoAudioTrack track)` - now accepts the full track object instead of separate parameters.
* This change provides better type safety and a more intuitive API for audio track selection.

## 6.6.0

* Adds `VideoAudioTrack` class and `getAudioTracks()`, `selectAudioTrack()`, `isAudioTrackSupportAvailable()` methods for audio track management.

Choose a reason for hiding this comment

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

medium

The current changelog is a bit confusing as it introduces a feature in a 6.6.0 entry and then immediately describes a breaking refactor of it in the 7.0.0 entry. Assuming 6.6.0 was not released, it would be clearer to combine these into a single entry for 7.0.0 that describes the audio track selection feature as it is being introduced in its final form. This will provide better clarity for users reading the release notes.

Suggested change
## 7.0.0
* **BREAKING CHANGE**: Refactors audio track identification system:
* `VideoAudioTrack.id` (String) replaced with separate `groupIndex` (int) and `trackIndex` (int) properties.
* `selectAudioTrack(int playerId, String trackId)` changed to `selectAudioTrack(int playerId, VideoAudioTrack track)` - now accepts the full track object instead of separate parameters.
* This change provides better type safety and a more intuitive API for audio track selection.
## 6.6.0
* Adds `VideoAudioTrack` class and `getAudioTracks()`, `selectAudioTrack()`, `isAudioTrackSupportAvailable()` methods for audio track management.
## 7.0.0
* **BREAKING CHANGE**: Adds support for audio track selection.
* Adds the `VideoAudioTrack` class, `getAudioTracks()`, `selectAudioTrack()`, and `isAudioTrackSupportAvailable()` methods for audio track management.
* `VideoAudioTrack` uses `groupIndex` and `trackIndex` integers for identification.
* `selectAudioTrack` accepts a `VideoAudioTrack` object for improved type safety.

@nateshmbhat nateshmbhat closed this Nov 7, 2025
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