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

Add option to directly open fullscreen when the main player starts #5459

Merged
merged 8 commits into from
Sep 1, 2021

Conversation

Stypox
Copy link
Member

@Stypox Stypox commented Jan 19, 2021

What is it?

  • Bugfix (user facing)
  • Feature (user facing)
  • Codebase improvement (dev facing)
  • Meta improvement to the project (dev facing)

Description of the changes in your PR

This PR adds a switch to video&audio settings that, when enabled, causes the main player to start automatically in fullscreen mode. This was rather painful to implement, but I think this finally works well.

Fixes the following issue(s)

Fixes #4152
Fixes #4387
Fixes #4682
Fixes #5845
Fixes #5594
Fixes #5299
Fixes #6785
Fixes #6784
Fixes #6131
See #4548

APK testing

The APK can be found by going to the "Checks" tab below the title. On the left pane, click on "CI", scroll down to "artifacts" and click "app" to download the zip file which contains the debug APK of this PR.

Due diligence

@XiangRongLin XiangRongLin added the feature request Issue is related to a feature in the app label Jan 19, 2021
@opusforlife2
Copy link
Collaborator

Well, first try: the rotation is quite laggy and jerky. The player first opens in portrait, the video starts loading, and then after some time, the player rotates. This can cause the loading circle to go to a corner until the video appears.

Can the player first rotate, and only after that's completed the video starts loading?

@Stypox
Copy link
Member Author

Stypox commented Jan 21, 2021

@opusforlife2 I can try, though the player code is so complex that I don't know if I will make it

@nikhilCad
Copy link

Any updates?

@JCU0 JCU0 mentioned this pull request Feb 15, 2021
3 tasks
@TobiGr TobiGr force-pushed the dev branch 2 times, most recently from 679bc75 to 2aeccc0 Compare March 16, 2021 08:24
@Stypox
Copy link
Member Author

Stypox commented Mar 21, 2021

@avently sorry to bother you. Do you have any solution for this? That is, opening the fullscreen player directly?

Well, first try: the rotation is quite laggy and jerky. The player first opens in portrait, the video starts loading, and then after some time, the player rotates. This can cause the loading circle to go to a corner until the video appears.

Can the player first rotate, and only after that's completed the video starts loading?

@avently
Copy link
Contributor

avently commented Mar 21, 2021

sorry to bother you

no problem.

Add

if (shouldPlayInFullscreen && !isLandscape()) {
onScreenRotationButtonClicked()
}

here before openVideoPlayer:
https://github.com/TeamNewPipe/NewPipe/blob/dev/app/src/main/java/org/schabi/newpipe/fragments/detail/VideoDetailFragment.java#L495

and in other similar methods, for example, when clicking on play/pause in mini player. There is no need to do any huge code changes. Only those you made for additional autoplay option.
shouldPlayInFullscreen is a sharedPreference option that is your new autoplay option.

does it work like you expect?

@Stypox Stypox linked an issue Mar 25, 2021 that may be closed by this pull request
@Stypox Stypox force-pushed the fullscreen-autoplay branch 4 times, most recently from 0dd4d56 to 55fd94a Compare March 25, 2021 21:59
@Stypox
Copy link
Member Author

Stypox commented Mar 25, 2021

I rebased and implemented what @avently suggested (though some testing is still needed). The fluidity is still not perfect, but it wasn't so even in pre-unified, so I don't think it can be improved much. I also fixed the review by @opusforlife2

@nikhilCad
Copy link

@avently friendly pin to check it now that @Stypox had made some changes

@avently
Copy link
Contributor

avently commented Mar 26, 2021

@Stypox

TODO does it work for large-land layout?

Nope, it doesn't. Because there is a check that prevent landscape layouts from advantage to go to fullscreen. So probably you need to specify

(!isLandcspe || isTablet)

To test the changes on large-land you could specify in developer settings of the phone/emulator Device width like 600

@avently
Copy link
Contributor

avently commented Mar 26, 2021

And maybe to call fullscreenButtonClicked in this case, not sure

@Stypox
Copy link
Member Author

Stypox commented Mar 26, 2021

@avently could you please implement it? I wasn't able to reach a solution, I've been trying for two hours and I ran into multiple inconsistent and strange behaviours, but I didn't find a solution working for every situation.

@avently
Copy link
Contributor

avently commented Mar 27, 2021

Ok, i'll look

@opusforlife2
Copy link
Collaborator

I rebased and implemented what avently suggested (though some testing is still needed). The fluidity is still not perfect, but it wasn't so even in pre-unified, so I don't think it can be improved much. I also fixed the review by opusforlife2

