Example usage for android.media MediaMetadataRetriever OPTION_CLOSEST

List of usage examples for android.media MediaMetadataRetriever OPTION_CLOSEST

Introduction

In this page you can find the example usage for android.media MediaMetadataRetriever OPTION_CLOSEST.

Prototype

int OPTION_CLOSEST

To view the source code for android.media MediaMetadataRetriever OPTION_CLOSEST.

Click Source Link

Document

This option is used with #getFrameAtTime(long,int) to retrieve a frame (not necessarily a key frame) associated with a data source that is located closest to or at the given time.

Usage

From source file:Main.java

public static Bitmap getVideoFrame(String videoPath, long frameTime) {
    MediaMetadataRetriever retriever = new MediaMetadataRetriever();

    try {//  w  w w . ja  v a 2s .  c o  m
        retriever.setDataSource(videoPath);
        return retriever.getFrameAtTime(frameTime, MediaMetadataRetriever.OPTION_CLOSEST);
    } catch (IllegalArgumentException ex) {
        Log.w("FFMPEG.MediaUtils", "illegal argument exception");

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