如何在Exoplayer中暂停/恢复视频? [英] How to pause/resume video in Exoplayer?
本文介绍了如何在Exoplayer中暂停/恢复视频?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用 Exoplayer 播放视频
I am using Exoplayer for playing video
Code 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
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
我的要求是在触摸VideoView时触摸 pause/resume
视频,现在该怎么做?
my requirement is to pause/resume
video when touch on VideoView any one now how to do it ?
Dependency
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'
推荐答案
For Play Video
For Play Video
private voide playPlayer() {
if (player != null) {
player.setPlayWhenReady(true);
}
}
For Pause Video
For Pause Video
private voide pausePlayer() {
if (player != null) {
player.setPlayWhenReady(false);
}
}
From Specific Position
From Specific Position
private void seekTo(long positionInMS) {
if (player != null) {
player.seekTo(positionInMS);
}
}
Relase Player
Relase Player
private void releasePlayer() {
if (player != null) {
player.release();
}
}
这篇关于如何在Exoplayer中暂停/恢复视频?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文