通过提供视频路径获取视频缩略图的路径

时间:2014-12-28 23:34:48

标签: java android picasso

我试图从Android Media数据库获取存储在手机内部存储中的视频的拇指路径,因此我可以在picasso库中使用该拇指路径。

有人对此有任何好结果吗?

或者如果有人知道如何用picasso从视频中提取拇指,但我认为从db获取它会更快。

非常感谢!

2 个答案:

答案 0 :(得分:2)

doc

查看createVideoThumbnail()

答案 1 :(得分:0)

我解决了。 我想做的就是拥有一个快速的列表视图,并且不要创建一个视频拇指,而是使用已经创建的一个,所以我的列表是smoth

Android为他的数据库添加了一个拇指,用于存储的视频。

它们是小尺寸的(MediaStore.Video.Thumbnails.MICRO_KIND),但它们可以毫无问题地调整大小。

我使用代码获取了视频ID:

String[] columns = {
    MediaStore.Video.Media._ID,
    MediaStore.Video.Media.TITLE,
    MediaStore.Video.Media.DATA,
    MediaStore.Video.Media.ARTIST,
    MediaStore.Video.Media.MIME_TYPE,
    MediaStore.Video.Media.SIZE,
    MediaStore.Video.Media.DURATION,
    MediaStore.Images.Media.HEIGHT,
    MediaStore.Images.Media.WIDTH,
};

Cursor cursor = ctx.getContentResolver().query(uri, columns, where, whereVal, orderBy);
if (cursor.moveToFirst())
{
    do
    {
       // cursor.getInt(cursor.getColumnIndex(MediaStore.Video.Media._ID)) is a video id
      //save curent video id in singleton class for example
         Singleton.addVideoID(cursor.getInt(cursor.getColumnIndex(MediaStore.Video.Media._ID)));

    } while (cursor.moveToNext());
}
cursor.close();

后者在

public View getView(int position, View convertView, ViewGroup parent)
ListView适配器的

将从singleton中检索视频ID,并显示与此视频ID相关联的拇指,如下所示:

                int videoID = Singleton.getVideoID( position  );

                Bitmap bitmap = MediaStore.Video.Thumbnails.getThumbnail(
                        getActivity().getContentResolver(),
                        videoID,
                        MediaStore.Video.Thumbnails.MICRO_KIND,
                        null );


                icon.setImageBitmap(Bitmap.createScaledBitmap(bitmap, 120, 120, false));

图标是必须在拇指上显示的ImageView,并且我将其缩放到120x120以使其更大。您必须在适配器布局的xml中定义“图标”我的是这样的

<ImageView
    android:id="@+id/icon"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:adjustViewBounds="true"
    android:maxHeight="120dp" 
    android:layout_centerHorizontal="true"
    android:contentDescription=""
    android:textColor="#000000"
     />

并且listview是scoth scrooling因为它不会在getview中创建拇指,它只是获取已经创建的一个并且一切都很快。如果你想改变它,你也可以控制大小。 我希望这有帮助ppls谁想要在网格和列表中显示拇指并运行smoth和快速。