gpt4 book ai didi

Android Exoplayer SimpleExoPlayerView 播放/暂停事件

转载 作者:行者123 更新时间:2023-11-29 01:08:41 25 4
gpt4 key购买 nike

有没有办法挂接到 SimpleExoPlayerView 控件的播放/暂停点击事件?我正在尝试将 chromecast 连接到我的播放 Activity ,我需要能够响应播放事件以确定 exoplayer 应该播放内容还是应该将其发送到 chromecast。

我认为 onPlayerStateChanged 可能对此有所帮助,但我看不到 ExoPlayer.STATE_PLAYING 状态。

最佳答案

in XML

           <androidx.constraintlayout.widget.ConstraintLayout
android:id="@+id/mainlayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/bgFrag">

<com.google.android.exoplayer2.ui.PlayerView
android:id="@+id/playerview"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:visibility="visible"
app:use_controller="true"
app:controller_layout_id="@layout/item_player_controler"
app:keep_content_on_player_reset="true"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:resize_mode="zoom"
app:shutter_background_color="@color/transperent">


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


<ImageView
android:id="@+id/ivExoPlayPause"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="centerInside"
android:visibility="invisible"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:srcCompat="@drawable/ic_play" />
</<androidx.constraintlayout.widget.ConstraintLayout>

item_player_controler.xml

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:visibility="visible"
android:layout_height="match_parent">

<ImageView android:id="@id/exo_play"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center"
android:button="@null"
android:scaleType="centerInside"
/>

<ImageView android:id="@id/exo_pause"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center"
android:visibility="visible"
android:button="@null"
android:scaleType="centerInside"
/>

</FrameLayout>

in Java

videoviewholder.playerview.findViewById(R.id.exo_play).setOnClickListener(view->{
ToastUtils.showShort("play");
videoviewholder.videoItemBinding.ivExoPlayPause.setVisibility(View.INVISIBLE);
videoviewholder.videoItemBinding.playerview.getPlayer().setPlayWhenReady(true);

});

videoviewholder.playerview.findViewById(R.id.exo_pause).setOnClickListener(view->{
ToastUtils.showShort("pause");
videoviewholder.videoItemBinding.ivExoPlayPause.setVisibility(View.VISIBLE);
videoviewholder.videoItemBinding.playerview.getPlayer().setPlayWhenReady(false);

});

videoviewholder.playerview.setControllerAutoShow(true);
videoviewholder.playerview.setControllerShowTimeoutMs(0);
videoviewholder.playerview.setControllerHideOnTouch(false);
videoviewholder.playerview.setPlayer(player);

关于Android Exoplayer SimpleExoPlayerView 播放/暂停事件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45051930/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com