我正在尝试检索有关存储在 sdcard 中的用户视频的信息,我有这个方法:
protected void addVideo () {
cursor = cr.query(MediaStore.Video.Media.EXTERNAL_CONTENT_URI,
mediaColumns, null, null, null);
if (cursor.moveToFirst()) {
int i = 1;
do {
VideoItem newVVI = new VideoItem();
int id = cursor.getInt(cursor
.getColumnIndex(MediaStore.Video.Media._ID));
newVVI.idthumb = cursor.getString(cursor
.getColumnIndex(MediaStore.Video.Thumbnails._ID));
Cursor thumbCursor = cr.query(
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));
}
newVVI.filePath = cursor.getString(cursor
.getColumnIndexOrThrow(MediaStore.Video.Media.DATA));
newVVI.title = cursor.getString(cursor
.getColumnIndexOrThrow(MediaStore.Video.Media.TITLE));
try {
newVVI.date = cursor.getString(cursor
.getColumnIndexOrThrow(MediaStore.Video.Media.DATE_TAKEN));
} catch (IllegalArgumentException e) {
// TODO Auto-generated catch block
newVVI.date = "0";
}
try {
newVVI.duration = cursor.getString(cursor
.getColumnIndexOrThrow(MediaStore.Video.Media.DURATION));
} catch (IllegalArgumentException e) {
// TODO Auto-generated catch block
newVVI.duration = "0";
}
try {
newVVI.size = cursor.getString(cursor
.getColumnIndexOrThrow(MediaStore.Video.Media.SIZE));
} catch (IllegalArgumentException e) {
// TODO Auto-generated catch block
newVVI.size = "0";
}
try {
newVVI.resolution = cursor.getString(cursor
.getColumnIndexOrThrow(MediaStore.Video.Media.RESOLUTION));
} catch (IllegalArgumentException e) {
// TODO Auto-generated catch block
newVVI.resolution = "0";
}
newVVI.mimeType = cursor
.getString(cursor
.getColumnIndexOrThrow(MediaStore.Video.Media.MIME_TYPE));
newVVI.id = Integer.toString(i);
ITEMS.add(newVVI);
ITEM_MAP.put(newVVI.id, newVVI);
i++;
} while (cursor.moveToNext());
cursor.close();
} else {
Log.d("TEST", ": else);
}
}
问题在于,对于 MediaStore.Video.Media.DATE_TAKEN、MediaStore.Video.Media.DURATION、MediaStore.Video.Media.SIZE 和 MediaStore.Video.Media.RESOLUTION,我总是得到“0”,因为对于这些,我总是抓住非法参数异常。
为什么?