Skip to content
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

Move Player.Listener impl, remove @VisibleForTesting isInitialized. #6922

Merged
merged 6 commits into from
Jun 13, 2024

Conversation

matanlurey
Copy link
Contributor

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).

@matanlurey matanlurey requested a review from gmackall June 13, 2024 20:47
@matanlurey matanlurey changed the title Move listener class, remove visibleForTesting isInitialized. Move Player.Listener impl, remove @VisibleForTesting isInitialized. Jun 13, 2024
@matanlurey matanlurey added the override: no versioning needed Override the check requiring version bumps for most changes label Jun 13, 2024
Copy link
Member

@gmackall gmackall left a comment

Choose a reason for hiding this comment

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

Mostly LGTM just one question about the Player.STATE_BUFFERING case

public void onPlaybackStateChanged(final int playbackState) {
switch (playbackState) {
case Player.STATE_BUFFERING:
setBuffering(true);
Copy link
Member

Choose a reason for hiding this comment

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

This is a slight behavior change, right?

Before we would always invoke videoPlayerEvents.onBufferingUpdate(exoPlayer.getBufferedPosition()):

setBuffering(true);
sendBufferingUpdate();

but now we only invoke it if we pass the check at the start of the slightly modified setBuffering.

I don't know enough about video_player to know if that case (we are in the case of this switch Player.STATE_BUFFERING while isBuffering is already true) can happen/matters, so feel free to ignore if it isn't important.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not only was this a good catch, but you caught a bug missed in the previous refactor.

I've fixed this and added a test to catch regressions.

@matanlurey matanlurey requested a review from gmackall June 13, 2024 22:37
@matanlurey matanlurey added the override: no changelog needed Override the check requiring CHANGELOG updates for most changes label Jun 13, 2024
@matanlurey
Copy link
Contributor Author

@camsim99 I am going to add auto-submit to fix the previous regression, but please leave comments still and I promise I'll address in a follow-up PR.

@matanlurey matanlurey added the autosubmit Merge PR when tree becomes green via auto submit App label Jun 13, 2024
Copy link
Contributor

auto-submit bot commented Jun 13, 2024

auto label is removed for flutter/packages/6922, due to - The status or check suite Linux_android android_device_tests_shard_1 master has failed. Please fix the issues identified (or deflake) before re-applying this label.

@auto-submit auto-submit bot removed the autosubmit Merge PR when tree becomes green via auto submit App label Jun 13, 2024
@matanlurey matanlurey added the autosubmit Merge PR when tree becomes green via auto submit App label Jun 13, 2024
@auto-submit auto-submit bot merged commit dd04ab1 into main Jun 13, 2024
74 checks passed
@auto-submit auto-submit bot deleted the video-player-is-initialized-refactor branch June 13, 2024 23:42
arc-yong pushed a commit to Arctuition/packages-arc that referenced this pull request Jun 14, 2024
…`. (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).
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Jun 14, 2024
auto-submit bot pushed a commit to flutter/flutter that referenced this pull request Jun 14, 2024
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
victorsanni pushed a commit to victorsanni/flutter that referenced this pull request Jun 14, 2024
…r#150264)

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
victorsanni pushed a commit to victorsanni/flutter that referenced this pull request Jun 14, 2024
…r#150264)

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
matanlurey added a commit that referenced this pull request Jun 25, 2024
…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.
gabbopalma pushed a commit to gabbopalma/packages that referenced this pull request Jun 26, 2024
…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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
autosubmit Merge PR when tree becomes green via auto submit App override: no changelog needed Override the check requiring CHANGELOG updates for most changes override: no versioning needed Override the check requiring version bumps for most changes p: video_player platform-android
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants