Skip to content

Commit f73a8a8

Browse files
committed
feat(video_player_android): update audio track API to use platform interface 7.0.0
- Changed `VideoAudioTrack` to use separate `groupIndex` and `trackIndex` integers instead of string ID - Updated `selectAudioTrack()` to accept a `VideoAudioTrack` object instead of separate parameters - Bumped version to 2.10.0 and updated platform interface dependency to ^7.0.0
1 parent ca5d1e2 commit f73a8a8

File tree

3 files changed

+19
-28
lines changed

3 files changed

+19
-28
lines changed

packages/video_player/video_player_android/CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
## 2.10.0
2+
3+
* Updates audio track API to use `video_player_platform_interface` 7.0.0:
4+
* `VideoAudioTrack` now uses separate `groupIndex` and `trackIndex` integers instead of string ID.
5+
* `selectAudioTrack()` now accepts a `VideoAudioTrack` object instead of separate parameters.
6+
* Requires `video_player_platform_interface` ^7.0.0.
7+
18
## 2.9.0
29

310
* Implements `getAudioTracks()` and `selectAudioTrack()` methods for Android using ExoPlayer.

packages/video_player/video_player_android/lib/src/android_video_player.dart

Lines changed: 10 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,7 @@ VideoPlayerInstanceApi _productionApiProvider(int playerId) {
1717
}
1818

1919
/// The non-test implementation of `_videoEventStreamProvider`.
20-
Stream<PlatformVideoEvent> _productionVideoEventStreamProvider(
21-
String streamIdentifier,
22-
) {
20+
Stream<PlatformVideoEvent> _productionVideoEventStreamProvider(String streamIdentifier) {
2321
return pigeon.videoEvents(instanceName: streamIdentifier);
2422
}
2523

@@ -29,8 +27,7 @@ class AndroidVideoPlayer extends VideoPlayerPlatform {
2927
/// Creates a new Android video player implementation instance.
3028
AndroidVideoPlayer({
3129
@visibleForTesting AndroidVideoPlayerApi? pluginApi,
32-
@visibleForTesting
33-
VideoPlayerInstanceApi Function(int playerId)? playerApiProvider,
30+
@visibleForTesting VideoPlayerInstanceApi Function(int playerId)? playerApiProvider,
3431
Stream<PlatformVideoEvent> Function(String streamIdentifier)?
3532
videoEventStreamProvider,
3633
}) : _api = pluginApi ?? AndroidVideoPlayerApi(),
@@ -90,14 +87,9 @@ class AndroidVideoPlayer extends VideoPlayerPlatform {
9087
case DataSourceType.asset:
9188
final String? asset = dataSource.asset;
9289
if (asset == null) {
93-
throw ArgumentError(
94-
'"asset" must be non-null for an asset data source',
95-
);
90+
throw ArgumentError('"asset" must be non-null for an asset data source');
9691
}
97-
final String key = await _api.getLookupKeyForAsset(
98-
asset,
99-
dataSource.package,
100-
);
92+
final String key = await _api.getLookupKeyForAsset(asset, dataSource.package);
10193
uri = 'asset:///$key';
10294
case DataSourceType.network:
10395
uri = dataSource.uri;
@@ -213,9 +205,7 @@ class AndroidVideoPlayer extends VideoPlayerPlatform {
213205
final VideoPlayerViewState viewState = _playerWith(id: playerId).viewState;
214206

215207
return switch (viewState) {
216-
VideoPlayerTextureViewState(:final int textureId) => Texture(
217-
textureId: textureId,
218-
),
208+
VideoPlayerTextureViewState(:final int textureId) => Texture(textureId: textureId),
219209
VideoPlayerPlatformViewState() => PlatformViewPlayer(playerId: playerId),
220210
};
221211
}
@@ -237,8 +227,8 @@ class AndroidVideoPlayer extends VideoPlayerPlatform {
237227
for (final ExoPlayerAudioTrackData track in nativeData.exoPlayerTracks!) {
238228
tracks.add(
239229
VideoAudioTrack(
240-
groupIndex: track.groupIndex!,
241-
trackIndex: track.trackIndex!,
230+
groupIndex: track.groupIndex,
231+
trackIndex: track.trackIndex,
242232
label: track.label,
243233
language: track.language,
244234
isSelected: track.isSelected,
@@ -257,9 +247,7 @@ class AndroidVideoPlayer extends VideoPlayerPlatform {
257247
@override
258248
Future<void> selectAudioTrack(int playerId, VideoAudioTrack track) {
259249
// Extract groupIndex and trackIndex from the track object for Android's ExoPlayer
260-
return _playerWith(
261-
id: playerId,
262-
).selectAudioTrack(track.groupIndex, track.trackIndex);
250+
return _playerWith(id: playerId).selectAudioTrack(track.groupIndex, track.trackIndex);
263251
}
264252

265253
@override
@@ -273,9 +261,7 @@ class AndroidVideoPlayer extends VideoPlayerPlatform {
273261
return player ?? (throw StateError('No active player with ID $id.'));
274262
}
275263

276-
PlatformVideoFormat? _platformVideoFormatFromVideoFormat(
277-
VideoFormat? format,
278-
) {
264+
PlatformVideoFormat? _platformVideoFormatFromVideoFormat(VideoFormat? format) {
279265
return switch (format) {
280266
VideoFormat.dash => PlatformVideoFormat.dash,
281267
VideoFormat.hls => PlatformVideoFormat.hls,
@@ -459,9 +445,7 @@ class _PlayerInstance {
459445
// should be synchronous with the state change.
460446
break;
461447
case PlatformPlaybackState.ended:
462-
_eventStreamController.add(
463-
VideoEvent(eventType: VideoEventType.completed),
464-
);
448+
_eventStreamController.add(VideoEvent(eventType: VideoEventType.completed));
465449
case PlatformPlaybackState.unknown:
466450
// Ignore unknown states. This isn't an error since the media
467451
// framework could add new states in the future.

packages/video_player/video_player_android/pubspec.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ name: video_player_android
22
description: Android implementation of the video_player plugin.
33
repository: https://github.com/flutter/packages/tree/main/packages/video_player/video_player_android
44
issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+video_player%22
5-
version: 2.9.0
5+
version: 2.10.0
66

77
environment:
88
sdk: ^3.9.0
@@ -20,7 +20,7 @@ flutter:
2020
dependencies:
2121
flutter:
2222
sdk: flutter
23-
video_player_platform_interface: ^6.6.0
23+
video_player_platform_interface: ^7.0.0
2424

2525
dev_dependencies:
2626
build_runner: ^2.3.3

0 commit comments

Comments
 (0)