mirror of
https://gitlab.futo.org/videostreaming/grayjay.git
synced 2025-08-08 09:09:48 +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 _viewDetail : VideoDetailView? = null;
|
||||||
private var _view : SingleViewTouchableMotionLayout? = null;
|
private var _view : SingleViewTouchableMotionLayout? = null;
|
||||||
|
|
||||||
private var isFullscreen : Boolean = false;
|
var isFullscreen : Boolean = false;
|
||||||
var isMinimizing : Boolean = false;
|
var isMinimizing : Boolean = false;
|
||||||
private var isSmallWindow : Boolean = true;
|
private var isSmallWindow : Boolean = true;
|
||||||
val onFullscreenChanged = Event1<Boolean>();
|
val onFullscreenChanged = Event1<Boolean>();
|
||||||
|
|
|
@ -2434,7 +2434,7 @@ class VideoDetailView : ConstraintLayout {
|
||||||
_overlayContainer.removeAllViews();
|
_overlayContainer.removeAllViews();
|
||||||
_overlay_quality_selector?.hide();
|
_overlay_quality_selector?.hide();
|
||||||
|
|
||||||
_player.fillHeight();
|
_player.fillHeight(false)
|
||||||
_layoutPlayerContainer.setPadding(0, 0, 0, 0);
|
_layoutPlayerContainer.setPadding(0, 0, 0, 0);
|
||||||
}
|
}
|
||||||
fun handleLeavePictureInPicture() {
|
fun handleLeavePictureInPicture() {
|
||||||
|
@ -2570,7 +2570,7 @@ class VideoDetailView : ConstraintLayout {
|
||||||
else {
|
else {
|
||||||
if(_player.layoutParams.height == WRAP_CONTENT) {
|
if(_player.layoutParams.height == WRAP_CONTENT) {
|
||||||
_player.layoutParams = FrameLayout.LayoutParams(MATCH_PARENT, MATCH_PARENT);
|
_player.layoutParams = FrameLayout.LayoutParams(MATCH_PARENT, MATCH_PARENT);
|
||||||
_player.fillHeight();
|
_player.fillHeight(true)
|
||||||
_cast.layoutParams = _cast.layoutParams.apply {
|
_cast.layoutParams = _cast.layoutParams.apply {
|
||||||
(this as MarginLayoutParams).bottomMargin = 0;
|
(this as MarginLayoutParams).bottomMargin = 0;
|
||||||
};
|
};
|
||||||
|
@ -2646,9 +2646,13 @@ class VideoDetailView : ConstraintLayout {
|
||||||
|
|
||||||
override fun onConfigurationChanged(newConfig: Configuration?) {
|
override fun onConfigurationChanged(newConfig: Configuration?) {
|
||||||
super.onConfigurationChanged(newConfig)
|
super.onConfigurationChanged(newConfig)
|
||||||
|
if (fragment.state == VideoDetailFragment.State.MINIMIZED) {
|
||||||
setVideoMinimize(_minimizeProgress)
|
setVideoMinimize(_minimizeProgress)
|
||||||
}
|
}
|
||||||
|
if (!fragment.isFullscreen) {
|
||||||
|
_player.fitHeight()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fun setVideoMinimize(value: Float) {
|
fun setVideoMinimize(value: Float) {
|
||||||
val totalPaddingNeeded = value * max(
|
val totalPaddingNeeded = value * max(
|
||||||
|
|
|
@ -20,7 +20,6 @@ import androidx.annotation.OptIn
|
||||||
import androidx.constraintlayout.widget.ConstraintLayout
|
import androidx.constraintlayout.widget.ConstraintLayout
|
||||||
import androidx.core.content.ContextCompat
|
import androidx.core.content.ContextCompat
|
||||||
import androidx.core.view.setMargins
|
import androidx.core.view.setMargins
|
||||||
import androidx.media3.common.C
|
|
||||||
import androidx.media3.common.PlaybackParameters
|
import androidx.media3.common.PlaybackParameters
|
||||||
import androidx.media3.common.VideoSize
|
import androidx.media3.common.VideoSize
|
||||||
import androidx.media3.common.util.UnstableApi
|
import androidx.media3.common.util.UnstableApi
|
||||||
|
@ -111,7 +110,9 @@ class FutoVideoPlayer : FutoVideoPlayerBase {
|
||||||
private val _author_fullscreen: TextView;
|
private val _author_fullscreen: TextView;
|
||||||
private var _shouldRestartHideJobOnPlaybackStateChange: Boolean = false;
|
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 _originalBottomMargin: Int = 0;
|
||||||
|
|
||||||
private var _isControlsLocked: Boolean = false;
|
private var _isControlsLocked: Boolean = false;
|
||||||
|
@ -632,7 +633,7 @@ class FutoVideoPlayer : FutoVideoPlayerBase {
|
||||||
|
|
||||||
private fun fitOrFill(fullScreen: Boolean) {
|
private fun fitOrFill(fullScreen: Boolean) {
|
||||||
if (fullScreen) {
|
if (fullScreen) {
|
||||||
fillHeight();
|
fillHeight(false);
|
||||||
} else {
|
} else {
|
||||||
fitHeight();
|
fitHeight();
|
||||||
}
|
}
|
||||||
|
@ -655,7 +656,7 @@ class FutoVideoPlayer : FutoVideoPlayerBase {
|
||||||
gestureControl.resetZoomPan()
|
gestureControl.resetZoomPan()
|
||||||
_lastSourceFit = null;
|
_lastSourceFit = null;
|
||||||
if(isFullScreen)
|
if(isFullScreen)
|
||||||
fillHeight();
|
fillHeight(false);
|
||||||
else if(_root.layoutParams.height != MATCH_PARENT)
|
else if(_root.layoutParams.height != MATCH_PARENT)
|
||||||
fitHeight(videoSize);
|
fitHeight(videoSize);
|
||||||
}
|
}
|
||||||
|
@ -719,67 +720,68 @@ class FutoVideoPlayer : FutoVideoPlayerBase {
|
||||||
//Sizing
|
//Sizing
|
||||||
@OptIn(UnstableApi::class)
|
@OptIn(UnstableApi::class)
|
||||||
fun fitHeight(videoSize: VideoSize? = null) {
|
fun fitHeight(videoSize: VideoSize? = null) {
|
||||||
Logger.i(TAG, "Video Fit Height");
|
Logger.i(TAG, "Video Fit Height")
|
||||||
if (_originalBottomMargin != 0) {
|
if (_originalBottomMargin != 0) {
|
||||||
val layoutParams = _videoView.layoutParams as ConstraintLayout.LayoutParams;
|
val layoutParams = _videoView.layoutParams as ConstraintLayout.LayoutParams
|
||||||
layoutParams.setMargins(0, 0, 0, _originalBottomMargin);
|
layoutParams.setMargins(0, 0, 0, _originalBottomMargin)
|
||||||
_videoView.layoutParams = layoutParams;
|
_videoView.layoutParams = layoutParams
|
||||||
}
|
}
|
||||||
|
|
||||||
var h = videoSize?.height ?: lastVideoSource?.height ?: exoPlayer?.player?.videoSize?.height
|
var h = videoSize?.height ?: lastVideoSource?.height ?: exoPlayer?.player?.videoSize?.height
|
||||||
?: 0;
|
?: 0
|
||||||
var w =
|
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) {
|
if (h == 0 && w == 0) {
|
||||||
Logger.i(
|
Logger.i(
|
||||||
TAG,
|
TAG,
|
||||||
"UNKNOWN VIDEO FIT: (videoSize: ${videoSize != null}, player.videoSize: ${exoPlayer?.player?.videoSize != null})"
|
"UNKNOWN VIDEO FIT: (videoSize: ${videoSize != null}, player.videoSize: ${exoPlayer?.player?.videoSize != null})"
|
||||||
);
|
);
|
||||||
w = 1280;
|
w = 1280
|
||||||
h = 720;
|
h = 720
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_lastSourceFit == null) {
|
val configuration = resources.configuration
|
||||||
val metrics = StateApp.instance.displayMetrics ?: resources.displayMetrics;
|
|
||||||
|
|
||||||
val viewWidth = Math.min(
|
val windowWidth = configuration.screenWidthDp
|
||||||
metrics.widthPixels,
|
val windowHeight = configuration.screenHeightDp
|
||||||
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)
|
if (_lastSourceFit == null || windowWidth != _lastWindowWidth || windowHeight != _lastWindowHeight) {
|
||||||
((h * (viewWidth.toDouble() / w)).toInt())
|
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
|
else
|
||||||
((h * (viewWidth.toDouble() / w)).toInt());
|
AspectRatioFrameLayout.RESIZE_MODE_ZOOM
|
||||||
_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}"
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
_desiredResizeModePortrait = AspectRatioFrameLayout.RESIZE_MODE_FIT;
|
_lastWindowWidth = windowWidth
|
||||||
_videoView.resizeMode = _desiredResizeModePortrait
|
_lastWindowHeight = windowHeight
|
||||||
}
|
}
|
||||||
_videoView.resizeMode = _desiredResizeModePortrait
|
_videoView.resizeMode = _desiredResizeModePortrait
|
||||||
|
|
||||||
val marginBottom =
|
val marginBottom =
|
||||||
TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 7f, resources.displayMetrics)
|
TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 7f, resources.displayMetrics)
|
||||||
.toInt();
|
.toInt()
|
||||||
val rootParams = LayoutParams(LayoutParams.MATCH_PARENT, _lastSourceFit!! + marginBottom)
|
val height = TypedValue.applyDimension(
|
||||||
rootParams.bottomMargin = marginBottom;
|
TypedValue.COMPLEX_UNIT_DIP,
|
||||||
|
_lastSourceFit!!,
|
||||||
|
resources.displayMetrics
|
||||||
|
)
|
||||||
|
val rootParams = LayoutParams(LayoutParams.MATCH_PARENT, (height + marginBottom).toInt())
|
||||||
|
rootParams.bottomMargin = marginBottom
|
||||||
_root.layoutParams = rootParams
|
_root.layoutParams = rootParams
|
||||||
isFitMode = true;
|
isFitMode = true
|
||||||
}
|
}
|
||||||
|
|
||||||
@OptIn(UnstableApi::class)
|
@OptIn(UnstableApi::class)
|
||||||
fun fillHeight() {
|
fun fillHeight(isMiniPlayer: Boolean) {
|
||||||
Logger.i(TAG, "Video Fill Height");
|
Logger.i(TAG, "Video Fill Height");
|
||||||
val layoutParams = _videoView.layoutParams as ConstraintLayout.LayoutParams;
|
val layoutParams = _videoView.layoutParams as ConstraintLayout.LayoutParams;
|
||||||
_originalBottomMargin =
|
_originalBottomMargin =
|
||||||
|
@ -792,7 +794,10 @@ class FutoVideoPlayer : FutoVideoPlayerBase {
|
||||||
_root.layoutParams = rootParams;
|
_root.layoutParams = rootParams;
|
||||||
_root.invalidate();
|
_root.invalidate();
|
||||||
|
|
||||||
|
if(isMiniPlayer){
|
||||||
_videoView.resizeMode = AspectRatioFrameLayout.RESIZE_MODE_ZOOM
|
_videoView.resizeMode = AspectRatioFrameLayout.RESIZE_MODE_ZOOM
|
||||||
|
}
|
||||||
|
|
||||||
isFitMode = false;
|
isFitMode = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue