futo-org / grayjay-android

Read-only mirror of Grayjay repo for issue tracking
https://gitlab.futo.org/videostreaming/grayjay
Other
761 stars 48 forks source link

Minimizing Video Bug #1145

Open breeze-bot opened 3 months ago

breeze-bot commented 3 months ago

What happened?

Device: Poco F5 (Android 14)

Enlarging a video when it is minimized causes the video to persist it's minimized size state.

Screenshot_20240713-162051_Grayjay

Slightly swiping the video down, or entering fullscreen and exiting, or pausing fixes the problem.

Grayjay Version

249

What plugins are you seeing the problem on?

All, Youtube, Twitch

Plugin Version

Youtube: 185, Twitch: 18

When do you experience the issue?

Relevant log output

No response

michael-oberpriller commented 3 months ago

From my testing, I found that explicitly setting the playerview's height in the fitHeight and fitFill functions within FutoVideoPlayer.kt seems to fix this problem.

    fun fitHeight(videoSize : VideoSize? = null){
        Logger.i(TAG, "Video Fit Height");

        var h = videoSize?.height ?: lastVideoSource?.height ?: exoPlayer?.player?.videoSize?.height ?: 0;
        var w = videoSize?.width ?: lastVideoSource?.width ?: exoPlayer?.player?.videoSize?.width ?: 0;

        if(h == 0 && w == 0) {
            Logger.i(TAG, "UNKNOWN VIDEO FIT: (videoSize: ${videoSize != null}, player.videoSize: ${exoPlayer?.player?.videoSize != null})");
            w = 1280;
            h = 720;
        }

        if(_lastSourceFit == null){
            val metrics = StateApp.instance.displayMetrics ?: resources.displayMetrics;

            val viewWidth = Math.min(metrics.widthPixels, metrics.heightPixels); //TODO: Get parent width. was this.width
            val deviceHeight = Math.max(metrics.widthPixels, metrics.heightPixels);
            val maxHeight = deviceHeight * 0.4;

            val determinedHeight = if(w > h)
                ((h * (viewWidth.toDouble() / w)).toInt())
            else
                ((h * (viewWidth.toDouble() / w)).toInt());
            _lastSourceFit = determinedHeight;
            _lastSourceFit = Math.max(_lastSourceFit!!, 250);
            _lastSourceFit = Math.min(_lastSourceFit!!, maxHeight.toInt());
            if((_lastSourceFit ?: 0) < 300 || (_lastSourceFit ?: 0) > viewWidth) {
                Log.d(TAG, "WEIRD HEIGHT DETECTED: ${_lastSourceFit}, Width: ${w}, Height: ${h}, VWidth: ${viewWidth}");
            }
            if(_lastSourceFit != determinedHeight)
                _videoView.resizeMode = AspectRatioFrameLayout.RESIZE_MODE_FIT;
            else
                _videoView.resizeMode = AspectRatioFrameLayout.RESIZE_MODE_ZOOM;
        }

        val layoutParams = _videoView.layoutParams as ConstraintLayout.LayoutParams;
        layoutParams.setMargins(0, 0, 0, _originalBottomMargin);
        layoutParams.height = _lastSourceFit!!;
        _videoView.layoutParams = layoutParams;

        val marginBottom = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 7f, resources.displayMetrics).toInt();
        val rootParams = LayoutParams(LayoutParams.MATCH_PARENT, _lastSourceFit!! + marginBottom)
        rootParams.bottomMargin = marginBottom;
        _root.layoutParams = rootParams
        isFitMode = true;
    }
    fun fillHeight(){
        Logger.i(TAG, "Video Fill Height");
        val layoutParams = _videoView.layoutParams as ConstraintLayout.LayoutParams;
        _originalBottomMargin = if(layoutParams.bottomMargin > 0) layoutParams.bottomMargin else _originalBottomMargin;
        layoutParams.setMargins(0);
        layoutParams.height = LayoutParams.MATCH_PARENT;
        _videoView.layoutParams = layoutParams;
        _videoView.invalidate();

        val rootParams = LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
        _root.layoutParams = rootParams;
        _root.invalidate();
        isFitMode = false;
    }
cpfotiadis commented 2 months ago

I have the same problem on a Pixel 6a with GrapheneOS and I can confirm that the problem has been around for quite some time. It doesn't matter the plugin, it gives me the exact same problem, whether it's with the YouTube plugin, Rumble, Odysee or BitChute. The problem can be reproduced very easily, as long as we minimize a video while it is playing and then restore it. If we do this several times while the video is playing, the problem will appear for sure.

Slightly swiping the video down, or entering fullscreen and exiting, or pausing fixes the problem.

Also, what the user @breeze-bot wrote about swiping, fullscreen, etc., applies to my case as well.

GrayJay Version:

262

What plugins are you seeing the problem on?

YouTube, Rumble, Odysee, BitChute

Plugin Version

YouTube: 201 Rumble: 45 Odysee: 38 BitChute: 4

Example:

Screenshot_20240907-084326