Skip to content
This repository was archived by the owner on Jul 18, 2026. It is now read-only.

Commit aeeefd9

Browse files
committed
修复竖屏视频全屏方向错误的问题
1 parent cac2078 commit aeeefd9

2 files changed

Lines changed: 37 additions & 6 deletions

File tree

app/src/main/java/com/yenaly/han1meviewer/ui/view/video/HJzvdStd.kt

Lines changed: 30 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import android.view.MotionEvent
1616
import android.view.View
1717
import android.view.View.OnLongClickListener
1818
import android.view.ViewGroup
19+
import android.view.animation.DecelerateInterpolator
1920
import android.widget.FrameLayout
2021
import android.widget.ImageView
2122
import android.widget.PopupWindow
@@ -692,8 +693,8 @@ class HJzvdStd @JvmOverloads constructor(
692693
var layoutParams = blockLayoutParams
693694
if (originalContainer is ConstraintLayout) {
694695
layoutParams = savedConstraintLayoutParams ?: ConstraintLayout.LayoutParams(
695-
ViewGroup.LayoutParams.MATCH_PARENT,
696-
ViewGroup.LayoutParams.WRAP_CONTENT
696+
LayoutParams.MATCH_PARENT,
697+
LayoutParams.WRAP_CONTENT
697698
)
698699
} else if (originalContainer is FrameLayout) {
699700
layoutParams = LayoutParams(blockLayoutParams)
@@ -733,14 +734,37 @@ class HJzvdStd @JvmOverloads constructor(
733734
CONTAINER_LIST.add(vg)
734735
val decorView = (JZUtils.scanForActivity(jzvdContext)).window.decorView as ViewGroup
735736
val fullLayout = LayoutParams(
736-
ViewGroup.LayoutParams.MATCH_PARENT,
737-
ViewGroup.LayoutParams.MATCH_PARENT
737+
LayoutParams.MATCH_PARENT,
738+
LayoutParams.MATCH_PARENT
738739
)
740+
val mediaKernel = CURRENT_JZVD?.mediaInterface as? ExoMediaKernel
741+
val videoWidth = mediaKernel?.videoRealWidth?:0
742+
val videoHeight = mediaKernel?.videoRealHeight?:0
743+
val isPortraitVideo = videoWidth > 0 && videoHeight > 0 && videoWidth < videoHeight
744+
if (isPortraitVideo) {
745+
pivotY = 0f
746+
scaleY = 0.5f
747+
}
739748
decorView.addView(this, fullLayout)
749+
if (isPortraitVideo) {
750+
animate()
751+
.scaleY(1f)
752+
.setDuration(300)
753+
.setInterpolator(DecelerateInterpolator())
754+
.start()
755+
}
740756
setScreenFullscreen()
741757
JZUtils.hideStatusBar(jzvdContext)
742-
if (activity != null) {
743-
manager.lockOrientation(activity,OrientationManager.ScreenOrientation.LANDSCAPE)
758+
val targetOrientation = if (videoWidth > 0 && videoHeight > 0) {
759+
if (isPortraitVideo)
760+
OrientationManager.ScreenOrientation.PORTRAIT
761+
else
762+
OrientationManager.ScreenOrientation.LANDSCAPE
763+
} else {
764+
OrientationManager.ScreenOrientation.LANDSCAPE
765+
}
766+
activity?.let {
767+
manager.lockOrientation(it, targetOrientation)
744768
}
745769
JZUtils.hideSystemUI(jzvdContext)
746770
}

app/src/main/java/com/yenaly/han1meviewer/ui/view/video/HMediaKernel.kt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,10 @@ class ExoMediaKernel(jzvd: Jzvd) : JZMediaInterface(jzvd), Player.Listener, HMed
9494
private var callback: Runnable? = null
9595
private var prevSeek = 0L
9696

97+
var videoRealWidth: Int = 0
98+
private set
99+
var videoRealHeight: Int = 0
100+
private set
97101
@OptIn(UnstableApi::class)
98102
override fun prepare() {
99103
if (_exoPlayer != null) {
@@ -178,6 +182,9 @@ class ExoMediaKernel(jzvd: Jzvd) : JZMediaInterface(jzvd), Player.Listener, HMed
178182
override fun onVideoSizeChanged(videoSize: VideoSize) {
179183
val realWidth = videoSize.width * videoSize.pixelWidthHeightRatio
180184
val realHeight = videoSize.height
185+
videoRealWidth = realWidth.toInt()
186+
videoRealHeight = realHeight
187+
Log.i("JZVD-onVideoSizeChanged","realWidth:$realWidth,realHeight:$realHeight")
181188
handler.post {
182189
jzvd.onVideoSizeChanged(realWidth.toInt(), realHeight)
183190
}

0 commit comments

Comments
 (0)