ExoPlayer-在播放音频剪辑的整个过程中显示PlayerControlView

时间:2018-07-29 09:34:54

标签: android exoplayer

我最近将ExoPlayer添加到了我的Android项目中。有了他们的网站,设置它并播放音频剪辑相对简单。我可以从我的API中获取音频文件并进行播放,但是问题是,播放开始后,PlayerControlView消失了。有没有一种方法可以强制PlayerControlView在音频剪辑的整个播放过程中停留?这是我的包含PlayerControlView的片段的XML:

<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto"
tools:context=".SetupWizard.NewHouseInformationFragment"
android:orientation="vertical">
<TextView android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_margin="5dp"
    app:layout_constraintTop_toTopOf="parent"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintEnd_toEndOf="parent"
    android:text="@string/why_join_a_house_string"
    android:fontFamily="sans-serif-light"
    android:textColor="@android:color/black"
    android:id = "@+id/HouseDescriptionTitleTextView"
    />
<TextView
    android:id = "@+id/WhyCreateHouseTitleTextView"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:textSize="18sp"
    android:fontFamily="sans-serif-medium"
    android:text="@string/why_create_house_string"
    android:textColor="@android:color/black"
    app:layout_constraintTop_toBottomOf="@id/HouseDescriptionTitleTextView"
    android:layout_margin="5dp"/>
<TextView
    android:fontFamily="sans-serif-light"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintStart_toStartOf="parent"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:text="@string/manage_your_niche_network"
    android:drawableStart="@drawable/ic_check"
    android:drawablePadding="5dp"
    android:layout_margin="5dp"
    android:id = "@+id/CreateNicheNetworksTextView"
    android:textColor="@android:color/black"
    app:layout_constraintTop_toBottomOf="@id/WhyCreateHouseTitleTextView"/>
<TextView
    android:fontFamily="sans-serif-light"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:textColor="@android:color/black"
    android:text="@string/share_content_string"
    android:drawableStart="@drawable/ic_check"
    android:drawablePadding="5dp"
    android:layout_margin="5dp"
    android:id = "@+id/ShareMultimediaTextView"
    app:layout_constraintTop_toBottomOf="@id/CreateNicheNetworksTextView"
    />
<TextView
    android:fontFamily="sans-serif-light"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:textColor="@android:color/black"
    android:text="@string/send_broadcasts_messages"
    android:id = "@+id/SendBroadcastsTextView"
    android:layout_margin="5dp"
    android:drawableStart="@drawable/ic_check"
    android:drawablePadding="5dp"
    app:layout_constraintTop_toBottomOf="@id/ShareMultimediaTextView"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintEnd_toEndOf="parent"
    />
<ImageView
    android:layout_width="match_parent"
    android:layout_height="0dp"
    android:id = "@+id/NewHouseContentImage"
    app:layout_constraintTop_toBottomOf="@id/FullControlTextView"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintVertical_weight="1"
    android:layout_margin="5dp"
    app:srcCompat = "@drawable/ic_chatting"
    android:adjustViewBounds="true"
    app:layout_constraintBottom_toTopOf="@id/CreateHousePlayerView"/>
<TextView
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:text="@string/be_your_own_boss"
    android:textColor="@android:color/black"
    android:fontFamily="sans-serif-light"
    android:drawableStart="@drawable/ic_check"
    app:layout_constraintTop_toBottomOf="@id/SendBroadcastsTextView"
    android:layout_margin="5dp"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintEnd_toEndOf="parent"
    android:drawablePadding="5dp"
    android:id = "@+id/FullControlTextView"/>
<com.google.android.exoplayer2.ui.PlayerControlView
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    app:layout_constraintBottom_toBottomOf="parent"
    android:id = "@+id/CreateHousePlayerView"
    android:layout_margin="5dp"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintEnd_toEndOf="parent"
    />

1 个答案:

答案 0 :(得分:3)

仔细阅读文档后,我发现了以下信息:

  

在布局XML文件中使用时,可以在PlayerControlView上设置以下属性:

     

show_timeout-上一次用户互动与互动之间的时间   控件会自动隐藏(以毫秒为单位)。如果使用零   控件不应自动超时。

因此,我进入PlayerControlView并将show_timeout属性设置为零。现在,播放器控件视图在一段时间后不会消失。

<com.google.android.exoplayer2.ui.PlayerControlView
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    app:show_timeout="0"
    app:layout_constraintBottom_toBottomOf="parent"
    android:id = "@+id/CreateHousePlayerView"
    android:layout_margin="5dp"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintTop_toBottomOf="@id/NewHouseContentImage"
    />

来源:https://google.github.io/ExoPlayer/doc/reference/com/google/android/exoplayer2/ui/PlayerControlView.html