我使用 Mediarecorder 捕获了一个视频,将其插入到 mediastore,然后在下一个屏幕中更新了该视频的内容值。 但是它改变了列表中所有视频的描述,我只想改变当前录制的视频。 下面是一些代码:
ContentValues values = new ContentValues(1);
//long current = System.currentTimeMillis();
//values.put(MediaStore.Video.Media.DATE_ADDED, (int) (current / 1000));
//values.put(MediaStore.Video.Media.MIME_TYPE, "video/mp4");
values.put(MediaStore.Video.Media.DESCRIPTION, edtext.getText().toString());
//values.put(MediaStore.Video.Media.DATA, videoFile.getAbsolutePath());
ContentResolver contentResolver = getContentResolver();
Uri base = MediaStore.Video.Media.EXTERNAL_CONTENT_URI;
contentResolver.update(base, values,null,null);
sendBroadcast(new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE, base));
我在 ListView 中使用它:
cursor = managedQuery(MediaStore.Video.Media.EXTERNAL_CONTENT_URI,
mediaColumns, null, null, null);
ArrayList<VideoViewInfo> videoRows = new ArrayList<VideoViewInfo>();
if (cursor.moveToFirst()) {
do {
VideoViewInfo newVVI = new VideoViewInfo();
int id = cursor.getInt(cursor
.getColumnIndex(MediaStore.Video.Media._ID));
Cursor thumbCursor = managedQuery(
MediaStore.Video.Thumbnails.EXTERNAL_CONTENT_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(QUEUE_LOG, "Thumb " + newVVI.thumbPath);
}
newVVI.filePath = cursor.getString(cursor
.getColumnIndexOrThrow(MediaStore.Video.Media.DATA));
newVVI.caption = cursor
.getString(cursor
.getColumnIndexOrThrow(MediaStore.Video.Media.DESCRIPTION));
我该如何解决这个问题以及如何将其设为我的应用程序的私有(private)文件夹?
最佳答案
在哪里做:
contentResolver.update(base, values,null,null);
您基本上是在要求它更改所有内容(并且系统完全按照您的要求进行操作)。您需要做的是像您已经在做的那样使用媒体扫描仪添加文件,然后查询文件(我认为您可以只使用 DATE_ADDED 列并搜索在您发送之前添加的任何视频 Intent ),然后在 update
调用中使用从查询中获得的 URI(而不是 base
)。
如果可行,请告诉我。
关于android - 更新特定视频的媒体存储内容值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6392105/