mirror of
https://github.com/apache/cordova-android.git
synced 2025-01-19 15:12:51 +08:00
Fix for Issue #218: audio capture audio/3gpp mimetype getting set to video/3gpp
Works around an issue where MimeTypeMap.getMimeTypeFromExtension() always returns video/3gpp when the file extension is .3gp or .3gpp.
This commit is contained in:
parent
e41746b6a8
commit
70de3d49a2
@ -29,6 +29,10 @@ import com.phonegap.api.PluginResult;
|
|||||||
|
|
||||||
public class Capture extends Plugin {
|
public class Capture extends Plugin {
|
||||||
|
|
||||||
|
private static final String VIDEO_3GPP = "video/3gpp";
|
||||||
|
private static final String AUDIO_3GPP = "audio/3gpp";
|
||||||
|
private static final String IMAGE_JPEG = "image/jpeg";
|
||||||
|
|
||||||
private static final int CAPTURE_AUDIO = 0; // Constant for capture audio
|
private static final int CAPTURE_AUDIO = 0; // Constant for capture audio
|
||||||
private static final int CAPTURE_IMAGE = 1; // Constant for capture image
|
private static final int CAPTURE_IMAGE = 1; // Constant for capture image
|
||||||
private static final int CAPTURE_VIDEO = 2; // Constant for capture video
|
private static final int CAPTURE_VIDEO = 2; // Constant for capture video
|
||||||
@ -97,14 +101,15 @@ public class Capture extends Plugin {
|
|||||||
if (mimeType == null || mimeType.equals("")) {
|
if (mimeType == null || mimeType.equals("")) {
|
||||||
mimeType = FileUtils.getMimeType(filePath);
|
mimeType = FileUtils.getMimeType(filePath);
|
||||||
}
|
}
|
||||||
|
Log.d(LOG_TAG, "Mime type = " + mimeType);
|
||||||
|
|
||||||
if (mimeType.equals("image/jpeg") || filePath.endsWith(".jpg")) {
|
if (mimeType.equals(IMAGE_JPEG) || filePath.endsWith(".jpg")) {
|
||||||
obj = getImageData(filePath, obj);
|
obj = getImageData(filePath, obj);
|
||||||
}
|
}
|
||||||
else if (filePath.endsWith("audio/3gpp")) {
|
else if (mimeType.endsWith(AUDIO_3GPP)) {
|
||||||
obj = getAudioVideoData(filePath, obj, false);
|
obj = getAudioVideoData(filePath, obj, false);
|
||||||
}
|
}
|
||||||
else if (mimeType.equals("video/3gpp")) {
|
else if (mimeType.equals(VIDEO_3GPP)) {
|
||||||
obj = getAudioVideoData(filePath, obj, true);
|
obj = getAudioVideoData(filePath, obj, true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -233,7 +238,7 @@ public class Capture extends Plugin {
|
|||||||
// Create entry in media store for image
|
// Create entry in media store for image
|
||||||
// (Don't use insertImage() because it uses default compression setting of 50 - no way to change it)
|
// (Don't use insertImage() because it uses default compression setting of 50 - no way to change it)
|
||||||
ContentValues values = new ContentValues();
|
ContentValues values = new ContentValues();
|
||||||
values.put(android.provider.MediaStore.Images.Media.MIME_TYPE, "image/jpeg");
|
values.put(android.provider.MediaStore.Images.Media.MIME_TYPE, IMAGE_JPEG);
|
||||||
Uri uri = null;
|
Uri uri = null;
|
||||||
try {
|
try {
|
||||||
uri = this.ctx.getContentResolver().insert(android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI, values);
|
uri = this.ctx.getContentResolver().insert(android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI, values);
|
||||||
@ -329,7 +334,20 @@ public class Capture extends Plugin {
|
|||||||
// File properties
|
// File properties
|
||||||
obj.put("name", fp.getName());
|
obj.put("name", fp.getName());
|
||||||
obj.put("fullPath", fp.getAbsolutePath());
|
obj.put("fullPath", fp.getAbsolutePath());
|
||||||
obj.put("type", FileUtils.getMimeType(fp.getAbsolutePath()));
|
|
||||||
|
// Because of an issue with MimeTypeMap.getMimeTypeFromExtension() all .3gpp files
|
||||||
|
// are reported as video/3gpp. I'm doing this hacky check of the URI to see if it
|
||||||
|
// is stored in the audio or video content store.
|
||||||
|
if (fp.getAbsoluteFile().toString().endsWith(".3gp") || fp.getAbsoluteFile().toString().endsWith(".3gpp")) {
|
||||||
|
if (data.toString().contains("/audio/")) {
|
||||||
|
obj.put("type", AUDIO_3GPP);
|
||||||
|
} else {
|
||||||
|
obj.put("type", VIDEO_3GPP);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
obj.put("type", FileUtils.getMimeType(fp.getAbsolutePath()));
|
||||||
|
}
|
||||||
|
|
||||||
obj.put("lastModifiedDate", fp.lastModified());
|
obj.put("lastModifiedDate", fp.lastModified());
|
||||||
obj.put("size", fp.length());
|
obj.put("size", fp.length());
|
||||||
} catch (JSONException e) {
|
} catch (JSONException e) {
|
||||||
|
Loading…
Reference in New Issue
Block a user