-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
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 player and extract UI components #8170
Conversation
And so it begins.
Do you want bug reports only related to this PR? Or bug reports for the player in general, like playback exceptions? |
@opusforlife2 possibly only related to this PR, but if in doubt send anyway. |
Do you intend to fix some bugs along the way or is this strictly a 1:1 refactor without any change in what the code actually does, bugs included? |
The code had to change in many places, and so what I rewritten may work differently than before and solve some bugs. But the point of the PR is the refactor, not the bug fixing (which will hopefully become simpler after this PR is merged). |
I solved almost all TODOs. I rebased on top of dev (which contained #8020, and I have a few questions about that PR I posted there). I used the first diff below here when rebasing, so that I could make sure that I didn't miss any changes in the
|
Kudos, SonarCloud Quality Gate passed! |
I finished the TODO list, now this PR is completely ready for review (to be done at the beginning of 0.24.0, if possible). |
which broadcasts do you mean? Just create the Intent not directly in sendBroadcast and call intent.setPackage("org.schabi.newpipe") -> "security" problem solved |
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.
Thank you for the PR!
This cleanup was long overdue and it has max priority on my personal PR todo-list (so that we don't end up with a ton of merge-conflicts).
Disclaimer: Didn't test it so far.
Your coding style is really good, found only some minor things while reviewing (might be leftovers from the migration/previous code):
Also please rebase the PR (merge conflicts).
PS: You might also have a look at Sonarcloud
app/src/main/java/org/schabi/newpipe/fragments/detail/VideoDetailFragment.java
Outdated
Show resolved
Hide resolved
app/src/main/java/org/schabi/newpipe/local/dialog/PlaylistDialog.java
Outdated
Show resolved
Hide resolved
app/src/main/java/org/schabi/newpipe/player/ui/VideoPlayerUi.java
Outdated
Show resolved
Hide resolved
@litetex I won't do much to this PR until 0.23.1 with delivery methods is released, as we decided a while ago. This PR will go into 0.24.0, which will also be the first version to drop support for KitKat. |
26099bb
to
755ab2b
Compare
|
@Stypox Looks pretty good to me now. I think a few things are still not resolved/commented (see my previous review above) but the rest looks good. |
Whoa, the player now reorients to portrait when it detects the video's aspect ratio with 'always fullscreen' on! Thanks, @Stypox! It's much better than doing it manually, fumbling with the button, and having to rewind. |
Oh yes, sorry. I pushed a commit regarding the
|
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.
Tested the APK a few days, everything is working fine :)
Code also LGTM
Also replace some `isPlayerOpen` with direct `playerType == null` checks.
I rebased again, and I also used the apk for a few days without encountering issues. @litetex please merge before more conflicts arise ;-) |
Got a crash. I can't tell you the context of the crash because... I fell asleep while using the app and woke up minutes later to Scoop with a crash report. 😅 Edit: the APK I have is from 7 July, in case that renders this crash invalid or outdated.
|
@opusforlife2 thank you for reporting; should be fixed in 0e8cc72 :-) |
Kudos, SonarCloud Quality Gate passed! |
I also got 2 random crashes over the past week with the debug APK from 2022-07-10 however I was unable to see what happened because there was no ACRA report and I didn't have a PC with ADB near me. But I guess it was the same problem as opus pointed out above. Merging for now to ensure no conflicts. Subsequent problems should be addressed by new PRs. |
I've found a minor problem with some videos with non standard aspect ratios like album covers. After opening the video in portrait mode, the video is stretched to use the full width of the screen. It's only reproducible with videos from "Artist - Topic" Youtube channels, videos from other channels with squarish aspect ratios are somehow not effected. Going into full screen playback and back to portrait resolves this issue. The testing APK otherwise works flawlessly in my two days of use. Screenshot of problem below: |
Confirmed ^ |
From the OP:
This might have been addressed in the review comments, but just in case it wasn't, I'm leaving this here for future reference. |
No, it wasn't addressed ;-) |
Description of the changes in your PR
This big PR extracts ~2500 lines of code from the
Player
, namely the code that handles the various UI states, into plug-and-play ui classes. The UI classes I created so far are:PlayerUi
: this is the base class with all of the base methods with an empty implementation. It holds a reference to the player.NotificationPlayerUi
: contains all of the calls to theNotificationUtil
class. Maybe we could merge it withNotificationUtil
? Tell me what you thinkVideoPlayerUi
: contains the code that main and popup player have in common, for example to handle controls, button presses, video surface, ... It also contains the reference to theVideoPlayerBinding
, that is, the instantiation ofplayer.xml
that currently is the same for both the popup and the main player (and probably it's ok to be that way for now). This class is where most of thePlayer
code went, as it is ~1500 lines long.MainPlayerUi
: contains the code specific to the main player: handling fullscreen, stream segments, chapters & play queue list, minimizing to popup/background, main player gesture listener ...PopupPlayerUi
: contains the code specific to the popup player: window management, close overlay, popup player gesture listener, ...The
Player
object now holds aPlayerUiList UIs
member variable through which UIs can be added, removed or queried. I used stream API andOptional
to simplify things: when the player wants to call some method on all of its UIs it just has to call e.g.UIs.call(PlayerUi::onComplete);
. And when classes from outside want to make changes to a specific UI, they can doplayer.UIs().get(MainPlayerUi.class)
and use theOptional
API on the returned object.MainPlayer
was renamed toPlayerService
as that's what it actually is. I also removed the unusedPlayerState
andPlayerServiceBinder
classes that were cluttering the .player package.Highlights
Main/PopupPlayerUi
is not added when starting the player in background, and removed when switching to it!PlayerGestureListener
class made no sense before the refactoring: why make both a base abstract class and a subclass, if they need to keep interchanging information and there is no difference in the nature of the code in the two classes?setupVideoSurfaceIfNeeded
method can be called anytime without issues, since the player works fine even without surface, and will start rendering happily as soon as a valid surface is connected. Btw, for Android >= API23, I usedsetVideoSurfaceHolder
instead of manually extracting the surface from the holder and then callingsetVideoSurface
, seeVideoPlayerUi
line ~1500 (@Redirion is this ok)?TODO / known issues
TODO TODO
commentsInvestigate why the initial video stream loading is far slower than when switching resolutionSeems to also happen ondev
NotificationPlayerUi
BackgroundPlayerUi
: it can probably be removed -- removedTurn the media session handling into ato do in another PR, note that this might solve problems with the thumbnail not being loaded correctlyMediaSessionPlayerUi
Maybe turn fragment/activity player listeners intoto do in another PRListenerPlayerUi
or something like thatRemove the playback speedsto do in another PRPopupMenu
in the popup player and just use the usualPlaybackParametersDialog
, to save a few lines of code, complexity and inconsistency.//region
commentsFixes the following issue(s)
Fixes part of #7939
Fixes #7262 according to user testing
Fixes #8428
Please test!
Could you test and tell me all of the issues you can find?