-
Notifications
You must be signed in to change notification settings - Fork 3.5k
feat(video_player): add audio track management support to platform interface #10171
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -121,6 +121,30 @@ abstract class VideoPlayerPlatform extends PlatformInterface { | |
Future<void> setWebOptions(int playerId, VideoPlayerWebOptions options) { | ||
throw UnimplementedError('setWebOptions() has not been implemented.'); | ||
} | ||
|
||
/// Gets the available audio tracks for the video. | ||
Future<List<VideoAudioTrack>> getAudioTracks(int playerId) { | ||
throw UnimplementedError('getAudioTracks() has not been implemented.'); | ||
} | ||
|
||
/// Selects an audio track by its ID. | ||
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.', | ||
); | ||
} | ||
Comment on lines
+125
to
+147
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These new methods are correctly defined with default |
||
} | ||
|
||
class _PlaceholderImplementation extends VideoPlayerPlatform {} | ||
|
@@ -529,3 +553,86 @@ class VideoCreationOptions { | |
/// The type of view to be used for displaying the video player | ||
final VideoViewType viewType; | ||
} | ||
|
||
/// Represents an audio track in a video with its metadata. | ||
@immutable | ||
class VideoAudioTrack { | ||
/// Constructs an instance of [VideoAudioTrack]. | ||
const VideoAudioTrack({ | ||
required this.id, | ||
required this.label, | ||
required this.language, | ||
required this.isSelected, | ||
this.bitrate, | ||
this.sampleRate, | ||
this.channelCount, | ||
this.codec, | ||
}); | ||
|
||
/// Unique identifier for the audio track. | ||
final String id; | ||
|
||
/// Human-readable label for the track. | ||
final String label; | ||
|
||
/// Language code of the audio track (e.g., 'en', 'es', 'und'). | ||
final String language; | ||
|
||
/// Whether this track is currently selected. | ||
final bool isSelected; | ||
|
||
/// Bitrate of the audio track in bits per second. | ||
/// May be null if not available from the platform. | ||
final int? bitrate; | ||
|
||
/// Sample rate of the audio track in Hz. | ||
/// May be null if not available from the platform. | ||
final int? sampleRate; | ||
|
||
/// Number of audio channels. | ||
/// May be null if not available from the platform. | ||
final int? channelCount; | ||
|
||
/// Audio codec used (e.g., 'aac', 'mp3', 'ac3'). | ||
/// May be null if not available from the platform. | ||
final String? codec; | ||
|
||
@override | ||
bool operator ==(Object other) { | ||
return identical(this, other) || | ||
other is VideoAudioTrack && | ||
runtimeType == other.runtimeType && | ||
id == other.id && | ||
label == other.label && | ||
language == other.language && | ||
isSelected == other.isSelected && | ||
bitrate == other.bitrate && | ||
sampleRate == other.sampleRate && | ||
channelCount == other.channelCount && | ||
codec == other.codec; | ||
} | ||
|
||
@override | ||
int get hashCode => Object.hash( | ||
id, | ||
label, | ||
language, | ||
isSelected, | ||
bitrate, | ||
sampleRate, | ||
channelCount, | ||
codec, | ||
); | ||
|
||
@override | ||
String toString() => | ||
'VideoAudioTrack(' | ||
'id: $id, ' | ||
'label: $label, ' | ||
'language: $language, ' | ||
'isSelected: $isSelected, ' | ||
'bitrate: $bitrate, ' | ||
'sampleRate: $sampleRate, ' | ||
'channelCount: $channelCount, ' | ||
'codec: $codec)'; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The changelog entry is great! For completeness, you might also want to include the
isAudioTrackSupportAvailable()
method, as it's part of the new functionality added in this PR.