Is there a way to hook into the Play/Pause click events of the SimpleExoPlayerView controls? I'm trying to hookup chromecast to my play activity and i need to be able to respond to play events to determine if exoplayer should play the content or it should be sent to chromecast.
I thought onPlayerStateChanged might help with this but i can't see a ExoPlayer.STATE_PLAYING state.
答案 0 :(得分:1)
试试这个解决方案:
SimpleExoPlayerView simpleExoPlayerView = (SimpleExoPlayerView)findViewById(R.id.simpleExoView);
simpleExoPlayerView.setControlDispatcher(new PlaybackControlView.ControlDispatcher() {
@Override
public boolean dispatchSetPlayWhenReady(ExoPlayer exoPlayer, boolean b) {
// implement what you need
return b;
}
@Override
public boolean dispatchSeekTo(ExoPlayer exoPlayer, int i, long l) {
return false;
}
});
答案 1 :(得分:0)
以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>
在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);