diff --git a/app/src/main/java/com/futo/platformplayer/fragment/mainactivity/main/VideoDetailFragment.kt b/app/src/main/java/com/futo/platformplayer/fragment/mainactivity/main/VideoDetailFragment.kt index 98df01cd..462471b3 100644 --- a/app/src/main/java/com/futo/platformplayer/fragment/mainactivity/main/VideoDetailFragment.kt +++ b/app/src/main/java/com/futo/platformplayer/fragment/mainactivity/main/VideoDetailFragment.kt @@ -41,7 +41,7 @@ class VideoDetailFragment : MainFragment { private var _viewDetail : VideoDetailView? = null; private var _view : SingleViewTouchableMotionLayout? = null; - private var isFullscreen : Boolean = false; + var isFullscreen : Boolean = false; var isMinimizing : Boolean = false; private var isSmallWindow : Boolean = true; val onFullscreenChanged = Event1(); diff --git a/app/src/main/java/com/futo/platformplayer/fragment/mainactivity/main/VideoDetailView.kt b/app/src/main/java/com/futo/platformplayer/fragment/mainactivity/main/VideoDetailView.kt index aaa60eb2..d49f3e46 100644 --- a/app/src/main/java/com/futo/platformplayer/fragment/mainactivity/main/VideoDetailView.kt +++ b/app/src/main/java/com/futo/platformplayer/fragment/mainactivity/main/VideoDetailView.kt @@ -2434,7 +2434,7 @@ class VideoDetailView : ConstraintLayout { _overlayContainer.removeAllViews(); _overlay_quality_selector?.hide(); - _player.fillHeight(); + _player.fillHeight(false) _layoutPlayerContainer.setPadding(0, 0, 0, 0); } fun handleLeavePictureInPicture() { @@ -2570,7 +2570,7 @@ class VideoDetailView : ConstraintLayout { else { if(_player.layoutParams.height == WRAP_CONTENT) { _player.layoutParams = FrameLayout.LayoutParams(MATCH_PARENT, MATCH_PARENT); - _player.fillHeight(); + _player.fillHeight(true) _cast.layoutParams = _cast.layoutParams.apply { (this as MarginLayoutParams).bottomMargin = 0; }; @@ -2646,8 +2646,12 @@ class VideoDetailView : ConstraintLayout { override fun onConfigurationChanged(newConfig: Configuration?) { super.onConfigurationChanged(newConfig) - - setVideoMinimize(_minimizeProgress) + if (fragment.state == VideoDetailFragment.State.MINIMIZED) { + setVideoMinimize(_minimizeProgress) + } + if (!fragment.isFullscreen) { + _player.fitHeight() + } } fun setVideoMinimize(value: Float) { diff --git a/app/src/main/java/com/futo/platformplayer/views/video/FutoVideoPlayer.kt b/app/src/main/java/com/futo/platformplayer/views/video/FutoVideoPlayer.kt index a40d9906..cd3fc3e9 100644 --- a/app/src/main/java/com/futo/platformplayer/views/video/FutoVideoPlayer.kt +++ b/app/src/main/java/com/futo/platformplayer/views/video/FutoVideoPlayer.kt @@ -20,7 +20,6 @@ import androidx.annotation.OptIn import androidx.constraintlayout.widget.ConstraintLayout import androidx.core.content.ContextCompat import androidx.core.view.setMargins -import androidx.media3.common.C import androidx.media3.common.PlaybackParameters import androidx.media3.common.VideoSize import androidx.media3.common.util.UnstableApi @@ -111,7 +110,9 @@ class FutoVideoPlayer : FutoVideoPlayerBase { private val _author_fullscreen: TextView; private var _shouldRestartHideJobOnPlaybackStateChange: Boolean = false; - private var _lastSourceFit: Int? = null; + private var _lastSourceFit: Float? = null; + private var _lastWindowWidth: Int = resources.configuration.screenWidthDp + private var _lastWindowHeight: Int = resources.configuration.screenHeightDp private var _originalBottomMargin: Int = 0; private var _isControlsLocked: Boolean = false; @@ -632,7 +633,7 @@ class FutoVideoPlayer : FutoVideoPlayerBase { private fun fitOrFill(fullScreen: Boolean) { if (fullScreen) { - fillHeight(); + fillHeight(false); } else { fitHeight(); } @@ -655,7 +656,7 @@ class FutoVideoPlayer : FutoVideoPlayerBase { gestureControl.resetZoomPan() _lastSourceFit = null; if(isFullScreen) - fillHeight(); + fillHeight(false); else if(_root.layoutParams.height != MATCH_PARENT) fitHeight(videoSize); } @@ -719,67 +720,68 @@ class FutoVideoPlayer : FutoVideoPlayerBase { //Sizing @OptIn(UnstableApi::class) fun fitHeight(videoSize: VideoSize? = null) { - Logger.i(TAG, "Video Fit Height"); + Logger.i(TAG, "Video Fit Height") if (_originalBottomMargin != 0) { - val layoutParams = _videoView.layoutParams as ConstraintLayout.LayoutParams; - layoutParams.setMargins(0, 0, 0, _originalBottomMargin); - _videoView.layoutParams = layoutParams; + val layoutParams = _videoView.layoutParams as ConstraintLayout.LayoutParams + layoutParams.setMargins(0, 0, 0, _originalBottomMargin) + _videoView.layoutParams = layoutParams } var h = videoSize?.height ?: lastVideoSource?.height ?: exoPlayer?.player?.videoSize?.height - ?: 0; + ?: 0 var w = - videoSize?.width ?: lastVideoSource?.width ?: exoPlayer?.player?.videoSize?.width ?: 0; + 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; + w = 1280 + h = 720 } - if (_lastSourceFit == null) { - val metrics = StateApp.instance.displayMetrics ?: resources.displayMetrics; + val configuration = resources.configuration - 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 windowWidth = configuration.screenWidthDp + val windowHeight = configuration.screenHeightDp - val determinedHeight = if (w > h) - ((h * (viewWidth.toDouble() / w)).toInt()) + if (_lastSourceFit == null || windowWidth != _lastWindowWidth || windowHeight != _lastWindowHeight) { + val maxHeight = windowHeight * 0.4f + + val aspectRatio = h.toFloat() / w + val determinedHeight = (aspectRatio * windowWidth) + + _lastSourceFit = determinedHeight + _lastSourceFit = _lastSourceFit!!.coerceAtLeast(250f) + _lastSourceFit = _lastSourceFit!!.coerceAtMost(maxHeight) + + _desiredResizeModePortrait = if (_lastSourceFit != determinedHeight) + AspectRatioFrameLayout.RESIZE_MODE_FIT 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}" - ); - } + AspectRatioFrameLayout.RESIZE_MODE_ZOOM - _desiredResizeModePortrait = AspectRatioFrameLayout.RESIZE_MODE_FIT; - _videoView.resizeMode = _desiredResizeModePortrait + _lastWindowWidth = windowWidth + _lastWindowHeight = windowHeight } _videoView.resizeMode = _desiredResizeModePortrait val marginBottom = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 7f, resources.displayMetrics) - .toInt(); - val rootParams = LayoutParams(LayoutParams.MATCH_PARENT, _lastSourceFit!! + marginBottom) - rootParams.bottomMargin = marginBottom; + .toInt() + val height = TypedValue.applyDimension( + TypedValue.COMPLEX_UNIT_DIP, + _lastSourceFit!!, + resources.displayMetrics + ) + val rootParams = LayoutParams(LayoutParams.MATCH_PARENT, (height + marginBottom).toInt()) + rootParams.bottomMargin = marginBottom _root.layoutParams = rootParams - isFitMode = true; + isFitMode = true } @OptIn(UnstableApi::class) - fun fillHeight() { + fun fillHeight(isMiniPlayer: Boolean) { Logger.i(TAG, "Video Fill Height"); val layoutParams = _videoView.layoutParams as ConstraintLayout.LayoutParams; _originalBottomMargin = @@ -792,7 +794,10 @@ class FutoVideoPlayer : FutoVideoPlayerBase { _root.layoutParams = rootParams; _root.invalidate(); - _videoView.resizeMode = AspectRatioFrameLayout.RESIZE_MODE_ZOOM + if(isMiniPlayer){ + _videoView.resizeMode = AspectRatioFrameLayout.RESIZE_MODE_ZOOM + } + isFitMode = false; }