mirror of
https://gitlab.futo.org/videostreaming/grayjay.git
synced 2025-04-20 03:24:50 +00:00
fixed video sizing
This commit is contained in:
parent
e465ec8278
commit
3299261db3
3 changed files with 54 additions and 45 deletions
|
@ -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<Boolean>();
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue