问题
I am using Exoplayer for playing video
Code For Playing Video
private PlayerView videoView;
SimpleExoPlayer player;
videoView = findViewById(R.id.video_view);
player = ExoPlayerFactory.newSimpleInstance(this, new DefaultTrackSelector());
videoView.setPlayer(player);
player.prepare(buildMediaSource(Uri.parse(_videoUrl)));
player.setPlayWhenReady(true);
videoView.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
//i want to pause video
//next time i want to resume
return false;
}
});
XML CODE
<com.google.android.exoplayer2.ui.PlayerView
android:id="@+id/video_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:layout_marginEnd="8dp"
android:layout_marginBottom="8dp"
//i don't want to use controls to i am setting false
app:use_controller="false"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
I cant find any usefull docs to pause and resume video
my requirement is to pause/resume
video when touch on VideoView any one now how to do it ?
Dependency
implementation 'com.google.android.exoplayer:exoplayer:2.7.3'
implementation 'com.google.android.exoplayer:exoplayer-core:2.7.3'
implementation 'com.google.android.exoplayer:exoplayer-dash:2.7.3'
implementation 'com.google.android.exoplayer:exoplayer-ui:2.7.3'
回答1:
For Play Video
private voide playPlayer() {
if (player != null) {
player.setPlayWhenReady(true);
}
}
For Pause Video
private voide pausePlayer() {
if (player != null) {
player.setPlayWhenReady(false);
}
}
From Specific Position
private void seekTo(long positionInMS) {
if (player != null) {
player.seekTo(positionInMS);
}
}
Relase Player
private void releasePlayer() {
if (player != null) {
player.release();
}
}
来源:https://stackoverflow.com/questions/54905518/how-to-pause-resume-video-in-exoplayer