Support retrieval of specific frames from MediaStore videos #657
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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
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.