Reputation: 107
I have created listview for video thumbnail display, My code is as below
Bitmap bitmap = null;
MediaMetadataRetriever mediaMetadataRetriever = null;
try
{
mediaMetadataRetriever = new MediaMetadataRetriever();
if (Build.VERSION.SDK_INT >= 14)
mediaMetadataRetriever.setDataSource(url+"/videos/" + list.get(position).getSelectedPath(), new HashMap<String, String>());
else
mediaMetadataRetriever.setDataSource(url+"/videos/" + list.get(position).getSelectedPath());
// mediaMetadataRetriever.setDataSource(videoPath);
bitmap = mediaMetadataRetriever.getFrameAtTime(11);
} catch (Exception e) {
e.printStackTrace();
} finally {
if (mediaMetadataRetriever != null) {
mediaMetadataRetriever.release();
}
}
imageView.setImageBitmap(bitmap);
It works fine but take more time for just loading, Is their any other way for fast loading.Please suggest. Thanks in advance.
Upvotes: 0
Views: 665
Reputation: 25511
Assuming this is for a solution where the videos are hosted on a server and streamed from there, the client side, the Android device in this case, has to do quite a bit of work here as it has to read and decode each video to allow it then retrieve a thumbnail to display.
No matter how efficiently you do this, it is always going to involve processing and delay. Additionally, it won't work at all for any of your videos which are DRM protected or encrypted.
The way many video services get over this is to do the thumbnail generation on the server side, and provide a link to the thumbnail and to the video.
Only the thumbnails are downloaded initially and if a user clicks on a particular thumbnail, or its associated play button, then the video is streamed at that point.
This has the disadvantage of requiring more server side work up front, but the advantage of reducing the work and the data transfer to the client devices.
Upvotes: 1