-
Notifications
You must be signed in to change notification settings - Fork 2.9k
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
Refactor VideoPlayer
to be less exposed to EventChannel
& related
#6908
Conversation
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.
lgtm modulo some nitpicks
* order to assert results. | ||
*/ | ||
interface VideoPlayerCallbacks { | ||
void onInitialized( |
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.
nit: rotationCorrectionInDegrees = 0
and rotationCorrectionInDegrees = null
have the same semantic meaning, right? If so, no need to make this nullable.
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.
Good point! Done.
return VideoPlayerEventCallbacks.withSink(eventSink); | ||
} | ||
|
||
static VideoPlayerEventCallbacks withSink(EventChannel.EventSink eventSink) { |
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.
@VisibleForTesting
?
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.
Done!
|
||
@Override | ||
public void onBufferingEnd() { | ||
Map<String, Object> event = new HashMap<>(); |
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.
nit: All of these events are allocating new HashMap with the same value. They could be private constants to avoid generating garbage. None of them seem that chatty though.
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.
I'm going to leave it as-is for now, hopefully we can use Map.of
soonish?
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.
LGTM! Just left some suggestions :)
} else if (eventSink != null) { | ||
eventSink.error("VideoError", "Video player had error " + error, null); | ||
} else { | ||
events.onError("VideoPlayer", "Video player had error " + error, null); |
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.
Are you switching this because the VideoPlayer tag used elsewhere? Looks like VideoError is at least also used on iOS so we may want to stay consistent for clarity: https://github.com/search?q=repo%3Aflutter%2Fpackages+VideoError&type=code.
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.
Oh, nope, that was an actual mistake - I'll also add a test before I resolve this comment.
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.
Done and test added!
private QueuingEventSink eventSink; | ||
|
||
private final EventChannel eventChannel; | ||
private final VideoPlayerCallbacks events; |
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.
Extreme nit: can this be something like videoPlayerEvents
or something to indicate the type of events?
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.
Done!
* expected events to send back through the plugin channel. In tests methods can be overridden in | ||
* order to assert results. | ||
*/ | ||
interface VideoPlayerCallbacks { |
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.
Maybe link the Player.Listener
docs to the callbacks that directly map to one of those events?
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.
Done!
auto label is removed for flutter/packages/6908, due to - The status or check suite Linux repo_checks has failed. Please fix the issues identified (or deflake) before re-applying this label. |
…`. (#6922) Similar to #6908, as part of flutter/flutter#148417. I'm working on re-landing #6456, this time without using the `ActivityAware` interface (see flutter/flutter#148417). As part of that work, I'll need to better control the `ExoPlayer` lifecycle and save/restore internal state. In this PR, I've removed the concept of the class being "initialized" or not - the only thing "initialized" means is "for a given instance of `ExoPlayer`, has received the `'initialized'` event. As a result I removed the quasi-public API that was used for testing only and replaced it with observing what the real production instance does (`Player.STATE_READY`). After this PR, I'll likely do one more pass around the constructors - the constructor that takes an `ExoPlayer` that is marked `@VisibleForTesting` _also_ doesn't make sense once we'll support suspending/resuming video players, so it will need to get reworked (probably into taking a factory method).
…flutter#6908) Part of flutter/flutter#148417. I'm working on re-landing flutter#6456, this time without using the `ActivityAware` interface (see flutter/flutter#148417). As part of that work, I'll need to better control the `ExoPlayer` lifecycle and save/restore internal state. These are some proposed refactors to limit how much work `VideoPlayer` is doing, so I can better understand what needs to be reset (or not) internally. Specifically, `VideoPlayer` no longer knows what an `EventChannel` or `EventSink` is, and does not need to manage the lifecycle (it stores a `private final VideoPlayerCallbacks` instead), and instead there is a `VideoPlayerCallbacks` interface that does all that. I'm totally open to: - Landing this as-is (+/- nits) and making minor improvements in follow-up PRs - Making more significant changes to this PR and then landing it - Not landing this PR at all because it doesn't follow the approach the folks who maintain the plugin prefer Also happy to chat in VC/person about any of the changes.
…`. (flutter#6922) Similar to flutter#6908, as part of flutter/flutter#148417. I'm working on re-landing flutter#6456, this time without using the `ActivityAware` interface (see flutter/flutter#148417). As part of that work, I'll need to better control the `ExoPlayer` lifecycle and save/restore internal state. In this PR, I've removed the concept of the class being "initialized" or not - the only thing "initialized" means is "for a given instance of `ExoPlayer`, has received the `'initialized'` event. As a result I removed the quasi-public API that was used for testing only and replaced it with observing what the real production instance does (`Player.STATE_READY`). After this PR, I'll likely do one more pass around the constructors - the constructor that takes an `ExoPlayer` that is marked `@VisibleForTesting` _also_ doesn't make sense once we'll support suspending/resuming video players, so it will need to get reworked (probably into taking a factory method).
flutter/packages@7805455...dd04ab1 2024-06-13 matanlurey@users.noreply.github.com Move `Player.Listener` impl, remove `@VisibleForTesting isInitialized`. (flutter/packages#6922) 2024-06-13 engine-flutter-autoroll@skia.org Roll Flutter from b1f9d71 to 01db23b (15 revisions) (flutter/packages#6921) 2024-06-13 matanlurey@users.noreply.github.com Refactor `VideoPlayer` to be less exposed to `EventChannel` & related (flutter/packages#6908) 2024-06-13 v.ditsyak@gmail.com [go_router] Added proper `redirect` handling for `ShellRoute.$route` and `StatefulShellRoute.$route` for proper redirection handling in case of code generation (flutter/packages#6841) If this roll has caused a breakage, revert this CL and stop the roller using the controls here: https://autoroll.skia.org/r/flutter-packages-flutter-autoroll Please CC flutter-ecosystem@google.com,rmistry@google.com on the revert to ensure that a human is aware of the problem. To file a bug in Flutter: https://github.com/flutter/flutter/issues/new/choose To report a problem with the AutoRoller itself, please file a bug: https://issues.skia.org/issues/new?component=1389291&template=1850622 Documentation for the AutoRoller is here: https://skia.googlesource.com/buildbot/+doc/main/autoroll/README.md
flutter/packages@7805455...dd04ab1 2024-06-13 matanlurey@users.noreply.github.com Move `Player.Listener` impl, remove `@VisibleForTesting isInitialized`. (flutter/packages#6922) 2024-06-13 engine-flutter-autoroll@skia.org Roll Flutter from b1f9d71 to 01db23b (15 revisions) (flutter/packages#6921) 2024-06-13 matanlurey@users.noreply.github.com Refactor `VideoPlayer` to be less exposed to `EventChannel` & related (flutter/packages#6908) 2024-06-13 v.ditsyak@gmail.com [go_router] Added proper `redirect` handling for `ShellRoute.$route` and `StatefulShellRoute.$route` for proper redirection handling in case of code generation (flutter/packages#6841) If this roll has caused a breakage, revert this CL and stop the roller using the controls here: https://autoroll.skia.org/r/flutter-packages-flutter-autoroll Please CC flutter-ecosystem@google.com,rmistry@google.com on the revert to ensure that a human is aware of the problem. To file a bug in Flutter: https://github.com/flutter/flutter/issues/new/choose To report a problem with the AutoRoller itself, please file a bug: https://issues.skia.org/issues/new?component=1389291&template=1850622 Documentation for the AutoRoller is here: https://skia.googlesource.com/buildbot/+doc/main/autoroll/README.md
flutter/packages@7805455...dd04ab1 2024-06-13 matanlurey@users.noreply.github.com Move `Player.Listener` impl, remove `@VisibleForTesting isInitialized`. (flutter/packages#6922) 2024-06-13 engine-flutter-autoroll@skia.org Roll Flutter from b1f9d71 to 01db23b (15 revisions) (flutter/packages#6921) 2024-06-13 matanlurey@users.noreply.github.com Refactor `VideoPlayer` to be less exposed to `EventChannel` & related (flutter/packages#6908) 2024-06-13 v.ditsyak@gmail.com [go_router] Added proper `redirect` handling for `ShellRoute.$route` and `StatefulShellRoute.$route` for proper redirection handling in case of code generation (flutter/packages#6841) If this roll has caused a breakage, revert this CL and stop the roller using the controls here: https://autoroll.skia.org/r/flutter-packages-flutter-autoroll Please CC flutter-ecosystem@google.com,rmistry@google.com on the revert to ensure that a human is aware of the problem. To file a bug in Flutter: https://github.com/flutter/flutter/issues/new/choose To report a problem with the AutoRoller itself, please file a bug: https://issues.skia.org/issues/new?component=1389291&template=1850622 Documentation for the AutoRoller is here: https://skia.googlesource.com/buildbot/+doc/main/autoroll/README.md
…allback`. (#6982) I'm working on re-landing #6456, this time without using the `ActivityAware` interface (see flutter/flutter#148417). As part of that work, I'll need to better control the `ExoPlayer` lifecycle and save/restore internal state. Follows the patterns of some of the previous PRs, i.e. - #6922 - #6908 The changes in this PR are _mostly_ tests, it was extremely difficult to just add more tests to the already very leaky `VideoPlayer` abstraction which had lots of `@VisibleForTesting` methods and other "holes" to observe state. This PR removes all of that, and adds test coverage where it was missing. Namely it: - Adds a new class, `VideoAsset`, that builds and configures the media that `ExoPlayer` uses. - Removes all "testing" state from `VidePlayer`, keeping it nearly immutable. - Added tests for most of the classes I've added since, which were mostly missing. That being said, this is a large change. I'm happy to sit down with either of you and walk through it. --- Opening as a draft for the moment, since there is a pubspec change needing I want to handle first.
…allback`. (flutter#6982) I'm working on re-landing flutter#6456, this time without using the `ActivityAware` interface (see flutter/flutter#148417). As part of that work, I'll need to better control the `ExoPlayer` lifecycle and save/restore internal state. Follows the patterns of some of the previous PRs, i.e. - flutter#6922 - flutter#6908 The changes in this PR are _mostly_ tests, it was extremely difficult to just add more tests to the already very leaky `VideoPlayer` abstraction which had lots of `@VisibleForTesting` methods and other "holes" to observe state. This PR removes all of that, and adds test coverage where it was missing. Namely it: - Adds a new class, `VideoAsset`, that builds and configures the media that `ExoPlayer` uses. - Removes all "testing" state from `VidePlayer`, keeping it nearly immutable. - Added tests for most of the classes I've added since, which were mostly missing. That being said, this is a large change. I'm happy to sit down with either of you and walk through it. --- Opening as a draft for the moment, since there is a pubspec change needing I want to handle first.
Part of flutter/flutter#148417.
I'm working on re-landing #6456, this time without using the
ActivityAware
interface (see flutter/flutter#148417). As part of that work, I'll need to better control theExoPlayer
lifecycle and save/restore internal state.These are some proposed refactors to limit how much work
VideoPlayer
is doing, so I can better understand what needs to be reset (or not) internally. Specifically,VideoPlayer
no longer knows what anEventChannel
orEventSink
is, and does not need to manage the lifecycle (it stores aprivate final VideoPlayerCallbacks
instead), and instead there is aVideoPlayerCallbacks
interface that does all that.I'm totally open to:
Also happy to chat in VC/person about any of the changes.