如何在Exoplayer中暂停/恢复视频?

时间:2019-02-27 12:28:50

标签: java android exoplayer

我正在使用 Exoplayer 播放视频

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" />

我找不到任何有用的文档来暂停和恢复视频

我的要求是在触摸VideoView时触摸 pause/resume 视频怎么做?

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 个答案:

答案 0 :(得分:1)

input()