StylePlayerView 控制器 xml 覆盖播放和暂停按钮不起作用

发布于 2025-01-11 15:09:51 字数 7581 浏览 4 评论 0原文

我更新了我的项目 exoplayer 依赖项,并且我正在使用 StylePlayerView (来自 exoplayer 的自定义布局)参考更新我的代码,但是当我执行代码时,关于这 2 个按钮“播放”和“暂停”的高估不起作用,您使用 PLAY_PAUSE 并有效,但是我想自定义这个图标..所以如果有人可以帮助我,我真的很感激。 psdt.-对我的英语感到抱歉,因为我说西班牙语。

<?xml version="1.0" encoding="utf-8"?>
<com.google.android.exoplayer2.ui.AspectRatioFrameLayout 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/customized_controller"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_gravity="center_horizontal"
    android:background="@color/transparentBackground">

    <androidx.constraintlayout.widget.ConstraintLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <LinearLayout
            android:id="@+id/linearLayout"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:orientation="horizontal"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toTopOf="parent">

            <ImageButton
                android:id="@+id/exo_rew"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:contentDescription="@string/replay"
                android:layout_gravity="center"
                style="@style/ExoMediaButton.Rewind"
                android:src="@drawable/ic_replay_10" />

            <ImageButton
                android:id="@+id/exo_play_pause"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:contentDescription="@string/play"
                android:visibility="gone"
                android:layout_gravity="center"
                style="@style/ExoMediaButton.Play"
                android:src="@drawable/ic_play"/>

            <ImageButton
                android:id="@+id/exo_play"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:contentDescription="@string/play"
                android:layout_gravity="center"
                android:visibility="visible"
                style="@style/ExoMediaButton.Play"
                android:src="@drawable/ic_play"/>

            <ImageButton
                android:id="@+id/exo_pause"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:contentDescription="@string/pause"
                android:layout_gravity="center"
                android:visibility="visible"
                style="@style/ExoMediaButton.Pause"
                android:src="@drawable/ic_pause" />

            <ImageButton
                android:id="@+id/exo_ffwd"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:contentDescription="@string/fast_forward"
                android:layout_gravity="center"
                style="@style/ExoMediaButton.FastForward"
                android:src="@drawable/ic_forward_30" />

        </LinearLayout>

        <TextView
            android:id="@+id/exo_duration"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_marginEnd="8dp"
            android:layout_marginBottom="8dp"
            android:layout_weight="1"
            android:textColor="@color/whitePrimary"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintEnd_toEndOf="parent" />

        <com.google.android.exoplayer2.ui.DefaultTimeBar
            android:id="@+id/exo_progress"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            app:buffered_color="@color/grey_accent"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintEnd_toStartOf="@+id/exo_duration"
            app:layout_constraintStart_toEndOf="@+id/exo_position"
            app:played_color="@color/blueLight"
            app:unplayed_color="@color/whiteSecondary"
            tools:ignore="SpeakableTextPresentCheck" />

        <ImageView
            android:id="@+id/bt_fullscreen"
            android:layout_width="18dp"
            android:layout_height="18dp"
            android:layout_marginEnd="8dp"
            android:layout_marginBottom="8dp"
            android:contentDescription="@string/full_screen"
            android:src="@drawable/ic_fullscreen_24"
            app:layout_constraintBottom_toTopOf="@+id/exo_progress"
            app:layout_constraintEnd_toEndOf="parent" />

        <TextView
            android:id="@+id/exo_position"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginStart="8dp"
            android:layout_marginBottom="8dp"
            android:textColor="@color/whitePrimary"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintStart_toStartOf="parent" />

        <ImageView
            android:id="@+id/bt_close_player"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginTop="4dp"
            android:contentDescription="@string/close"
            android:paddingHorizontal="8dp"
            android:src="@drawable/ic_chevron_left"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toTopOf="parent" />

        <TextView
            android:id="@+id/txvChapterTitle"
            android:layout_width="0dp"
            android:layout_height="0dp"
            android:ellipsize="end"
            android:gravity="center_vertical"
            android:maxLines="1"
            android:paddingHorizontal="8dp"
            android:text="@string/title"
            android:textColor="@color/whitePrimary"
            android:textSize="14sp"
            android:textStyle="bold"
            app:layout_constraintBottom_toBottomOf="@+id/bt_close_player"
            app:layout_constraintEnd_toStartOf="@+id/lnSettings"
            app:layout_constraintStart_toEndOf="@+id/bt_close_player"
            app:layout_constraintTop_toTopOf="@+id/bt_close_player" />

        <LinearLayout
            android:id="@+id/lnSettings"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:orientation="vertical"
            android:gravity="center"
            android:padding="12dp"
            app:layout_constraintBottom_toBottomOf="@+id/bt_close_player"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintTop_toTopOf="@+id/bt_close_player">

            <ImageView
                android:id="@+id/bt_settings"
                android:layout_width="18dp"
                android:layout_height="18dp"
                android:contentDescription="@string/title_settings"
                app:srcCompat="@drawable/ic_settings_24" />
        </LinearLayout>

    </androidx.constraintlayout.widget.ConstraintLayout>

