Abhishek
Abhishek

Reputation: 25

How to auto start the video using exoplayer?

I am using exo-player as a video player for my application. I am unable to start the videos automatically as it is opened in the gallery mode. I need to click on play button to play the video.

How do I make it autoplay instead of click and play?

I used the below 2 solutions which did not give the required results,

exoPlayer.setPlayWhenReady(true);
exoPlayer.getPlayWhenReady(); 

edit -

public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX, float distanceY) {
    Log.e("Scroll",String.valueOf(distanceY)+" - "+String.valueOf(distanceX));
    if(distanceY>-40&&distanceY<-20&&distanceX<10){
        ImageCorouselViewActivity.this.finish();

        try {
            int position = vpImageCorousel.getCurrentItem();

            if(listImagesViewPagers.get(position).isVideo()) {
                //exoPlayer.setPlayWhenReady(false);
                exoPlayer.setPlayWhenReady(true);
                exoPlayer.getPlaybackState();
            }
        }
        catch (Exception e) {
            e.printStackTrace();
        }

        super.onBackPressed();
        ImageCorouselViewActivity.this.overridePendingTransition(R.anim.stay,R.anim.slide_down);

        return true;
    }
    return false;
}

Upvotes: 2

Views: 3028

Answers (1)

Abdul Kawee
Abdul Kawee

Reputation: 2727

You need to add prepare() on exoplayer

if(listImagesViewPagers.get(position).isVideo()) {
            //exoPlayer.setPlayWhenReady(false);
            exoPlayer.setPlayWhenReady(true);
            exoPlayer.getPlaybackState();
            // Prepare the player with the source.
            mPlayer.prepare(mVideoSource);
        }

Hope this helps

Upvotes: 4

Related Questions