如何在Android中使用PlayerView的DefaultTimeBar outSide

问题描述 投票:0回答:1

我正在使用播放器视图,我想显示视频的进度。所以我使用了PlayerView并在playerview下面使用了LinearLayout,在LinearLayout内部我使用了PlayerView但是我不知道如何将它与Playerview连接。我不想在 Playerview 上有任何控件,它应该在playerview之外。

我的代码如下:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@android:color/black"
android:orientation="vertical">

<com.google.android.exoplayer2.ui.PlayerView
    android:id="@+id/videoView"
    android:layout_width="match_parent"
    android:layout_height="300dp"
    android:layout_marginLeft="50dp"
    android:layout_marginRight="50dp"
    android:background="@android:color/white"
    android:visibility="visible">

</com.google.android.exoplayer2.ui.PlayerView>

     <com.google.android.exoplayer2.ui.DefaultTimeBar
       android:id="@+id/exo_progress1"
       style="@style/Base.Widget.AppCompat.SeekBar"
       android:layout_width="wrap_content"
       android:layout_height="wrap_content" />

</LinearLayout>

这是我的要求

Requirement

android progress-bar android-progressbar
1个回答
0
投票

对于这种情况我有一个解决方法。这个想法是,您仍然将 DefaultTimeBar 放在 PlayerView 控制器布局内,然后手动将 DefaultTimeBar 视图移动到 PlayerView 外部,对于您的情况,它位于 LinearLayout 中。

R.layout.main

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/mainView"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@android:color/black"
    android:orientation="vertical">

    <com.google.android.exoplayer2.ui.PlayerView
        android:id="@+id/videoView"
        android:layout_width="match_parent"
        android:layout_height="300dp"
        android:layout_marginLeft="50dp"
        android:layout_marginRight="50dp"
        android:background="@android:color/white"
        app:controller_layout_id="@layout/exo_playback_control_view" />

</LinearLayout>

R.layout.exo_playback_control_view

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <com.google.android.exoplayer2.ui.DefaultTimeBar
       android:id="@+id/exo_progress"
       style="@style/Base.Widget.AppCompat.SeekBar"
       android:layout_width="wrap_content"
       android:layout_height="wrap_content" />

</RelativeLayout>

然后,在您的活动/片段中的某个位置,手动移动视图(例如,我在这里使用 Kotlin)。

val mainView = findViewById<LinearLayout>(R.id.mainView)
val videoView = findViewById<PlayerView>(R.id.videoView)
val defaultTimeBarView = videoView.findViewById<DefaultTimeBar>(R.id.exo_progress)

val parent = defaultTimeBarView.parent as? ViewGroup
parent?.removeView(defaultTimeBarView)
mainView.addView(defaultTimeBarView)

但是,如果 PlayerView 的控制器视图可见性被隐藏,则进度条上仍然有奇怪的动画,但如果它可见,则进度条可以工作。

© www.soinside.com 2019 - 2024. All rights reserved.