</com.google.android.exoplayer2.ui.AspectRatioFrameLayout>

I updated my project exoplayer dependency, and i was updating my code with StylePlayerView (customized layout from exoplayer) reference, but when i executed my code the overrating about this 2 buttons PLAY and PAUSE, are not working, y use PLAY_PAUSE and works, but i want to customize this icons.. so if someone can help me, i really apreace it.
psdt.- And sorry about mi english because i speak spanish.

<?xml version="1.0" encoding="utf-8"?>
<com.google.android.exoplayer2.ui.AspectRatioFrameLayout 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/customized_controller"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_gravity="center_horizontal"
    android:background="@color/transparentBackground">

    <androidx.constraintlayout.widget.ConstraintLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <LinearLayout
            android:id="@+id/linearLayout"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:orientation="horizontal"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toTopOf="parent">

            <ImageButton
                android:id="@+id/exo_rew"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:contentDescription="@string/replay"
                android:layout_gravity="center"
                style="@style/ExoMediaButton.Rewind"
                android:src="@drawable/ic_replay_10" />

            <ImageButton
                android:id="@+id/exo_play_pause"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:contentDescription="@string/play"
                android:visibility="gone"
                android:layout_gravity="center"
                style="@style/ExoMediaButton.Play"
                android:src="@drawable/ic_play"/>

            <ImageButton
                android:id="@+id/exo_play"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:contentDescription="@string/play"
                android:layout_gravity="center"
                android:visibility="visible"
                style="@style/ExoMediaButton.Play"
                android:src="@drawable/ic_play"/>

            <ImageButton
                android:id="@+id/exo_pause"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:contentDescription="@string/pause"
                android:layout_gravity="center"
                android:visibility="visible"
                style="@style/ExoMediaButton.Pause"
                android:src="@drawable/ic_pause" />

            <ImageButton
                android:id="@+id/exo_ffwd"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:contentDescription="@string/fast_forward"
                android:layout_gravity="center"
                style="@style/ExoMediaButton.FastForward"
                android:src="@drawable/ic_forward_30" />

        </LinearLayout>

        <TextView
            android:id="@+id/exo_duration"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_marginEnd="8dp"
            android:layout_marginBottom="8dp"
            android:layout_weight="1"
            android:textColor="@color/whitePrimary"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintEnd_toEndOf="parent" />

        <com.google.android.exoplayer2.ui.DefaultTimeBar
            android:id="@+id/exo_progress"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            app:buffered_color="@color/grey_accent"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintEnd_toStartOf="@+id/exo_duration"
            app:layout_constraintStart_toEndOf="@+id/exo_position"
            app:played_color="@color/blueLight"
            app:unplayed_color="@color/whiteSecondary"
            tools:ignore="SpeakableTextPresentCheck" />

        <ImageView
            android:id="@+id/bt_fullscreen"
            android:layout_width="18dp"
            android:layout_height="18dp"
            android:layout_marginEnd="8dp"
            android:layout_marginBottom="8dp"
            android:contentDescription="@string/full_screen"
            android:src="@drawable/ic_fullscreen_24"
            app:layout_constraintBottom_toTopOf="@+id/exo_progress"
            app:layout_constraintEnd_toEndOf="parent" />

        <TextView
            android:id="@+id/exo_position"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginStart="8dp"
            android:layout_marginBottom="8dp"
            android:textColor="@color/whitePrimary"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintStart_toStartOf="parent" />

        <ImageView
            android:id="@+id/bt_close_player"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginTop="4dp"
            android:contentDescription="@string/close"
            android:paddingHorizontal="8dp"
            android:src="@drawable/ic_chevron_left"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toTopOf="parent" />

        <TextView
            android:id="@+id/txvChapterTitle"
            android:layout_width="0dp"
            android:layout_height="0dp"
            android:ellipsize="end"
            android:gravity="center_vertical"
            android:maxLines="1"
            android:paddingHorizontal="8dp"
            android:text="@string/title"
            android:textColor="@color/whitePrimary"
            android:textSize="14sp"
            android:textStyle="bold"
            app:layout_constraintBottom_toBottomOf="@+id/bt_close_player"
            app:layout_constraintEnd_toStartOf="@+id/lnSettings"
            app:layout_constraintStart_toEndOf="@+id/bt_close_player"
            app:layout_constraintTop_toTopOf="@+id/bt_close_player" />

        <LinearLayout
            android:id="@+id/lnSettings"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:orientation="vertical"
            android:gravity="center"
            android:padding="12dp"
            app:layout_constraintBottom_toBottomOf="@+id/bt_close_player"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintTop_toTopOf="@+id/bt_close_player">

            <ImageView
                android:id="@+id/bt_settings"
                android:layout_width="18dp"
                android:layout_height="18dp"
                android:contentDescription="@string/title_settings"
                app:srcCompat="@drawable/ic_settings_24" />
        </LinearLayout>

    </androidx.constraintlayout.widget.ConstraintLayout>

