1
votes

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;
}
1
can you post your complete code here, where you are initializing exoplayerAbdul Kawee
Added @AbdulKaweeAbhishek

1 Answers

2
votes

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