0

I am trying to convert a videoview into bitmap. Here's the code I have tried.But here the bitmap is always null. Can anyone please tell me why and what is the correct way to do so.

        public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    mainLayout = (RelativeLayout) findViewById(R.id.activity_main);

    videoView = new CustomVideoView(this);

    MediaController mediaController = new MediaController(getApplicationContext());
    mediaController.setAnchorView(videoView);
    videoView.setMediaController(mediaController);

    video_relativeLayout = new RelativeLayout(this);
    RelativeLayout.LayoutParams videoRelativeLayout_param = new RelativeLayout.LayoutParams(
            RelativeLayout.LayoutParams.MATCH_PARENT,
            RelativeLayout.LayoutParams.MATCH_PARENT);
    video_relativeLayout.setLayoutParams(videoRelativeLayout_param);

    videoView.requestFocus();
    video_relativeLayout.addView(videoView);


    videoView.setVideoURI(Uri.parse("android.resource://" + getApplicationContext().getPackageName() + "/" + R.raw.kitkat));

    videoView.requestFocus();
    videoView.start();

mainLayout.addView(video_relativeLayout);

    mainLayout.setDrawingCacheEnabled(true);
    mainLayout.buildDrawingCache();
    Bitmap bm = mainLayout.getDrawingCache();

}
apurv
  • 11
  • 6

1 Answers1

0

Consider using a TextureView instead of VideoView since it has getBitmap() method.

More information here (android get screenshot of current videoview).

Community
  • 1
  • 1
arkus
  • 405
  • 3
  • 11