</com.google.android.exoplayer2.ui.AspectRatioFrameLayout>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

电影里的梦 2025-01-18 15:09:51

我通过覆盖样式和可绘制对象解决了这个问题。我在我的值文件上创建了一个新样式,如下所示:

<style name="ExoStyledControls.Button.Center.PlayPause">
    <item name="android:src">@drawable/exo_styled_controls_pause</item>
    <item name="android:contentDescription">@string/exo_controls_play_description</item>
    <item name="android:padding">@dimen/exo_icon_padding</item>
</style>
<drawable name="exo_styled_controls_pause">@drawable/exo_styled_control_pause</drawable>
<drawable name="exo_styled_controls_play">@drawable/exo_styled_control_play</drawable>

可绘制对象 exo_styled_control_play 和 exo_styled_control_pause 应包含您自己的可绘制代码。

如果缓存不能立即工作,请不要忘记使缓存失效并重新启动。

I solved this issue for me by overriding the style and drawables. I created a new style on my values file like below:

<style name="ExoStyledControls.Button.Center.PlayPause">
    <item name="android:src">@drawable/exo_styled_controls_pause</item>
    <item name="android:contentDescription">@string/exo_controls_play_description</item>
    <item name="android:padding">@dimen/exo_icon_padding</item>
</style>
<drawable name="exo_styled_controls_pause">@drawable/exo_styled_control_pause</drawable>
<drawable name="exo_styled_controls_play">@drawable/exo_styled_control_play</drawable>

The drawables exo_styled_control_play and exo_styled_control_pause should contain your own drawable code.

Do not forget to invalidate cache and restart if it doesn't work right away.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文