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

Prevent jumping of the player and wrong padding on devices with cutout #4154

Merged
merged 3 commits into from
Sep 8, 2020

Conversation

avently
Copy link
Contributor

@avently avently commented Aug 17, 2020

What is it?

  • Bug fix (user facing)

Description of the changes in your PR

On devices with cutout there is a "jump" when you are in multiWindow mode or when you're watching vertical video in fullscreen. This PR fixes that jump (the first commit).

On the same devices there is a problem related to top padding on vertical videos in portrait in fullscreen. This is more interesting because a couple hours ago I thought I will not be able to fix it. This problem makes situation when the center of the player is not in the center of the screen. After hours trying I installed the app on my phone and the issue is fixed actually (same Android version but different result). So I have no idea will my method (from the second commit) work on user's devices or not. I think the issue is still here but on devices with non-standard screen ratio. But I don't know how to fix it. You can merge the PR as is or merge only first commit, or drop it.

In short:

  • in multiwindow mode all videos work great
  • there is no jump that happened before when a user shows/hides controls in the player
  • there is a correct padding on top of the player (but I'm sure it isn't on devices with non-standart ratio).

Everyone who has a device with a hole, cutout, whatever check this build in vertical videos in landscape, in portrait, in multi window mode, check non-vertical videos too.

Fixes the following issue(s)

partially fixes #4040

Testing apk

app-release-final.zip

Agreement

@TobiGr TobiGr added bug Issue is related to a bug player Issues related to any player (main, popup and background) labels Aug 17, 2020
@B0pol B0pol added this to the 0.20.0 milestone Aug 17, 2020
@blackbox87
Copy link

This problem makes situation when the center of the player is not in the center of the screen. After hours trying I installed the app on my phone and the issue is fixed actually (same Android version but different result). So I have no idea will my method (from the second commit) work on user's devices or not. I think the issue is still here but on devices with non-standard screen ratio. But I don't know how to fix it. You can merge the PR as is or merge only first commit, or drop it.

That commit actually makes the player off-center for me while using a Poco F1. It was perfect before the commit as it was almost identical to the official YouTube app, minus pinch to zoom.

Aligning to the notch means you'll probably lose some of the image. Like in my case it's now off-center and I lose some of the image on the right side of my screen due to the phones rounded corners.

YouTube:
YouTube

NewPipe v0.19.8:
NewPipe

NewPipe Cutout:
NewPipe_Cutout

@avently
Copy link
Contributor Author

avently commented Aug 30, 2020

@blackbox87
Thank you for testing. Actually we need to compare the apk from this PR with the apk from this post: https://github.com/TeamNewPipe/NewPipe/projects/17#card-42918515

You compared with 0.19.8 which doesn't make sense. In 0.19.8 the app uses default mechanism of handling the cutout, everything is done by Android. On the newest version there is no way to give this job to Android because of the need to use Fragment instead of an Activity.

So, just compare with the latest apk from the link. More info about the problem the PR trying to fix can be found in #4040

@blackbox87
Copy link

You compared with 0.19.8 which doesn't make sense. In 0.19.8 the app uses default mechanism of handling the cutout, everything is done by Android. On the newest version there is no way to give this job to Android because of the need to use Fragment instead of an Activity.

Sorry about that. I haven't been testing debug versions for a while now, so I didn't think to compare it to a different debug build. But I can confirm that the builds by @B0pol all have the same issue. It's awful.

You're not supposed to align videos to the cutcout while using landscape because cutcouts come in many different sizes. If you do then you'll likely end up with off-centered videos and only having rounded corners on one side of your screen. That's why YouTube, VLC & many other players don't do anything about the notch and always center the videos to fit.

Comment on lines +2003 to +2007
// Prevent jumping of the player on devices with cutout
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
activity.getWindow().getAttributes().layoutInDisplayCutoutMode =
WindowManager.LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_NEVER;
}

Choose a reason for hiding this comment

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

Change to the following and it fixes landscape too.

        // Prevent jumping of the player on devices with cutout
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
            if (isLandscape()) {
                activity.getWindow().getAttributes().layoutInDisplayCutoutMode =
                        WindowManager.LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_SHORT_EDGES;
            } else {
                activity.getWindow().getAttributes().layoutInDisplayCutoutMode =
                        WindowManager.LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_NEVER;
            }
        }

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I can do this but in this case a title and a description will be hidden under possible cutout from top right corner (in landscape orientation it will be in top left corner). I'm not sure about how much devices have such cutout but it's not an ideal choice anyway.