@Stypox MUCH better than before, thank you. It's not perfect, like you said, but at least the video only starts after the app goes to full screen, instead of showing a black screen and a distorted player layout, forcing you to rewind the video from the beginning.

For reference, the current behaviour is: Tap thumbnail -> App goes into landscape (still on video details) -> The video stream is being fetched -> The moment it starts playing, the player goes into full screen.

Intended perfect behaviour (IMO): Tap thumbnail -> App goes into landscape AND player goes into full screen -> The video stream is being fetched -> The video starts playing. (Similar to 0.19.x behaviour).

@opusforlife2
Copy link
Collaborator

@Stypox Incidentally, the ripple animation when tapping on the thumbnail is gone, leaving no visual feedback of the tapping action. Intentional?

@Stypox
Copy link
Member Author

Stypox commented Mar 27, 2021

Ok, i'll look

Thank you, and sorry again for bothering you ;-)

Incidentally, the ripple animation when tapping on the thumbnail is gone, leaving no visual feedback of the tapping action. Intentional?

No, that's probably just another random bug caused by the messiness of the code

@avently
Copy link
Contributor

avently commented Mar 27, 2021

@opusforlife2

Remove

&& !player.isPlaying()

Here

if (globalScreenOrientationLocked(activity) && !player.isPlaying()) {

Ane look at the result

And the app will be in fullscreen right after orientation change. Instead of removing this immediate fullscreen can be turned on for those who have autofullscreen enabled instead of everyone

No, that's probably just another random bug caused by the messiness of the code

No, that's because you're forcing activity to change the orientation. It do it in main thread, ripple only works when main thread is free. So nothing strange here, immediate feedback of ui

@avently
Copy link
Contributor

avently commented Mar 28, 2021

@Stypox I played with the code and looks like I found the best possible solution. However I didn't tested all million possible ways to interact with the app. But I like what I see. You probably will want to move your code from onClickListener to the new place when you see how awesome it works on tablets.

Ok, add this lines

if (PlayerHelper.getAutoplayType(service)
                == PlayerHelper.AutoplayType.AUTOPLAY_TYPE_NEVER_AND_START_IN_FULLSCREEN
                && DeviceUtils.isTablet(service)
                && fragmentListener != null
                && videoPlayerSelected()
                && PlayerHelper.globalScreenOrientationLocked(service)) {
            fragmentListener.onScreenRotationButtonClicked();
        }

Here

Better to have a separate method of course and just to call it here. Something like `openFullScreenIfNeeded()' and to put your code from on click listener too, maybe it will work even better
Good?

@avently
Copy link
Contributor

avently commented Aug 30, 2021

Video demonstration of #5459 (comment)
Happens with default settings too. On the video I just changed language and content language just for your better understanding.
https://user-images.githubusercontent.com/7953703/131280656-a8599183-2843-470d-becf-298e3d9c78f0.mp4

@Stypox
Copy link
Member Author

Stypox commented Aug 31, 2021

I could reproduce:

E/ExoPlayerImplInternal: Playback error
      com.google.android.exoplayer2.ExoPlaybackException: MediaCodecVideoRenderer error, index=0, format=Format(1, null, null, video/avc, null, -1, null, [1280, 720, 23.976023], [-1, -1]), format_supported=YES
        at com.google.android.exoplayer2.ExoPlayerImplInternal.handleMessage(ExoPlayerImplInternal.java:542)
        at android.os.Handler.dispatchMessage(Handler.java:103)
        at android.os.Looper.loop(Looper.java:214)
        at android.os.HandlerThread.run(HandlerThread.java:67)
     Caused by: com.google.android.exoplayer2.mediacodec.MediaCodecRenderer$DecoderInitializationException: Decoder init failed: OMX.qcom.video.decoder.avc, Format(1, null, null, video/avc, null, -1, null, [1280, 720, 23.976023], [-1, -1])
        at com.google.android.exoplayer2.mediacodec.MediaCodecRenderer.maybeInitCodecWithFallback(MediaCodecRenderer.java:1052)
        at com.google.android.exoplayer2.mediacodec.MediaCodecRenderer.maybeInitCodecOrBypass(MediaCodecRenderer.java:609)
        at com.google.android.exoplayer2.mediacodec.MediaCodecRenderer.onInputFormatChanged(MediaCodecRenderer.java:1480)
        at com.google.android.exoplayer2.video.MediaCodecVideoRenderer.onInputFormatChanged(MediaCodecVideoRenderer.java:640)
        at com.google.android.exoplayer2.mediacodec.MediaCodecRenderer.readToFlagsOnlyBuffer(MediaCodecRenderer.java:999)
        at com.google.android.exoplayer2.mediacodec.MediaCodecRenderer.render(MediaCodecRenderer.java:849)
        at com.google.android.exoplayer2.ExoPlayerImplInternal.doSomeWork(ExoPlayerImplInternal.java:892)
        at com.google.android.exoplayer2.ExoPlayerImplInternal.handleMessage(ExoPlayerImplInternal.java:467)
        at android.os.Handler.dispatchMessage(Handler.java:103) 
        at android.os.Looper.loop(Looper.java:214) 
        at android.os.HandlerThread.run(HandlerThread.java:67) 
     Caused by: java.lang.IllegalArgumentException: The surface has been released
        at android.media.MediaCodec.native_configure(Native Method)
        at android.media.MediaCodec.configure(MediaCodec.java:2026)
        at android.media.MediaCodec.configure(MediaCodec.java:1954)
        at com.google.android.exoplayer2.mediacodec.SynchronousMediaCodecAdapter.configure(SynchronousMediaCodecAdapter.java:43)
        at com.google.android.exoplayer2.video.MediaCodecVideoRenderer.configureCodec(MediaCodecVideoRenderer.java:580)
        at com.google.android.exoplayer2.mediacodec.MediaCodecRenderer.initCodec(MediaCodecRenderer.java:1148)
        at com.google.android.exoplayer2.mediacodec.MediaCodecRenderer.maybeInitCodecWithFallback(MediaCodecRenderer.java:1045)
        at com.google.android.exoplayer2.mediacodec.MediaCodecRenderer.maybeInitCodecOrBypass(MediaCodecRenderer.java:609) 
        at com.google.android.exoplayer2.mediacodec.MediaCodecRenderer.onInputFormatChanged(MediaCodecRenderer.java:1480) 
        at com.google.android.exoplayer2.video.MediaCodecVideoRenderer.onInputFormatChanged(MediaCodecVideoRenderer.java:640) 
        at com.google.android.exoplayer2.mediacodec.MediaCodecRenderer.readToFlagsOnlyBuffer(MediaCodecRenderer.java:999) 
        at com.google.android.exoplayer2.mediacodec.MediaCodecRenderer.render(MediaCodecRenderer.java:849) 
        at com.google.android.exoplayer2.ExoPlayerImplInternal.doSomeWork(ExoPlayerImplInternal.java:892) 
        at com.google.android.exoplayer2.ExoPlayerImplInternal.handleMessage(ExoPlayerImplInternal.java:467) 
        at android.os.Handler.dispatchMessage(Handler.java:103) 
        at android.os.Looper.loop(Looper.java:214) 
        at android.os.HandlerThread.run(HandlerThread.java:67) 

@Stypox
Copy link
Member Author

Stypox commented Aug 31, 2021

  • @avently video isn't playing and I see thumbnail - Fixed in 45599c7 by completely closing the player when switching video detail with autoplay disabled
  • @TobiGr Please use JavaDoc - Done in b8f16d0
  • I'll explain this is the case in the setting description - Done
  • Also fixed a NPE that happened while testing - ab97f48

@TobiGr TobiGr added the player Issues related to any player (main, popup and background) label Aug 31, 2021
@Stypox
Copy link
Member Author

Stypox commented Sep 1, 2021

  • Renamed isStartMainPlayerFullscreen to isStartMainPlayerFullscreenEnabled (sorry, I forgot about this @TobiGr)
  • Added app:singleLineTitle="false"

@TobiGr TobiGr merged commit 81fa0c1 into TeamNewPipe:dev Sep 1, 2021
@tsiflimagas
Copy link
Contributor

tsiflimagas commented Sep 2, 2021

There seems to be a problem with this. Tapping on the button to go to main player from popup, it opens in fullscreen, even when the option is disabled.

@Stypox
Copy link
Member Author

Stypox commented Sep 3, 2021

@tsiflimagas yes, that's expected. The symbol on the popup fullscreen button is a fullscreen one, hence it should behave as fullscreen always.

@tsiflimagas
Copy link
Contributor

tsiflimagas commented Sep 3, 2021

@Stypox ohh, that's unfortunate for me :) Now there's no way on the popup player to open normally in the main player, so the only way is to open the app and tap on the main player (which has the problem of moving the seekbar to where it was when the video was switched to popup player, not where it was a moment ago (idk if there's already an issue for this)). It felt wrong when the app was rotated, while I just wanted to switch player (and landscape view is really pain in the neck on these long and narrow phones). I hope something new will come up for this.
Btw, I referred to how uncomfortable landscaping is, because the video opens in laptop mode instead of fullscreen (when switching from popup). I remembered about the laptop mode option though, set it to off and now it directly opens in fullscreen. It was auto by default.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment