Skip to content

Conversation

@stuartmorgan-g
Copy link
Collaborator

Refactors the Dart internals to create a pleyer instance class on the Dart side, and intermediates the event stream with an instance-managed stream controller that would allow for alternate event sources (e.g., Dart code).

This prepares for future moves of more logic to Dart, and parallels Android Dart code changes made in
#9771

Part of flutter/flutter#172763

Pre-Review Checklist

Footnotes

  1. Regular contributors who have demonstrated familiarity with the repository guidelines only need to comment if the PR is not auto-exempted by repo tooling. 2 3

Refactors the Dart internals to create a pleyer instance class on the
Dart side, and intermediates the event stream with an instance-managed
stream controller that would allow for alternate event sources (e.g.,
Dart code).

This prepares for future moves of more logic to Dart, and parallels
Android Dart code changes made in
flutter#9771

Part of flutter/flutter#172763
FVPEventBridge *eventBridge = [[FVPEventBridge alloc]
initWithMessenger:messenger
channelName:[NSString stringWithFormat:@"flutter.io/videoPlayer/videoEvents%@",
channelName:[NSString stringWithFormat:@"flutter.dev/videoPlayer/videoEvents%@",
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This was just an opportunistic change; I had mass-changed flutter.io to flutter.dev in most places a while ago, and apparently missed this channel name.

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

This pull request refactors the Dart implementation of the AVFoundation video player to introduce a _PlayerInstance class. This new class encapsulates the state and behavior for a single video player instance, including handling API calls and event streams. This is a good architectural improvement that increases modularity and maintainability. The event channel name has also been updated from flutter.io to flutter.dev for consistency. The tests have been updated to reflect these changes.

I've found a couple of issues related to the new StreamController in _PlayerInstance that could lead to resource leaks or runtime errors. Please see my detailed comments.

Comment on lines 231 to 232
final StreamController<VideoEvent> _eventStreamController =
StreamController<VideoEvent>();

Choose a reason for hiding this comment

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

high

The _eventStreamController is created as a single-subscription StreamController. This can lead to runtime errors if there are multiple attempts to listen to the videoEvents stream. It's safer to use a broadcast stream controller to allow for multiple listeners, which makes the implementation more robust.

Suggested change
final StreamController<VideoEvent> _eventStreamController =
StreamController<VideoEvent>();
final StreamController<VideoEvent> _eventStreamController =
StreamController<VideoEvent>.broadcast();


Future<void> dispose() async {
await _eventSubscription?.cancel();
await _api.dispose();

Choose a reason for hiding this comment

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

high

The _eventStreamController is not closed in the dispose method. This can lead to a resource leak. You should close the stream controller to release its resources when the player instance is disposed.

    await _eventStreamController.close();
    await _api.dispose();

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant