【发布时间】:2018-08-15 09:53:51
【问题描述】:
我正在使用 Exoplayer2 在我的应用程序中显示视频。我需要控件始终可见。我可以通过设置app:show_timeout="0" 来归档它。但是当控件始终可见时,它们会占用 PlayerView 中的空间。
我想在 PlayerView 下方显示控件,以便始终显示到整个视频。
这是我的布局文件:
<?xml version="1.0" encoding="utf-8"?>
<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"
tools:context=".MediaPlayerActivity"
android:theme="@android:style/Theme.NoTitleBar"
android:contentDescription="hf_hide_help">
<com.google.android.exoplayer2.ui.PlayerView
android:id="@+id/playerView"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:use_controller="true"
app:rewind_increment="0"
app:fastforward_increment="0"
app:repeat_toggle_modes="none"
app:show_timeout="0"
/>
</RelativeLayout>
这是我的exo_player_control_view.xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:layoutDirection="ltr"
android:background="#CC000000"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:paddingTop="4dp"
android:orientation="horizontal">
<ImageButton android:id="@id/exo_play"
style="@style/ExoMediaButton.Play"/>
<ImageButton android:id="@id/exo_pause"
style="@style/ExoMediaButton.Pause"/>
<TextView android:id="@id/exo_position"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="14sp"
android:textStyle="bold"
android:paddingLeft="4dp"
android:paddingRight="4dp"
android:includeFontPadding="false"
android:textColor="#FFBEBEBE"/>
<com.google.android.exoplayer2.ui.DefaultTimeBar
android:id="@id/exo_progress"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="26dp"/>
<TextView android:id="@id/exo_duration"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="14sp"
android:textStyle="bold"
android:paddingLeft="4dp"
android:paddingRight="4dp"
android:includeFontPadding="false"
android:textColor="#FFBEBEBE"/>
</LinearLayout>
</LinearLayout>
【问题讨论】:
-
请加个截图好吗?
-
我添加了截图。
-
我已经创建了自定义控件 xml 文件并在 xml 文件中添加到 PlayerView 中,例如 app:controller_layout_id="@layout/custom_controls" 但自定义控件显示在 PlayerView 上而不是在播放器视图之外。请指导我如何在 PlayerView 之外显示自定义控件。? ——
标签: android exoplayer exoplayer2.x