Media3Exoplayer

修改控制組件的樣式

屬性 controller_layout_id

<?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:id="@+id/main"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity">
   <androidx.media3.ui.PlayerView
       android:id="@+id/player"
       android:layout_width="match_parent"
       app:show_buffering="when_playing"
       app:use_controller="true"
       app:controller_layout_id="@layout/exo_player_control_view"
       app:auto_show="true"
       android:layout_height="300dp"/>
</RelativeLayout>

這個(gè)exo_player_control_view 布局是有講究的注意<merge> 標(biāo)簽
先下載源碼方便看布局
https://github.com/androidx/media
更換 controller_layout_id其實(shí)就是更換 PlayerControlView
進(jìn)入到PlayerControlView的源碼

image.png

看到布局是這樣的
image.png

放進(jìn)我們的項(xiàng)目改一個(gè)顏色試試看

image.png

跑起來(lái)的樣式是


image.png

image.png

image.png

控制組件精簡(jiǎn)后:


image.png
<?xml version="1.0" encoding="utf-8"?><!-- Copyright 2020 The Android Open Source Project

     Licensed under the Apache License, Version 2.0 (the "License");
     you may not use this file except in compliance with the License.
     You may obtain a copy of the License at

          http://www.apache.org/licenses/LICENSE-2.0

     Unless required by applicable law or agreed to in writing, software
     distributed under the License is distributed on an "AS IS" BASIS,
     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     See the License for the specific language governing permissions and
     limitations under the License.
-->
<merge xmlns:tools="http://schemas.android.com/tools"
    xmlns:android="http://schemas.android.com/apk/res/android">

    <!-- 0dp dimensions are used to prevent this view from influencing the size of
         the parent view if it uses "wrap_content". It is expanded to occupy the
         entirety of the parent in code, after the parent's size has been
         determined. See: https://github.com/google/ExoPlayer/issues/8726.
    -->
    <View
        android:id="@id/exo_controls_background"
        android:layout_width="0dp"
        android:layout_height="0dp"
        android:background="@color/exo_black_opacity_60" />
    <!--android:background="@color/exo_bottom_bar_background"-->
    <!--   android:layout_height="@dimen/exo_styled_bottom_bar_height" -->
    <FrameLayout
        android:id="@id/exo_bottom_bar"
        android:layout_width="match_parent"
        android:layout_height="30dp"
        android:layout_gravity="bottom"
        android:layout_marginTop="@dimen/exo_styled_bottom_bar_margin_top"
        android:background="#ff0000">


        <LinearLayout
            android:gravity="center_vertical"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="horizontal"
            tools:ignore="UselessParent">

            <TextView

                android:layout_gravity="center_vertical"
                android:id="@id/exo_position"
                style="@style/ExoStyledControls.TimeText.Position" />


            <androidx.media3.ui.DefaultTimeBar
                android:layout_gravity="center_vertical"
                android:id="@id/exo_progress"
                android:layout_width="0dp"
                android:layout_weight="1"
                android:layout_height="wrap_content"/>

            <TextView
                android:layout_gravity="center_vertical"
                android:id="@id/exo_duration"
                style="@style/ExoStyledControls.TimeText.Duration" />


        </LinearLayout>


        <!--    <LinearLayout android:id="@id/exo_time"-->
        <!--        android:layout_width="wrap_content"-->
        <!--        android:layout_height="wrap_content"-->
        <!--        android:paddingStart="@dimen/exo_styled_bottom_bar_time_padding"-->
        <!--        android:paddingEnd="@dimen/exo_styled_bottom_bar_time_padding"-->
        <!--        android:paddingLeft="@dimen/exo_styled_bottom_bar_time_padding"-->
        <!--        android:paddingRight="@dimen/exo_styled_bottom_bar_time_padding"-->
        <!--       >-->

        <!--      <TextView android:id="@id/exo_position"-->
        <!--          style="@style/ExoStyledControls.TimeText.Position"/>-->

        <!--      <TextView-->
        <!--          style="@style/ExoStyledControls.TimeText.Separator"/>-->

        <!--      <TextView android:id="@id/exo_duration"-->
        <!--          style="@style/ExoStyledControls.TimeText.Duration"/>-->

        <!--    </LinearLayout>-->

        <!--    <LinearLayout android:id="@id/exo_basic_controls"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="center_vertical|end"
                android:layoutDirection="ltr">

              <ImageButton android:id="@id/exo_vr"
                  style="@style/ExoStyledControls.Button.Bottom.VR"/>

              <ImageButton android:id="@id/exo_shuffle"
                  style="@style/ExoStyledControls.Button.Bottom.Shuffle"/>

              <ImageButton android:id="@id/exo_repeat_toggle"
                  style="@style/ExoStyledControls.Button.Bottom.RepeatToggle"/>

              <ImageButton android:id="@id/exo_subtitle"
                  style="@style/ExoStyledControls.Button.Bottom.CC"/>

             &lt;!&ndash; <ImageButton android:id="@id/exo_settings"
                  style="@style/ExoStyledControls.Button.Bottom.Settings"/>
        &ndash;&gt;
              <ImageButton android:id="@id/exo_fullscreen"
                  style="@style/ExoStyledControls.Button.Bottom.FullScreen"/>

              <ImageButton android:id="@id/exo_overflow_show"
                  style="@style/ExoStyledControls.Button.Bottom.OverflowShow"/>

            </LinearLayout>

            <HorizontalScrollView android:id="@id/exo_extra_controls_scroll_view"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="center_vertical|end"
                android:visibility="invisible">

              <LinearLayout android:id="@id/exo_extra_controls"
                  android:layout_width="wrap_content"
                  android:layout_height="wrap_content"
                  android:layoutDirection="ltr">

                <ImageButton android:id="@id/exo_overflow_hide"
                    style="@style/ExoStyledControls.Button.Bottom.OverflowHide"/>

              </LinearLayout>

            </HorizontalScrollView>-->

    </FrameLayout>

    <!--  <View android:id="@id/exo_progress_placeholder"-->
    <!--      android:layout_width="match_parent"-->
    <!--      android:layout_height="@dimen/exo_styled_progress_layout_height"-->
    <!--      android:layout_gravity="bottom"-->
    <!--      android:layout_marginBottom="@dimen/exo_styled_progress_margin_bottom"/>-->

    <!--  <LinearLayout android:id="@id/exo_minimal_controls"-->
    <!--      android:layout_width="wrap_content"-->
    <!--      android:layout_height="wrap_content"-->
    <!--      android:layout_gravity="bottom|end"-->
    <!--      android:layout_marginBottom="@dimen/exo_styled_minimal_controls_margin_bottom"-->
    <!--      android:orientation="horizontal"-->
    <!--      android:gravity="center_vertical"-->
    <!--      android:layoutDirection="ltr">-->

    <!--    <ImageButton android:id="@id/exo_minimal_fullscreen"-->
    <!--        style="@style/ExoStyledControls.Button.Bottom.FullScreen"/>-->

    <!--  </LinearLayout>-->

    <LinearLayout
        android:id="@id/exo_center_controls"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:background="@android:color/transparent"
        android:clipToPadding="false"
        android:gravity="center"
        android:layoutDirection="ltr"
        android:padding="@dimen/exo_styled_controls_padding">

