Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support retrieval of specific frames from MediaStore videos #657

Closed
wants to merge 1 commit into from
Closed

Support retrieval of specific frames from MediaStore videos #657

wants to merge 1 commit into from

Conversation

jacobtabak
Copy link
Contributor

Motivation

Picasso supports loading of MediaStore video thumbnails, however the thumbnail generated by Android is pulled from the middle of the video. For this project, we needed to load the first frame of a video that automatically starts when the user scrolls to the center of the screen, to avoid this (youtube). The end result turned out quite nicely, you can see a demonstration here (youtube):

API

Uri uri = myVideoUri.buildUpon().appendQueryParameter("t", "0").build();
Picasso.with(context).load(uri).into(imageview)

This is still up in the air. I had originally suggested load(Uri uri, long offset), but it almost certainly doesn't make sense to add a new method signature for such an obscure feature. So I settled on the current implementation, which follows YouTube's convention of appending ?t=[position] to the end of a uri, for example: https://www.youtube.com/watch?v=wtLJPvx7-ys#t=3945

YouTube's time query parameter is in seconds, but since the underlying API that this change uses (android.media.MediaMetadataRetriever) accepts the time position in microseconds, my initial implementation does as well, but that's definitely not set in stone.

Tests

In this PR, I upgraded Robolectric from 2.2 to 2.3. 2.2 did not have a shadow MediaMetadataRetriever implementation. However, the implementation in 2.3 was incomplete so I ended up writing my own shadow MediaMetadataRetriever (which I will be submitting as a PR to them). All the tests still pass, but this PR doesn't require Robolectric 2.3 to so we can revert to 2.2 if necessary.

Travis was failing with Robolectric 2.3 so I reverted to 2.2.

@jacobtabak
Copy link
Contributor Author

Sample app available here

@jacobtabak
Copy link
Contributor Author

Closing this, it's better off as a request handler. Gist here: https://gist.github.com/jacobtabak/3d0562501df7c61f7b9a

@jacobtabak jacobtabak closed this Sep 23, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant