Forked from jacobtabak/PicassoVideoFrameRequestHandler.java
Last active
August 29, 2015 14:12
-
-
Save rahulgautam/4c4f9e4eb2824501c5c7 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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