Issue
I am trying on Android 11 to display a thumbnail for a video. I have successfully queried the MediaStore and obtained the URIs for pics and videos in the device's gallery. I can display the pics OK, but when I attempt to access the videos to make a thumbnail, I get this error:
java.lang.IllegalArgumentException: could not access content://media/external/images/media/355 at android.media.MediaMetadataRetriever.setDataSource(MediaMetadataRetriever.java:342)
Here is my code:
val mmr = MediaMetadataRetriever()
mmr.setDataSource(context, uri)
val bitmap = mmr.getFrameAtTime(1000, MediaMetadataRetriever.OPTION_CLOSEST_SYNC);
GlideApp.with(context)
.load(bitmap)
.centerCrop()
.into(view)
Any pointers would be appreciated.
Thanks.
Solution
It turned out to be a dumb error. My projection was still using most of the fields from the Image projection:
val videoProjection = arrayOf(
MediaStore.Images.Media._ID,
MediaStore.Images.Media.DATE_ADDED,
MediaStore.Images.Media.ORIENTATION,
MediaStore.Video.VideoColumns.DURATION,
MediaStore.Images.Media.SIZE,
)
...whereas it should have been like so:
val videoProjection = arrayOf(
MediaStore.Video.Media._ID,
MediaStore.Video.Media.DATE_ADDED,
MediaStore.Video.Media.ORIENTATION,
MediaStore.Video.VideoColumns.DURATION,
MediaStore.Video.Media.SIZE,
)
So now the URL is now "content://media/external/videos/media/355", and is readily accessible.
Answered By - Casey Perkins
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.