Skip to content

Conversation

@nateshmbhat
Copy link
Contributor

@nateshmbhat nateshmbhat commented Oct 28, 2025

  • Implemented getAudioTracks() and selectAudioTrack() methods for Android video player

Android PR for : #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.

- Implemented getAudioTracks() and selectAudioTrack() methods for Android video player using ExoPlayer
- Removed Kotlin dependencies and switched back to pure Java implementation
- Updated event listener to handle buffering states more accurately with start/end events
- Simplified playback state handling by removing unnecessary state enum
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

The pull request implements audio track selection for ExoPlayer in the Android video player. It adds getAudioTracks() and selectAudioTrack() methods, updates the Pigeon definitions, modifies the ExoPlayerEventListener to handle buffering states, and includes corresponding tests. The changes also involve removing Kotlin-related configurations from build.gradle and updating the CHANGELOG.md file.

Comment on lines 50 to 59
private void setBuffering(boolean buffering) {
if (isBuffering == buffering) {
return;
}
isBuffering = buffering;
if (buffering) {
events.onBufferingStart();
} else {
events.onBufferingEnd();
}

Choose a reason for hiding this comment

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

medium

This method encapsulates the logic for setting the buffering state and invoking the corresponding callbacks. It checks if the buffering state has changed before invoking the callbacks, preventing redundant calls. This is a good practice for optimizing performance and avoiding unnecessary UI updates. However, there is no error handling for the callback invocations. Consider adding try-catch blocks around the callback invocations to handle potential exceptions and prevent crashes.

Comment on lines 123 to 127
public @NonNull Messages.PlaybackState getPlaybackState() {
return new Messages.PlaybackState.Builder()
.setPlayPosition(exoPlayer.getCurrentPosition())
.setBufferPosition(exoPlayer.getBufferedPosition())
.build();

Choose a reason for hiding this comment

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

medium

The getPlaybackState method creates and returns a PlaybackState object with the current play and buffer positions. This is a good approach for encapsulating the playback state and providing a consistent way to access it. However, the method does not handle potential exceptions that might occur when accessing the ExoPlayer's state. Consider adding error handling to gracefully handle exceptions and prevent crashes.

Comment on lines +183 to +187
public void selectAudioTrack(@NonNull String trackId) {
if (trackSelector == null) {
Log.w("VideoPlayer", "Cannot select audio track: track selector is null");
return;
}

Choose a reason for hiding this comment

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

medium

It's important to handle the case where trackSelector is null to prevent NullPointerException. Logging a warning is a good approach, but consider throwing an exception or returning an error code to the Flutter side to indicate that audio track selection is not supported in this case. This would allow the Flutter app to handle the situation gracefully and provide feedback to the user.

Comment on lines +247 to +248
trackSelector.setParameters(
trackSelector.buildUponParameters().setOverrideForType(override).build());

Choose a reason for hiding this comment

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

medium

The setParameters method can throw exceptions if the provided parameters are invalid or if there is an issue with the underlying player. Consider adding a try-catch block around this call to handle potential exceptions and prevent crashes. Log the exception for debugging purposes.

Comment on lines 46 to 54
Map<String, Object> event = new HashMap<>();
event.put("event", "initialized");
event.put("width", width);
event.put("height", height);
event.put("duration", durationInMs);
if (rotationCorrectionInDegrees != 0) {
event.put("rotationCorrection", rotationCorrectionInDegrees);
}
eventSink.success(event);

Choose a reason for hiding this comment

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

medium

The onInitialized method constructs a Map to represent the initialization event. This is a good approach for sending structured data to the Flutter side. However, the code does not handle potential exceptions that might occur when putting values into the Map. Consider adding error handling to gracefully handle exceptions and prevent crashes.

- Moved video event processing logic to Dart for better buffer range updates during pause
- Switched Pigeon-generated code to Kotlin for improved type safety
- Added Kotlin plugin and configuration to build.gradle
- Implemented type-safe event channels for internal communication
- Refactored event handling to use dedicated event classes instead of HashMap
- Simplified buffering state management by moving logic to Dart layer
@stuartmorgan-g stuartmorgan-g added the triage-android Should be looked at in Android triage label Oct 28, 2025
// Create AudioTrackMessage with metadata
Messages.ExoPlayerAudioTrackData audioTrack =
new Messages.ExoPlayerAudioTrackData.Builder()
.setTrackId(groupIndex + "_" + trackIndex)
Copy link
Contributor

Choose a reason for hiding this comment

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

Instead of this string join on groupIndex and trackIndex and sending that as the track id, can we just send the group and track index separately? That way we don't have to do any decoding logic when retrieving the track ID back from the dart side.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You mean send it as a model or a tuple? And expect the same while setting?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

p: video_player platform-android triage-android Should be looked at in Android triage

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants