Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I send exoplayer buffered data to other activity exoplayer

I have a exoplayer my first activity and when I click full screen button, I open a new VideoActivity full screen. I just only send my current position and start VideoActivity that position.

  TrackSelector trackSelector = new DefaultTrackSelector(videoTrackSelectionFactory);
  SimpleExoPlayer player = ExoPlayerFactory.newSimpleInstance(context, trackSelector);

  playerView.setPlayer(player);
  player.prepare(contentMediaSource);
  player.setPlayWhenReady(true);
  player.seekTo(positionFromFirstActivity);

But the problem is when open new activity and start exoplayer from current position. Exoplayer start the buffering once again.

Is there any way to carry the buffering data to SecondActivity.

like image 658
6155031 Avatar asked Sep 27 '18 14:09

6155031


1 Answers

This might be too late to answer this, but this might help other people.

If you wanna implement the fullscreen functionality for the exoplayer, don't do it through a separate activity, you just need to open a dialog with hieght and width mathcing the entire screen and just need to add the playerview that you were using for the 'none-fullscreen' exoplyer.

mFullScreenButton.setOnClickListener(v -> {
        if (!mExoPlayerFullscreen) {
            ((Activity) mContext).setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE);
            openFullscreenDialog();
        } else {
            ((Activity) mContext).setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT);
            closeFullscreenDialog();
        }
    });

here we're initializing the onClick for the fullscreen button

private void openFullscreenDialog() {
    ((ViewGroup) playerView.getParent()).removeView(playerView);
    mFullScreenDialog.addContentView(playerView, new ViewGroup.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT));
    mFullScreenIcon.setImageResource(R.drawable.ic_exit_fullscreen);
    mExoPlayerFullscreen = true;
    mFullScreenDialog.show();
}

above is the method which is called when the fullscreen button is called for matching the screen. And below is the method for undoing the fullscreen.

private void closeFullscreenDialog() {
    ((ViewGroup) playerView.getParent()).removeView(playerView);
    ((FrameLayout) findViewById(R.id.main_media_frame)).addView(playerView);
    mExoPlayerFullscreen = false;
    mFullScreenDialog.dismiss();
    mFullScreenIcon.setImageResource(R.drawable.ic_fullscreen);
}

Below is the code snippet for initializing the dialog.

mFullScreenDialog = new Dialog(mContext, android.R.style.Theme_Black_NoTitleBar_Fullscreen) {
        public void onBackPressed() {
            if (mExoPlayerFullscreen) {
                closeFullscreenDialog();
            }
            super.onBackPressed();
        }
    };
like image 185
Abhishek Kumar Avatar answered Oct 16 '22 21:10

Abhishek Kumar