【问题标题】:how to use DefaultTimeBar outSide of PlayerView in Android如何在 Android 中在 PlayerView 之外使用 DefaultTimeBar
【发布时间】:2021-07-28 15:54:25
【问题描述】:

我正在使用 playerview,我想显示视频的进度。所以我使用了 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>

这是我的要求

【问题讨论】:

    标签: android progress-bar android-progressbar


    【解决方案1】:

    对于这种情况,我有一个解决方法。这个想法是您仍然将 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 的控制器视图可见性被隐藏,进度条上仍然会出现奇怪的动画,但如果它是可见的,那么进度条就会起作用。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-06-18
      • 2018-03-21
      • 1970-01-01
      • 1970-01-01
      • 2022-06-28
      • 2018-09-03
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多