代码之家  ›  专栏  ›  技术社区  ›  Sasha Shpota A-Bag

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

  •  12
  • Sasha Shpota A-Bag  · 技术社区  · 6 年前

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

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

    我经历了 SimpleExoPlayer 播放视图 但我还没找到办法。

    问题: 如何使用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>
    
    3 回复  |  直到 6 年前
        1
  •  15
  •   Sasha Shpota A-Bag    6 年前

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

    <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);
    

    编辑: 修改了我对来自 @木槿

        2
  •  5
  •   Man    6 年前

    参考答案 @皮埃尔 .
    同时从上面移除控制器 PlayerView ,在这种情况下, @id/video_view 通过写作 player.showController(false) 在java文件中。
    你也可以使用 app:use_controller:false 在xml中。
    所以你将是唯一没有控制器的视频。把它连接到一个新的控制器上,在这种情况下, @id/controls 在视频的底部。

        3
  •  3
  •   Tejashwi Kalp Taru    6 年前

    这可能会给你一个主意,你也有 tried to override the controls ?

    例如,假设我们希望回放控件仅由位于视图中心的播放/暂停按钮组成。我们可以通过创造 exo_playback_control_view.xml 应用程序res/layout目录中的文件,包含:

    <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的完整列表可以在 PlaybackControlView SimpleExoPlayerView . 每个标准id的使用都是可选的。

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

    推荐文章