<!--            <ImageButton android:id="@id/exo_prev"-->
<!--                style="@style/ExoStyledControls.Button.Center.Previous"/>-->

<!--            <include layout="@layout/exo_player_control_rewind_button" />-->

        <ImageButton
            android:id="@id/exo_play_pause"
            style="@style/ExoStyledControls.Button.Center.PlayPause" />

<!--            <include layout="@layout/exo_player_control_ffwd_button" />-->

<!--            <ImageButton android:id="@id/exo_next"-->
<!--                style="@style/ExoStyledControls.Button.Center.Next"/>-->

    </LinearLayout>

</merge>

修改播放器 loading的顏色

通過(guò)源碼拿到布局文件 給PlayerView設(shè)置上
源碼中的布局文件
exo_player_view

<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright (C) 2020 The Android Open Source Project

     Licensed under the Apache License, Version 2.0 (the "License");
     you may not use this file except in compliance with the License.
     You may obtain a copy of the License at

          http://www.apache.org/licenses/LICENSE-2.0

     Unless required by applicable law or agreed to in writing, software
     distributed under the License is distributed on an "AS IS" BASIS,
     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     See the License for the specific language governing permissions and
     limitations under the License.
-->
<merge xmlns:android="http://schemas.android.com/apk/res/android">

  <androidx.media3.ui.AspectRatioFrameLayout android:id="@id/exo_content_frame"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_gravity="center">

    <!-- Video surface will be inserted as the first child of the content frame. -->

    <View android:id="@id/exo_shutter"
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      android:background="@android:color/black"/>

    <ImageView android:id="@id/exo_image"
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      android:scaleType="fitXY"
      android:contentDescription="@null"/>

    <ImageView android:id="@id/exo_artwork"
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      android:scaleType="fitXY"
      android:contentDescription="@null"/>

    <androidx.media3.ui.SubtitleView android:id="@id/exo_subtitles"
      android:layout_width="match_parent"
      android:layout_height="match_parent"/>

    <ProgressBar android:id="@id/exo_buffering"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:indeterminate="true"
      android:layout_gravity="center"/>

    <TextView android:id="@id/exo_error_message"
      android:layout_width="wrap_content"
      android:layout_height="@dimen/exo_error_message_height"
      android:layout_gravity="center"
      android:layout_marginBottom="@dimen/exo_error_message_margin_bottom"
      android:gravity="center"
      android:textColor="@color/exo_white"
      android:textSize="@dimen/exo_error_message_text_size"
      android:background="@drawable/exo_rounded_rectangle"
      android:paddingLeft="@dimen/exo_error_message_text_padding_horizontal"
      android:paddingRight="@dimen/exo_error_message_text_padding_horizontal"
      android:paddingTop="@dimen/exo_error_message_text_padding_vertical"
      android:paddingBottom="@dimen/exo_error_message_text_padding_vertical"/>

  </androidx.media3.ui.AspectRatioFrameLayout>

  <FrameLayout android:id="@id/exo_ad_overlay"
    android:layout_width="match_parent"
    android:layout_height="match_parent"/>

  <FrameLayout android:id="@id/exo_overlay"
    android:layout_width="match_parent"
    android:layout_height="match_parent"/>

  <View android:id="@id/exo_controller_placeholder"
    android:layout_width="match_parent"
    android:layout_height="match_parent"/>

</merge>

設(shè)置


image.png

image.png
image.png
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容