3

What is the simple way to create video thumbnail or snapshot or frame capture from url? I am using videoview and it has black screen before start.
My code is:

String vidAddress = URL_trailers_mp4;
Uri vidUri = Uri.parse(vidAddress);
VideoView vidView=(VideoView)findViewById(R.id.myVideo);
vidView.setVideoURI(vidUri);
MediaController vidControl = new MediaController(this);
vidControl.setAnchorView(vidView);
vidView.setMediaController(vidControl);
vidView.seekTo(0);

And it does not work.

Iraklii
  • 1,295
  • 13
  • 30

5 Answers5

0

Maybe just simple

videoview.seekto(0);

will help. It should set first key frame of the video as videoview preview

Karol Żygłowicz
  • 2,442
  • 2
  • 26
  • 35
0

I found some rough decision: seekto, start and pause got me image on video.

0

You can try this way:

FileOutputStream out;
File land=new File(URL);// image file use to create image u can give any path.
Bitmap bitmap=ThumbnailUtils.createVideoThumbnail(filePath, MediaStore.Video.Thumbnails.FULL_SCREEN_KIND);//filePath is your video file path.
ByteArrayOutputStream stream = new ByteArrayOutputStream();
bitmap.compress(Bitmap.CompressFormat.JPEG, 100, stream);
byte[] byteArray = stream.toByteArray();

out=new  FileOutputStream(land.getPath());
out.write(byteArray);
out.close();
Maveňツ
  • 1
  • 12
  • 50
  • 89
0

Change vidView.seekTo(0); to vidView.seekTo(100); //100 milliseconds (0.1 s) clip of video

And you may create a thumbnail with the following code:

                ImageView imageThumbnail = new ImageView(Video.this);
                Bitmap bmThumbnail;
                bmThumbnail = ThumbnailUtils.createVideoThumbnail(videoSource, MediaStore.Video.Thumbnails.MINI_KIND);
                imageThumbnail.setImageBitmap(bmThumbnail);
Prabs
  • 4,923
  • 6
  • 38
  • 59
0

You can use MediaMetadataRetriever. example:

MediaMetadataRetriever retriever = new MediaMetadataRetriever();
retriever.setDataSource(context, vidUri);
Bitmap bitmap = retriever.getFrameAtTime(expectPosition);

However,there is no guarentee that the data source has a frame located at the position. When this happens, a frame nearby will be returned.

chiemy
  • 11
  • 2