【问题标题】:android get video thumbnail PATH, not Bitmapandroid获取视频缩略图PATH,而不是位图
【发布时间】:2013-01-07 03:59:46
【问题描述】:

是否可以获得视频缩略图路径,而不是位图对象本身?我知道方法

MediaStore.Images.Thumbnails.queryMiniThumbnail

但由于我使用自己的位图缓存机制,因此我希望获得视频缩略图的路径,而不是位图对象本身。此方法返回位图对象,而不是路径。 谢谢

【问题讨论】:

    标签: java android eclipse thumbnails


    【解决方案1】:

    首先获取视频文件的 URL,然后使用下面的查询。

    示例代码:

    private static final String[] VIDEOTHUMBNAIL_TABLE = new String[] {
        Video.Media._ID, // 0
        Video.Media.DATA, // 1 from android.provider.MediaStore.Video
        };
    
    Uri videoUri = MediaStore.Video.Thumbnails.getContentUri("external");
    
    cursor c = cr.query(videoUri, VIDEOTHUMBNAIL_TABLE, where, 
               new String[] {filepath}, null);
    
    if ((c != null) && c.moveToFirst()) {
      VideoThumbnailPath = c.getString(1);
    }
    

    VideoThumbnailPath,应该有视频缩略图路径。希望对你有帮助。

    【讨论】:

    • “where”参数的值是多少(调用 c.query 时的第三个参数)?
    • Where String: Video.Thumbnails.VIDEO_ID + " In (select _id from video where _data =?)";
    • 像魅力一样工作!谢谢!
    • 这太令人困惑了,它对我不起作用,谁能提供更好的解决方案?
    • 它不起作用,是 cr : ContentResolver crThumb = App.getContext().getContentResolver(); , 光标为:光标 c = crThumb.query(videoUri, VIDEO_THUMBNAIL_TABLE, "_data =?", new String[] { videoPath }, null); ??????
    【解决方案2】:

    从video_id获取视频缩略图路径:

    public static String getVideoThumbnail(Context context, int videoID) {
            try {
                String[] projection = {
                        MediaStore.Video.Thumbnails.DATA,
                };
                ContentResolver cr = context.getContentResolver();
                Cursor cursor = cr.query(
                        MediaStore.Video.Thumbnails.EXTERNAL_CONTENT_URI,
                        projection, 
                        MediaStore.Video.Thumbnails.VIDEO_ID + "=?", 
                        new String[] { String.valueOf(videoID) }, 
                        null);
                cursor.moveToFirst();
                return cursor.getString(0);
            } catch (Exception e) {
            }
            return null;
        }
    

    【讨论】:

      猜你喜欢
      • 2015-03-10
      • 2014-04-14
      • 1970-01-01
      • 2012-02-23
      • 1970-01-01
      • 2013-08-31
      • 2017-10-21
      • 2011-05-12
      • 2011-06-18
      相关资源
      最近更新 更多