Choose a reason for hiding this comment

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

That's actually a separate issue that's caused by the status bar height (and navbar height?) not being accounted for while viewing a video in landscape. So I'm currently trying to work out the best way to center the controls.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good to know that someone cares about it. Not only landscape mode has the problem with the centering but vertical videos too.

@blackbox87
Copy link

blackbox87 commented Sep 7, 2020

@avently Check out my commit. It should give you perfectly centered videos and all of the controls will have the correct padding.

And although it's unrelated to this problem I noticed that screen rotation doesn't always behave correctly.

  1. Enable auto-rotate and watch a video in landscape
  2. Disable auto-rotate while watching the video in landscape

Previously NewPipe would return you to your default orientation, but now you'll remain stuck in landscape and NewPipe's fullscreen button won't do anything no matter how many times you press on it. So as it seems buggy I made this change which restores the original behaviour.

@avently
Copy link
Contributor Author

avently commented Sep 7, 2020

@blackbox87 I didn't look closely on your changes but looks like the changes depend on this PR. And you say now everything is fine. So we can merge this PR and then to wait your PR, right?

About autorotation issue: can you make a PR too?

@blackbox87
Copy link

So we can merge this PR and then to wait your PR, right?

It could be done that way or you could just copy my changes into your branch. I'm happy with whatever as long as this gets fixed.

About autorotation issue: can you make a PR too?

I'd like to know if it's the intended behaviour or not first. Maybe @Stypox or @TobiGr can comment?

It's possible that they want NewPipe to remain in landscape mode, but having the button not do anything when you disable auto-rotate seems like a bug either way. It should always be able to toggle between portrait and landscape.

@avently
Copy link
Contributor Author

avently commented Sep 7, 2020

@blackbox87 I prefer to maintain only my code. So better to have your code inside your PR.

About autorotation: this is my code that makes such situation so if your solution fixes it just make a PR. For me it was like a rare case (when you lock orientation while in landscape) and I just skipped that case

@blackbox87
Copy link

blackbox87 commented Sep 7, 2020

@blackbox87 I prefer to maintain only my code. So better to have your code inside your PR.

Fair enough. If someone merges this in then I'll update my fork and create a pull request.

About autorotation: this is my code that makes such situation so if your solution fixes it just make a PR. For me it was like a rare case (when you lock orientation while in landscape) and I just skipped that case

Well there's two ways to fix the issue.

  1. Set the orientation to portrait if auto-rotate is disabled and certain conditions are met.
  2. Fix the fullscreen button so that you can always toggle between portrait and landscape.

I'm not familiar with the code, which is why I went with the first option and made NewPipe behave as it used to. But I think fixing the button might actually be the better solution.

@avently
Copy link
Contributor Author

avently commented Sep 7, 2020

@blackbox87 second way is not an option at all. So, yeah, the first way is what we need.

Copy link
Member

@Stypox Stypox left a comment

Choose a reason for hiding this comment

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

Code looks good, though I don't have a device to test this on. But if @blackbox87 says he has a fully working solution based on this one I'd merge right away, also to prevent rebasing issues. Thank you @avently ;-)

@blackbox87 thank you for your investigations, as soon as this PR will get merged feel free to create two separate PRs for cutout and rotation. I think your rotation approach is right, obviously having a button doing nothing is a bad idea and the previous behaviour was ok. Thanks :-D

@blackbox87
Copy link

@Stypox

I think your rotation approach is right, obviously having a button doing nothing is a bad idea and the previous behaviour was ok.

I've actually figured out how to fix the button, although @avently said that it wouldn't be an option. So we could have NewPipe remain in landscape and only change to portrait when the fullscreen button is pressed again. Personally I think that might be the better solution too.

@Stypox Stypox merged commit 530f745 into TeamNewPipe:dev Sep 8, 2020
@Stypox
Copy link
Member

Stypox commented Sep 8, 2020

@blackbox87 yeah, do as you said ;-)

@B0pol
Copy link
Member

B0pol commented Sep 8, 2020

thank you

@avently
Copy link
Contributor Author

avently commented Sep 8, 2020

thank you

You're welcome. Can wait to see a fix for centering from @blackbox87

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Issue is related to a bug player Issues related to any player (main, popup and background)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Content not centered with 18:9 screen -> weird behaviour with navigation bar
6 participants