Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions packages/video_player/video_player/lib/video_player.dart
Original file line number Diff line number Diff line change
Expand Up @@ -857,6 +857,28 @@ class VideoPlayerController extends ValueNotifier<VideoPlayerValue> {
}
}

/// Returns whether audio track selection is supported on this platform.
///
/// This method allows developers to query at runtime whether the current
/// platform supports audio track selection functionality. This is useful
/// for platforms like web where audio track selection may not be available.
///
/// Returns `true` if [getAudioTracks] and [selectAudioTrack] are supported,
/// `false` otherwise.
///
/// Example usage:
/// ```dart
/// if (await controller.isAudioTrackSupportAvailable()) {
/// final tracks = await controller.getAudioTracks();
/// // Show audio track selection UI
/// } else {
/// // Hide audio track selection UI or show unsupported message
/// }
/// ```
Future<bool> isAudioTrackSupportAvailable() async {
return _videoPlayerPlatform.isAudioTrackSupportAvailable();
}

bool get _isDisposedOrNotInitialized => _isDisposed || !value.isInitialized;
}

Expand Down
12 changes: 12 additions & 0 deletions packages/video_player/video_player/test/video_player_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,12 @@ class FakeController extends ValueNotifier<VideoPlayerValue>
selectedAudioTrackId = trackId;
}

@override
Future<bool> isAudioTrackSupportAvailable() async {
// Return true for testing purposes
return true;
}

String? selectedAudioTrackId;
}

Expand Down Expand Up @@ -1852,5 +1858,11 @@ class FakeVideoPlayerPlatform extends VideoPlayerPlatform {
selectedAudioTrackIds[playerId] = trackId;
}

@override
Future<bool> isAudioTrackSupportAvailable() async {
calls.add('isAudioTrackSupportAvailable');
return true; // Return true for testing purposes
}

final Map<int, String> selectedAudioTrackIds = <int, String>{};
}
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,12 @@ class AndroidVideoPlayer extends VideoPlayerPlatform {
return _playerWith(id: playerId).selectAudioTrack(trackId);
}

@override
Future<bool> isAudioTrackSupportAvailable() async {
// Android with ExoPlayer supports audio track selection
return true;
}

_PlayerInstance _playerWith({required int id}) {
final _PlayerInstance? player = _players[id];
return player ?? (throw StateError('No active player with ID $id.'));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,12 @@ class AVFoundationVideoPlayer extends VideoPlayerPlatform {
return _playerWith(id: playerId).selectAudioTrack(trackId);
}

@override
Future<bool> isAudioTrackSupportAvailable() async {
// iOS/macOS with AVFoundation supports audio track selection
return true;
}

@override
Widget buildView(int playerId) {
return buildViewWithOptions(VideoViewOptions(playerId: playerId));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,18 @@ abstract class VideoPlayerPlatform extends PlatformInterface {
Future<void> selectAudioTrack(int playerId, String trackId) {
throw UnimplementedError('selectAudioTrack() has not been implemented.');
}

/// Returns whether audio track selection is supported on this platform.
///
/// This method allows developers to query at runtime whether the current
/// platform supports audio track selection functionality. This is useful
/// for platforms like web where audio track selection may not be available.
///
/// Returns `true` if [getAudioTracks] and [selectAudioTrack] are supported,
/// `false` otherwise.
Future<bool> isAudioTrackSupportAvailable() {
throw UnimplementedError('isAudioTrackSupportAvailable() has not been implemented.');
}
}

class _PlaceholderImplementation extends VideoPlayerPlatform {}
Expand Down
4 changes: 4 additions & 0 deletions packages/video_player/video_player_web/example/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,7 @@ dev_dependencies:
sdk: flutter
integration_test:
sdk: flutter
# FOR TESTING AND INITIAL REVIEW ONLY. DO NOT MERGE.
# See https://github.com/flutter/flutter/blob/master/docs/ecosystem/contributing/README.md#changing-federated-plugins
dependency_overrides:
video_player_platform_interface: {path: ../../../../packages/video_player/video_player_platform_interface}
18 changes: 18 additions & 0 deletions packages/video_player/video_player_web/lib/video_player_web.dart
Original file line number Diff line number Diff line change
Expand Up @@ -170,4 +170,22 @@ class VideoPlayerPlugin extends VideoPlayerPlatform {
/// Sets the audio mode to mix with other sources (ignored).
@override
Future<void> setMixWithOthers(bool mixWithOthers) => Future<void>.value();

@override
Future<List<VideoAudioTrack>> getAudioTracks(int playerId) async {
// Web platform does not support audio track selection
throw UnimplementedError('getAudioTracks() is not supported on web');
}

@override
Future<void> selectAudioTrack(int playerId, String trackId) async {
// Web platform does not support audio track selection
throw UnimplementedError('selectAudioTrack() is not supported on web');
}

@override
Future<bool> isAudioTrackSupportAvailable() async {
// Web platform does not support audio track selection
return false;
}
}
4 changes: 4 additions & 0 deletions packages/video_player/video_player_web/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,7 @@ dev_dependencies:
topics:
- video
- video-player
# FOR TESTING AND INITIAL REVIEW ONLY. DO NOT MERGE.
# See https://github.com/flutter/flutter/blob/master/docs/ecosystem/contributing/README.md#changing-federated-plugins
dependency_overrides:
video_player_platform_interface: {path: ../../../packages/video_player/video_player_platform_interface}