zxzx74147 / ExoPlayer

Fork from https://github.com/google/ExoPlayer , add tranparency support.
Apache License 2.0
19 stars 8 forks source link

创建出来的SimpleExoPlayer,播放视频时会覆盖其他view #6

Open yanjunhui2014 opened 4 months ago

yanjunhui2014 commented 4 months ago
 DefaultRenderersFactory renderersFactory = new DefaultRenderersFactory(context.getApplicationContext());
        mVideoPlayer = new SimpleExoPlayer.Builder(context, renderersFactory)
                .build();

我就这样正常创建,但是返回键被视频挡住了,视频层级没问题。

image

布局文件能看到,imgBack是在最后的。 这种问题怎么解决啊?

        <androidx.constraintlayout.widget.ConstraintLayout
            android:id="@+id/layoutVideo"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            app:layout_constraintTop_toTopOf="parent"
            tools:layout_height="200dp">

            <com.google.android.exoplayer2.ui.PlayerView
                android:id="@+id/playerView"
                android:layout_width="match_parent"
                android:layout_height="200dp"
                android:background="@color/black"
                app:controller_layout_id="@layout/view_dub_video_control"
                app:layout_constraintBottom_toBottomOf="parent"
                app:layout_constraintEnd_toEndOf="parent"
                app:layout_constraintStart_toStartOf="parent"
                app:layout_constraintTop_toTopOf="parent" />

            <com.fz.lib.media.widget.StrokeTextView
                android:id="@+id/mTvSrt"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_centerHorizontal="true"
                android:layout_marginStart="20dp"
                android:layout_marginEnd="20dp"
                android:layout_marginBottom="5dp"
                android:gravity="center"
                android:textColor="@color/lib_media_white"
                android:textSize="15sp"
                app:layout_constraintBottom_toBottomOf="parent"
                app:stroke_color="#000000"
                app:stroke_width="5px" />

            <ImageView
                android:id="@+id/imgCover"
                android:layout_width="0dp"
                android:layout_height="0dp"
                app:layout_constraintBottom_toBottomOf="parent"
                app:layout_constraintEnd_toEndOf="parent"
                app:layout_constraintStart_toStartOf="parent"
                app:layout_constraintTop_toTopOf="parent"
                tools:src="@color/c7" />

            <ProgressBar
                android:id="@+id/pbVideoLoading"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                app:layout_constraintBottom_toBottomOf="parent"
                app:layout_constraintEnd_toEndOf="parent"
                app:layout_constraintStart_toStartOf="parent"
                app:layout_constraintTop_toTopOf="parent" />

            <View
                android:id="@+id/viewVideoClick"
                android:layout_width="0dp"
                android:layout_height="0dp"
                android:layout_marginTop="45dp"
                android:onClick="@{click::onClick}"
                app:layout_constraintBottom_toBottomOf="@+id/playerView"
                app:layout_constraintEnd_toEndOf="@+id/playerView"
                app:layout_constraintStart_toStartOf="@+id/playerView"
                app:layout_constraintTop_toTopOf="@+id/playerView" />

            <ImageView
                android:id="@+id/imgBack"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:onClick="@{click::onClick}"
                android:padding="12dp"
                android:src="@drawable/module_common_ic_video_back_white"
                app:layout_constraintStart_toStartOf="parent"
                app:layout_constraintTop_toTopOf="parent" />

        </androidx.constraintlayout.widget.ConstraintLayout>
yanjunhui2014 commented 4 months ago

我解决了。我看了你修改的代码。

image

知道这一层就好办了

        if (mBinding.playerView.getVideoSurfaceView() instanceof SurfaceView) {
            ((SurfaceView) mBinding.playerView.getVideoSurfaceView()).setZOrderOnTop(false);
        }

这样就解决了。项目里很多地方都用了PlayerView,只有少量的地方是需要置顶的,其余还是要和原PlayerView一样,保持原有层级的。 建议在DefaultRenderersFactory.EXTENSION_RENDERER_MODE_ON是,去掉置顶属性。