我最近在我的android项目中添加了exoplayer。由于他们的网站,设置和播放音频片段相对简单。我可以从我的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"
    />

最佳答案

仔细查看文档后,我发现以下信息:
在布局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

关于android - ExoPlayer - 在整个音频剪辑播放过程中显示PlayerControlView,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/51579006/

10-11 13:46