get Video Frame and return a Bitmap - Android android.media

Android examples for android.media:Video

Description

get Video Frame and return a Bitmap

Demo Code

import android.graphics.Bitmap;
import android.media.MediaMetadataRetriever;
import android.util.Log;

public class Main {

  public static Bitmap getVideoFrame(String videoPath, long frameTime) {
    MediaMetadataRetriever retriever = new MediaMetadataRetriever();
    try {/*from  w  w  w .ja  va  2 s.c  o m*/
      retriever.setDataSource(videoPath);
      return retriever.getFrameAtTime(frameTime, MediaMetadataRetriever.OPTION_CLOSEST);
    } catch (IllegalArgumentException ex) {
      Log.e("MediaUtils", "error getting video frame", ex);

    } catch (RuntimeException ex) {
      Log.e("MediaUtils", "error getting video frame", ex);
    } finally {
      try {
        retriever.release();
      } catch (RuntimeException ex) {
      }
    }
    return null;
  }

}

Related Tutorials