-
Notifications
You must be signed in to change notification settings - Fork 3.5k
[video_player_avfoundation] Create a Dart player instance #10490
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?
[video_player_avfoundation] Create a Dart player instance #10490
Conversation
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%@", |
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.
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.
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.
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.
| final StreamController<VideoEvent> _eventStreamController = | ||
| StreamController<VideoEvent>(); |
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 _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.
| final StreamController<VideoEvent> _eventStreamController = | |
| StreamController<VideoEvent>(); | |
| final StreamController<VideoEvent> _eventStreamController = | |
| StreamController<VideoEvent>.broadcast(); |
|
|
||
| Future<void> dispose() async { | ||
| await _eventSubscription?.cancel(); | ||
| await _api.dispose(); |
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.
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
[shared_preferences]pubspec.yamlwith an appropriate new version according to the pub versioning philosophy, or I have commented below to indicate which version change exemption this PR falls under1.CHANGELOG.mdto add a description of the change, following repository CHANGELOG style, or I have commented below to indicate which CHANGELOG exemption this PR falls under1.///).Footnotes
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