有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java ExoPlayer:将控制器放置在视频下方,不与视频重叠

我有一个PlayerView以纵向方向占据活动的上半部分,屏幕的下半部分显示一些文本

我需要让控制器位于视频下方,而不与视频内容重叠(它将始终显示)。默认情况下,当用户触摸视频时,控制器出现在视频底部,覆盖视频的底部。在我的情况下,我需要控制器粘在视频下,与视频内容没有交叉点

我浏览了SimpleExoPlayerPlayerViewAPI,但没有找到任何方法

问题:如何使用ExoPlayer将控制器放置在视频下方

以下是布局的外观:

<RelativeLayout xmlns:安卓="http://schemas.安卓.com/apk/res/安卓"
    安卓:layout_width="match_parent"
    安卓:layout_height="match_parent">

    <com.google.安卓.exoplayer2.ui.PlayerView
        安卓:id="@+id/video_view"
        安卓:layout_width="match_parent"
        安卓:layout_height="wrap_content"/>

    <TextView
        安卓:id="@+id/text"
        安卓:layout_width="wrap_content"
        安卓:layout_height="wrap_content"
        安卓:layout_alignParentStart="true"
        安卓:layout_below="@id/video_view"
        安卓:scrollbars="vertical" />

</RelativeLayout>

共 (3) 个答案

  1. # 1 楼答案

    请参阅皮埃尔的回答
    还要从上面删除控制器PlayerView,在这种情况下,通过在java文件中写入player.showController(false)来删除控制器
    您还可以在xml中使用app:use_controller:false
    因此,您将是唯一一个顶部没有控制器的视频。并将其链接到视频底部的新控制器上

  2. # 2 楼答案

    这可能会给你一个主意,你也是吗

    例如,假设我们希望播放控件仅包含位于视图中心的播放/暂停按钮。我们可以通过在应用程序的res/layout目录中创建exo_playback_control_view.xml文件来实现这一点,该文件包含:

    <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="match_parent">
    
      <ImageButton android:id="@id/exo_play"
          android:layout_width="100dp"
          android:layout_height="100dp"
          android:layout_gravity="center"
          android:background="#CC000000"
          style="@style/ExoMediaButton.Play"/>
    
      <ImageButton android:id="@id/exo_pause"
          android:layout_width="100dp"
          android:layout_height="100dp"
          android:layout_gravity="center"
          android:background="#CC000000"
          style="@style/ExoMediaButton.Pause"/>
    
    </FrameLayout>
    

    请注意,在布局中@id/exo_play@id/exo_pause是由ExoPlayer库定义的标准ID。需要使用标准ID,以便可以识别子视图,将其绑定到播放器并以适当的方式更新。每个视图的标准ID的完整列表可以在PlaybackControlViewSimpleExoPlayerView的Javadoc中找到。每个标准id的使用是可选的

    https://medium.com/google-exoplayer/customizing-exoplayers-ui-components-728cf55ee07a

  3. # 3 楼答案

    这会将控件向下推至屏幕底部:

    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        android:layout_width="match_parent"
        android:layout_height="match_parent">
    
        <com.google.android.exoplayer2.ui.PlayerView
            android:id="@+id/video_view"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            app:use_controller="false" />
    
        <com.google.android.exoplayer2.ui.PlayerControlView
            android:id="@+id/controls"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_below="@id/video_view"
            app:show_timeout="0" />
       
    </RelativeLayout>
    

    然后在Java中:

    PlayerView videoView = findViewById(R.id.video_view);
    PlayerControlView controls = findViewById(R.id.controls);
    controls.setPlayer(videoView.getPlayer());
    

    编辑:修改了我对@RashimiGautam建议的回答