我使用以下代码上传视频。我使用以下代码执行此操作,但我将"cursor"
变量设为NULL
。有人可以告诉我下面代码中的错误或上传视频的任何其他代码段。
private String getPath(Uri uri) {
String[] projection = { MediaStore.Video.Media.DATA, MediaStore.Video.Media.SIZE, MediaStore.Video.Media.DURATION};
Cursor cursor = getContentResolver().query(uri, projection, null, null, null);
cursor.moveToFirst();
String filePath = cursor.getString(cursor.getColumnIndexOrThrow(MediaStore.Video.Media.DATA));
int fileSize = cursor.getInt(cursor.getColumnIndexOrThrow(MediaStore.Video.Media.SIZE));
long duration = TimeUnit.MILLISECONDS.toSeconds(cursor.getInt(cursor.getColumnIndexOrThrow(MediaStore.Video.Media.DURATION)));
//some extra potentially useful data to help with filtering if necessary
System.out.println("size: " + fileSize);
System.out.println("path: " + filePath);
System.out.println("duration: " + duration);
return filePath;
}