Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save rahulgautam/4c4f9e4eb2824501c5c7 to your computer and use it in GitHub Desktop.

Select an option

Save rahulgautam/4c4f9e4eb2824501c5c7 to your computer and use it in GitHub Desktop.
import android.graphics.Bitmap;
import android.media.MediaMetadataRetriever;
import com.squareup.picasso.Picasso;
import com.squareup.picasso.Request;
import com.squareup.picasso.RequestHandler;
import java.io.IOException;
/**
* Loads frames from a video at the specified microsecond. Usage:
* Picasso picasso = new Picasso.Builder(this).addRequestHandler(new VideoFrameRequestHandler()).build();
* picasso.load("videoframe://path/to/video#microseconds
* The offset is in microseconds, so #1000000 = 1 second in.
*/
public class PicassoVideoFrameRequestHandler extends RequestHandler {
public static final String SCHEME = "videoframe";
@Override public boolean canHandleRequest(Request data) {
return SCHEME.equals(data.uri.getScheme());
}
@Override public Result load(Request data) throws IOException {
MediaMetadataRetriever mediaMetadataRetriever = new MediaMetadataRetriever();
mediaMetadataRetriever.setDataSource(data.uri.getPath());
String offsetString = data.uri.getFragment();
long offset = Long.parseLong(offsetString);
Bitmap bitmap = mediaMetadataRetriever.getFrameAtTime(offset);
return new Result(bitmap, Picasso.LoadedFrom.DISK);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment