Как приостановить / возобновить видео в Exoplayer?

1

Я использую 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" />

Я не могу найти какие-либо полезные документы, чтобы приостановить и возобновить видео

мое требование состоит в том, чтобы pause/resume видео при прикосновении к VideoView любой сейчас, как это сделать?

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'
Теги:
exoplayer

1 ответ

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(); } 
    }
  • 0
    где код или логика для приостановки видео? я не могу найти в предоставленном коде ... вы можете объяснить больше?
  • 1
    private voide playPlayer () {if (player! = null) {player.setPlayWhenReady (true); }} private voide pausePlayer () {if (player! = null) {player.setPlayWhenReady (false); }} private void seekTo (long positionInMS) {if (player! = null) {player.seekTo (positionInMS); }} private void releasePlayer () {if (player! = null) {player.release (); }}

Ещё вопросы

Сообщество Overcoder
Наверх
Меню