-
-
Couldn't load subscription status.
- Fork 774
Description
`
<com.android.natural.utils.widget.RoundConstraintLayout
android:id="@+id/view_cover"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/white"
android:layout_marginTop="12dp"
app:rcl_radius="25dp">
<!-- 视频区域容器 -->
<com.android.natural.utils.widget.RoundConstraintLayout
android:id="@+id/video_container"
android:layout_width="match_parent"
android:layout_height="194dp"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:rcl_radius="25dp">
<!-- 加载中视图 -->
<com.android.natural.viewbuilder.widget.GradientLoaderView
android:id="@+id/glv_loading"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:borderRadius="24dp"
app:enableAnimation="true" />
<!-- 缩略图 -->
<com.android.natural.utils.widget.RoundImageView
android:visibility="gone"
android:id="@+id/iv_cover"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="fitXY"
app:riv_radius="25dp" />
<!-- 播放按钮 -->
<ImageView
android:visibility="gone"
android:id="@+id/iv_play"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@mipmap/ic_youtube_player"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<!-- 视频播放容器 -->
<com.android.natural.utils.widget.RoundConstraintLayout
android:id="@+id/rcl_video"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:visibility="gone"
app:rcl_radius="15dp">
<com.pierfrancescosoffritti.androidyoutubeplayer.core.player.views.YouTubePlayerView
android:id="@+id/youtube_player_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/video_bg_gray_15"
android:visibility="invisible"
app:autoPlay="false"
app:enableAutomaticInitialization="false" />
<ProgressBar
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintTop_toTopOf="parent"
android:id="@+id/progressbar"
android:visibility="gone"
style="@style/Widget.AppCompat.ProgressBar"
android:indeterminateTint="@android:color/white"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true" />
</com.android.natural.utils.widget.RoundConstraintLayout>
</com.android.natural.utils.widget.RoundConstraintLayout>
<androidx.constraintlayout.widget.ConstraintLayout
android:visibility="gone"
android:id="@+id/cl_title_area"
android:paddingBottom="24dp"
app:layout_constraintTop_toBottomOf="@+id/video_container"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<!-- 视频信息区域(移到外层,保持一致位置) -->
<TextView
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintStart_toStartOf="parent"
android:id="@+id/tv_title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="24dp"
android:layout_marginTop="16dp"
android:layout_marginEnd="24dp"
android:ellipsize="end"
android:singleLine="true"
android:textColor="@color/color_12192B"
android:textSize="14sp"
android:textStyle="bold" />
<com.android.natural.utils.widget.RoundImageView
android:id="@+id/iv_logo"
android:layout_width="16dp"
android:layout_height="16dp"
android:layout_marginTop="8dp"
android:background="@color/white"
android:scaleType="fitCenter"
android:src="@mipmap/ic_youtube"
app:layout_constraintStart_toStartOf="@+id/tv_title"
app:layout_constraintTop_toBottomOf="@+id/tv_title"
app:riv_radius="10dp" />
<TextView
android:id="@+id/tv_source"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:text="@string/youtube"
android:textColor="@color/color_12192B"
android:textSize="12sp"
app:layout_constraintBottom_toBottomOf="@+id/iv_logo"
app:layout_constraintStart_toEndOf="@+id/iv_logo"
app:layout_constraintTop_toTopOf="@+id/iv_logo" />
<TextView
android:id="@+id/tv_dot"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:text="@string/dot_separator"
android:textColor="@color/color_B8BABF"
android:textSize="12sp"
app:layout_constraintBottom_toBottomOf="@+id/iv_logo"
app:layout_constraintStart_toEndOf="@+id/tv_source"
app:layout_constraintTop_toTopOf="@+id/iv_logo" />
<TextView
android:id="@+id/tv_lenght"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:text="@string/video_length"
android:textColor="@color/color_12192B"
android:textSize="12sp"
app:layout_constraintBottom_toBottomOf="@+id/iv_logo"
app:layout_constraintStart_toEndOf="@+id/tv_dot"
app:layout_constraintTop_toTopOf="@+id/iv_logo" />
</androidx.constraintlayout.widget.ConstraintLayout>
</com.android.natural.utils.widget.RoundConstraintLayout>
This is my layout.Default height: 194 When I set the value through code as youtubePlayerView.layoutParams = FrameLayout.LayoutParams( ViewGroup.LayoutParams.MATCH_PARENT,
ViewGroup.LayoutParams.MATCH_PARENT
).apply {
gravity = android.view.Gravity.CENTER
}`,
The video will play frame by frame.
However, when I set
youtubePlayerView.layoutParams = FrameLayout.LayoutParams( ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT ).apply { gravity = android.view.Gravity.CENTER }
no problem.
This is the code I executed when the screen was full:
`fun handleFullscreenToggle() {
val rootView = fragViewBuilder?.view ?: return
val displayMetrics = rootView.context.resources.displayMetrics
val screenWidth = displayMetrics.widthPixels
val screenHeight = displayMetrics.heightPixels
// 确保搜索容器存在
var searchContainer = rootView.findViewById<FrameLayout>(R.id.search_container)
// **这里才会执行!设置容器为屏幕尺寸**
XLog.d("searchContainer已存在,设置为屏幕尺寸: ${screenWidth}x${screenHeight}")
searchContainer.layoutParams = FrameLayout.LayoutParams(
ViewGroup.LayoutParams.MATCH_PARENT,
ViewGroup.LayoutParams.MATCH_PARENT
)
searchContainer.setBackgroundColor(Color.BLACK)
// **确保现有容器也阻止穿透**
searchContainer.isClickable = true
searchContainer.isFocusable = true
// **设置点击监听器**
searchContainer.setOnClickListener {
// 点击背景区域时退出全屏
// if (isFullscreen) {
// handleFullscreenToggle()
// }
}
// 切换全屏状态
isFullscreen = !isFullscreen
fragViewBuilder?.mViewModel?.isFullscreenVideo = isFullscreen
if (isFullscreen) {
// 全屏时允许横屏
fragViewBuilder?.activity?.requestedOrientation =
android.content.pm.ActivityInfo.SCREEN_ORIENTATION_SENSOR
val parent = youtubePlayerView.parent as? ViewGroup ?: return
val index = parent.indexOfChild(youtubePlayerView)
searchContainer.removeAllViews()
youtubePlayerView.post {
parent.removeView(youtubePlayerView)
searchContainer.addView(
youtubePlayerView, FrameLayout.LayoutParams(
ViewGroup.LayoutParams.MATCH_PARENT,
ViewGroup.LayoutParams.MATCH_PARENT
)
)
defaultPlayerUiController?.rootView?.layoutParams = FrameLayout.LayoutParams(
ViewGroup.LayoutParams.MATCH_PARENT,
ViewGroup.LayoutParams.MATCH_PARENT
)
youtubePlayerView.layoutParams = FrameLayout.LayoutParams(
ViewGroup.LayoutParams.MATCH_PARENT,
ViewGroup.LayoutParams.MATCH_PARENT
).apply {
gravity = android.view.Gravity.CENTER
}
}
}
}`
Could you please help me figure out why it gets stuck when in full-screen mode? For your demo, the full-screen Activity I ran did not have any lag. Mine is a RecyclerView and it needs to have a default fixed height of 194dp.