gpt4 book ai didi

android - 获取视频缩略图时 getContentResolver().query 问题

转载 作者:行者123 更新时间:2023-11-30 00:23:58 24 4
gpt4 key购买 nike

情况:我正要使用 managequery 代码,但后来它被弃用了,所以我决定使用 getContentResolver().query

但我总是在这一行中收到错误:

Cursor thumbCursor = getContentResolver().query(uri, thumbColumns, MediaStore.Video.Thumbnails.VIDEO_ID + "=" + id, null, null);

08-18 04:17:49.373 20629-20629/com.chill.leoj.burp E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.chill.leoj.burp, PID: 20629
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.chill.leoj.burp/com.chill.leoj.burp.Videos}: android.database.sqlite.SQLiteException: no such column: video_id (code 1): , while compiling: SELECT _data, video_id FROM files WHERE (video_id=347888)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2348)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2410)
at android.app.ActivityThread.access$800(ActivityThread.java:151)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1313)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5345)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:947)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:742)
at de.robv.android.xposed.XposedBridge.main(XposedBridge.java:102)
Caused by: android.database.sqlite.SQLiteException: no such column: video_id (code 1): , while compiling: SELECT _data, video_id FROM files WHERE (video_id=347888)
at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:224)
at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:180)
at android.content.ContentProviderProxy.query(ContentProviderNative.java:447)
at android.content.ContentResolver.query(ContentResolver.java:478)
at android.content.ContentResolver.query(ContentResolver.java:422)
at com.chill.leoj.burp.Videos.onCreate(Videos.java:150)
at android.app.Activity.performCreate(Activity.java:6012)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1106)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2292)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2410) 
at android.app.ActivityThread.access$800(ActivityThread.java:151) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1313) 
at android.os.Handler.dispatchMessage(Handler.java:102) 
at android.os.Looper.loop(Looper.java:135) 
at android.app.ActivityThread.main(ActivityThread.java:5345) 
at java.lang.reflect.Method.invoke(Native Method) 
at java.lang.reflect.Method.invoke(Method.java:372) 
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:947) 
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:742) 
at de.robv.android.xposed.XposedBridge.main(XposedBridge.java:102) 

这就是我在我的应用程序中使用它的方式:

 Uri uri = MediaStore.Files.getContentUri("external");

String[] thumbColumns = { MediaStore.Video.Thumbnails.DATA,
MediaStore.Video.Thumbnails.VIDEO_ID };

String[] mediaColumns = { MediaStore.Video.Media._ID,
MediaStore.Video.Media.DATA, MediaStore.Video.Media.TITLE,
MediaStore.Video.Media.MIME_TYPE };

Cursor cursor = getContentResolver().query(uri,
mediaColumns, null, null, null);



if (cursor.moveToFirst()) {
do {

VideoViewInfo newVVI = new VideoViewInfo();
int id = cursor.getInt(cursor.getColumnIndex(MediaStore.Video.Media._ID));

Cursor thumbCursor = getContentResolver().query(uri, thumbColumns, MediaStore.Video.Thumbnails.VIDEO_ID
+ "=" + id, null, null);
if (thumbCursor.moveToFirst()) {
newVVI.thumbPath = thumbCursor.getString(thumbCursor.getColumnIndex(MediaStore.Video.Thumbnails.DATA));
Log.v("", newVVI.thumbPath);
}

newVVI.filePath = cursor.getString(cursor.getColumnIndexOrThrow(MediaStore.Video.Media.DATA));
newVVI.title = cursor.getString(cursor.getColumnIndexOrThrow(MediaStore.Video.Media.TITLE));
newVVI.mimeType = cursor.getString(cursor.getColumnIndexOrThrow(MediaStore.Video.Media.MIME_TYPE));
videoRows.add(newVVI);
} while (cursor.moveToNext());


cursor.close();
videoAdapter = new VideoGalleryAdapter(Videos.this, videoRows);

}

有人可以指出我做错了什么,如果可能的话如何解决这个问题。非常感谢您。

最佳答案

不是在内容 Uri 中搜索视频以查找一般文件 (MediaStore.Files.getContentUri("external")),您应该在内容 Uri 中搜索视频 Uri uri = MediaStore.Video。 Media.EXTERNAL_CONTENT_URI;,这会起作用。

关于android - 获取视频缩略图时 getContentResolver().query 问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45744168/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com