2016-09-15 1 views
0

Im, использующий Exoplayer для воспроизведения видео в моем приложении для Android. Я хочу разместить кнопку воспроизведения/паузы в середине видеопроигрывателя (как на изображении ниже). Как достичь этого enter image description hereКнопка Android ExoPlayer, Play/Pause в середине VideoPlayer

Im просто раздувает новый макет вместо стандартного MediaController для Android. Им интересно, это правильный путь, чтобы получить ниже вид макета изображения

media_controller.xml

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="match_parent" 
android:layout_height="wrap_content" 
android:layout_gravity="center" 
android:background="#CC000000" 
android:orientation="vertical"> 

<LinearLayout 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:paddingTop="4dip" 
    android:orientation="horizontal"> 


    <ImageButton android:id="@+id/pause" 
     style="@android:style/MediaButton.Play" 
     android:layout_gravity="center_horizontal" 
     android:contentDescription="play/pause" /> 

    <TextView android:id="@+id/time_current" 
     android:textSize="14sp" 
     android:textStyle="bold" 
     android:paddingTop="4dip" 
     android:paddingLeft="4dip" 
     android:layout_gravity="center_horizontal" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:paddingRight="4dip" /> 

    <SeekBar 
     android:id="@+id/mediacontroller_progress" 
     style="?android:attr/progressBarStyleHorizontal" 
     android:layout_width="0dip" 
     android:layout_weight="1" 
     android:layout_height="32dip" /> 

    <TextView android:id="@+id/time" 
     android:textSize="14sp" 
     android:textStyle="bold" 
     android:paddingTop="4dip" 
     android:paddingRight="4dip" 
     android:layout_gravity="center_horizontal" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:paddingLeft="4dip" /> 

</LinearLayout> 

+0

вы пытались создать кнопки и добавить их в макет? –

+0

Я пробовал, но кнопки идут внизу –

+0

вы можете разместить свой макет и показать мне, где именно вы пытались добавить эти кнопки? –

ответ

2

Это может быть достигнуто в Exoplayer 2.1.0. Библиотека Exoplayer имеет способ определить наши собственные макеты для воспроизведения Media Controller, называется PlayBackControllerView. Это может быть достигнуто путем переопределения файлов макета. Чтобы настроить эти макеты, приложение может определять файлы макета с одинаковыми именами в своих собственных каталогах res/layout *. Эти файлы макета переопределяют те, которые предоставляются библиотекой ExoPlayer. Мы можем добиться этого, создав файл exo_playback_control_view.xml в каталоге res/layout приложения.

exo_playback_control_view.xml

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:layout_gravity="bottom" 
    android:layoutDirection="ltr" 
    android:background="#22000000"> 

    <LinearLayout 
     android:id="@+id/play_pause_layout" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_centerInParent="true" 
     android:paddingTop="4dp" 
     android:orientation="horizontal" 
     android:gravity="center"> 

     <ImageButton android:id="@id/exo_play" 
      style="@style/ExoMediaButton.Play"/> 

     <ImageButton android:id="@id/exo_pause" 
      style="@style/ExoMediaButton.Pause"/> 

    </LinearLayout> 

    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_marginTop="4dp" 
     android:gravity="center_vertical" 
     android:layout_alignParentBottom="true" 
     android:orientation="horizontal"> 

     <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"/> 

     <SeekBar android:id="@id/exo_progress" 
      android:layout_width="0dp" 
      android:layout_weight="1" 
      android:layout_height="32dp" 
      android:focusable="false" 
      style="?android:attr/progressBarStyleHorizontal"/> 

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

</RelativeLayout> 

Ref: Customizing Exoplayer's UI components

Смежные вопросы