【问题标题】:ExoPlayer: Place controller under the video without overlapping the videoExoPlayer:将控制器放置在视频下方而不与视频重叠
【发布时间】:2019-01-12 14:50:54
【问题描述】:

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

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

我浏览了SimpleExoPlayerPlayerView API,但我没有找到任何方法。

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

下面是布局的样子:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    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"/>

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

</RelativeLayout>

【问题讨论】:

  • 您应该通过将 exoplayer 作为模块导入来编辑 exoplayer 布局
  • 能否将您的问题的图片发布为更好的理解
  • @WaleedAsim 现在无法发帖。但我用更多解释更新了这个问题(希望现在很清楚)。

标签: java android exoplayer exoplayer2.x


【解决方案1】:

这可能会给你一个想法,你也有tried to override the controls吗?

例如,假设我们希望播放控件仅包含位于视图中心的播放/暂停按钮。我们可以通过在应用程序的 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,以便可以识别子视图、绑定到播放器并以适当的方式更新。可以在PlaybackControlViewSimpleExoPlayerView 的Javadoc 中找到每个视图的标准ID 的完整列表。每个标准 id 的使用是可选的。

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

【讨论】:

  • 我知道如何隐藏除播放和暂停之外的所有按钮。但是如何将控制栏粘贴在视频视图下方?
  • 你可以覆盖控制栏,然后放在视频下面
【解决方案2】:

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

<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

建议的回答

【讨论】:

  • 谢谢。这样我就可以同时拥有两个控件。你知道怎么去掉原来的吗?
  • @OleksandrShpota 看看编辑后的答案是否适合你
  • 谢谢。有效。虽然 PlaybackControlView 已被弃用 - 我将其替换为 PlayerControlView
  • 你不能在controls.setPlayer(videoView)中设置PlayerView。
  • 您需要将 ExoPlayer 引用传递给 controls.setPlayer(player)
【解决方案3】:

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

【讨论】:

    猜你喜欢
    • 2014-04-25
    • 2015-07-24
    • 2012-12-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-08-05
    • 1970-01-01
    相关资源
    最近更新 更多