Merge "Make MediaScanner extract "date taken" from videos, if present" into nyc-mr1-dev
This commit is contained in:
committed by
Android (Google) Code Review
commit
d63dbfdb6b
@@ -60,11 +60,14 @@ import java.io.FileDescriptor;
|
|||||||
import java.io.FileInputStream;
|
import java.io.FileInputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStreamReader;
|
import java.io.InputStreamReader;
|
||||||
|
import java.text.SimpleDateFormat;
|
||||||
|
import java.text.ParseException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
|
import java.util.TimeZone;
|
||||||
import java.util.concurrent.atomic.AtomicBoolean;
|
import java.util.concurrent.atomic.AtomicBoolean;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -451,6 +454,8 @@ public class MediaScanner implements AutoCloseable {
|
|||||||
|
|
||||||
private class MyMediaScannerClient implements MediaScannerClient {
|
private class MyMediaScannerClient implements MediaScannerClient {
|
||||||
|
|
||||||
|
private final SimpleDateFormat mDateFormatter;
|
||||||
|
|
||||||
private String mArtist;
|
private String mArtist;
|
||||||
private String mAlbumArtist; // use this if mArtist is missing
|
private String mAlbumArtist; // use this if mArtist is missing
|
||||||
private String mAlbum;
|
private String mAlbum;
|
||||||
@@ -463,6 +468,7 @@ public class MediaScanner implements AutoCloseable {
|
|||||||
private int mYear;
|
private int mYear;
|
||||||
private int mDuration;
|
private int mDuration;
|
||||||
private String mPath;
|
private String mPath;
|
||||||
|
private long mDate;
|
||||||
private long mLastModified;
|
private long mLastModified;
|
||||||
private long mFileSize;
|
private long mFileSize;
|
||||||
private String mWriter;
|
private String mWriter;
|
||||||
@@ -472,6 +478,11 @@ public class MediaScanner implements AutoCloseable {
|
|||||||
private int mWidth;
|
private int mWidth;
|
||||||
private int mHeight;
|
private int mHeight;
|
||||||
|
|
||||||
|
public MyMediaScannerClient() {
|
||||||
|
mDateFormatter = new SimpleDateFormat("yyyyMMdd'T'HHmmss");
|
||||||
|
mDateFormatter.setTimeZone(TimeZone.getTimeZone("UTC"));
|
||||||
|
}
|
||||||
|
|
||||||
public FileEntry beginFile(String path, String mimeType, long lastModified,
|
public FileEntry beginFile(String path, String mimeType, long lastModified,
|
||||||
long fileSize, boolean isDirectory, boolean noMedia) {
|
long fileSize, boolean isDirectory, boolean noMedia) {
|
||||||
mMimeType = mimeType;
|
mMimeType = mimeType;
|
||||||
@@ -537,6 +548,7 @@ public class MediaScanner implements AutoCloseable {
|
|||||||
mYear = 0;
|
mYear = 0;
|
||||||
mDuration = 0;
|
mDuration = 0;
|
||||||
mPath = path;
|
mPath = path;
|
||||||
|
mDate = 0;
|
||||||
mLastModified = lastModified;
|
mLastModified = lastModified;
|
||||||
mWriter = null;
|
mWriter = null;
|
||||||
mCompilation = 0;
|
mCompilation = 0;
|
||||||
@@ -627,6 +639,14 @@ public class MediaScanner implements AutoCloseable {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private long parseDate(String date) {
|
||||||
|
try {
|
||||||
|
return mDateFormatter.parse(date).getTime();
|
||||||
|
} catch (ParseException e) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private int parseSubstring(String s, int start, int defaultValue) {
|
private int parseSubstring(String s, int start, int defaultValue) {
|
||||||
int length = s.length();
|
int length = s.length();
|
||||||
if (start == length) return defaultValue;
|
if (start == length) return defaultValue;
|
||||||
@@ -684,6 +704,8 @@ public class MediaScanner implements AutoCloseable {
|
|||||||
mCompilation = parseSubstring(value, 0, 0);
|
mCompilation = parseSubstring(value, 0, 0);
|
||||||
} else if (name.equalsIgnoreCase("isdrm")) {
|
} else if (name.equalsIgnoreCase("isdrm")) {
|
||||||
mIsDrm = (parseSubstring(value, 0, 0) == 1);
|
mIsDrm = (parseSubstring(value, 0, 0) == 1);
|
||||||
|
} else if (name.equalsIgnoreCase("date")) {
|
||||||
|
mDate = parseDate(value);
|
||||||
} else if (name.equalsIgnoreCase("width")) {
|
} else if (name.equalsIgnoreCase("width")) {
|
||||||
mWidth = parseSubstring(value, 0, 0);
|
mWidth = parseSubstring(value, 0, 0);
|
||||||
} else if (name.equalsIgnoreCase("height")) {
|
} else if (name.equalsIgnoreCase("height")) {
|
||||||
@@ -830,6 +852,9 @@ public class MediaScanner implements AutoCloseable {
|
|||||||
if (resolution != null) {
|
if (resolution != null) {
|
||||||
map.put(Video.Media.RESOLUTION, resolution);
|
map.put(Video.Media.RESOLUTION, resolution);
|
||||||
}
|
}
|
||||||
|
if (mDate > 0) {
|
||||||
|
map.put(Video.Media.DATE_TAKEN, mDate);
|
||||||
|
}
|
||||||
} else if (MediaFile.isImageFileType(mFileType)) {
|
} else if (MediaFile.isImageFileType(mFileType)) {
|
||||||
// FIXME - add DESCRIPTION
|
// FIXME - add DESCRIPTION
|
||||||
} else if (MediaFile.isAudioFileType(mFileType)) {
|
} else if (MediaFile.isAudioFileType(mFileType)) {
|
||||||
|
|||||||
Reference in New Issue
Block a user