Skip to content

Commit 6a387c9

Browse files
committed
refactor(video_player): change audio track selection to use track object 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
1 parent 4c47c2c commit 6a387c9

File tree

4 files changed

+34
-10
lines changed

4 files changed

+34
-10
lines changed

packages/video_player/video_player_platform_interface/CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
## 7.0.0
2+
3+
* **BREAKING CHANGE**: Refactors audio track identification system:
4+
* `VideoAudioTrack.id` (String) replaced with separate `groupIndex` (int) and `trackIndex` (int) properties.
5+
* `selectAudioTrack(int playerId, String trackId)` changed to `selectAudioTrack(int playerId, VideoAudioTrack track)` - now accepts the full track object instead of separate parameters.
6+
* This change provides better type safety and a more intuitive API for audio track selection.
7+
18
## 6.6.0
29

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

packages/video_player/video_player_platform_interface/lib/video_player_platform_interface.dart

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -134,8 +134,11 @@ abstract class VideoPlayerPlatform extends PlatformInterface {
134134
throw UnimplementedError('getAudioTracks() has not been implemented.');
135135
}
136136

137-
/// Selects which audio track is chosen for playback from its [trackId]
138-
Future<void> selectAudioTrack(int playerId, String trackId) {
137+
/// Selects which audio track is chosen for playback.
138+
///
139+
/// The [track] parameter should be one of the tracks returned by [getAudioTracks].
140+
/// Platform implementations will extract the necessary indices from the track object.
141+
Future<void> selectAudioTrack(int playerId, VideoAudioTrack track) {
139142
throw UnimplementedError('selectAudioTrack() has not been implemented.');
140143
}
141144

@@ -567,7 +570,8 @@ class VideoCreationOptions {
567570
class VideoAudioTrack {
568571
/// Constructs an instance of [VideoAudioTrack].
569572
const VideoAudioTrack({
570-
required this.id,
573+
required this.groupIndex,
574+
required this.trackIndex,
571575
required this.label,
572576
required this.language,
573577
required this.isSelected,
@@ -577,8 +581,11 @@ class VideoAudioTrack {
577581
this.codec,
578582
});
579583

580-
/// Unique identifier for the audio track.
581-
final String id;
584+
/// The group index of the audio track.
585+
final int groupIndex;
586+
587+
/// The track index within the group.
588+
final int trackIndex;
582589

583590
/// Human-readable label for the track.
584591
///
@@ -618,7 +625,8 @@ class VideoAudioTrack {
618625
return identical(this, other) ||
619626
other is VideoAudioTrack &&
620627
runtimeType == other.runtimeType &&
621-
id == other.id &&
628+
groupIndex == other.groupIndex &&
629+
trackIndex == other.trackIndex &&
622630
label == other.label &&
623631
language == other.language &&
624632
isSelected == other.isSelected &&
@@ -630,7 +638,8 @@ class VideoAudioTrack {
630638

631639
@override
632640
int get hashCode => Object.hash(
633-
id,
641+
groupIndex,
642+
trackIndex,
634643
label,
635644
language,
636645
isSelected,
@@ -643,7 +652,8 @@ class VideoAudioTrack {
643652
@override
644653
String toString() =>
645654
'VideoAudioTrack('
646-
'id: $id, '
655+
'groupIndex: $groupIndex, '
656+
'trackIndex: $trackIndex, '
647657
'label: $label, '
648658
'language: $language, '
649659
'isSelected: $isSelected, '

packages/video_player/video_player_platform_interface/pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ repository: https://github.com/flutter/packages/tree/main/packages/video_player/
44
issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+video_player%22
55
# NOTE: We strongly prefer non-breaking changes, even at the expense of a
66
# less-clean API. See https://flutter.dev/go/platform-interface-breaking-changes
7-
version: 6.6.0
7+
version: 7.0.0
88

99
environment:
1010
sdk: ^3.7.0

packages/video_player/video_player_platform_interface/test/video_player_platform_interface_test.dart

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,15 @@ void main() {
3030
test(
3131
'default implementation selectAudioTrack throws unimplemented',
3232
() async {
33+
const VideoAudioTrack track = VideoAudioTrack(
34+
groupIndex: 0,
35+
trackIndex: 0,
36+
label: 'Test',
37+
language: 'en',
38+
isSelected: false,
39+
);
3340
await expectLater(
34-
() => initialInstance.selectAudioTrack(1, 'trackId'),
41+
() => initialInstance.selectAudioTrack(1, track),
3542
throwsUnimplementedError,
3643
);
3744
},

0 commit comments

Comments
 (0)