Details
-
Type:
Bug
-
Status: Closed
-
Priority:
Low
-
Resolution: Fixed
-
Affects Version/s: Release 7.0.0
-
Fix Version/s: Release 9.3.0
-
Component/s: Android
-
Labels:
-
Environment:
Mac OS
Ti 7.0.X
Android
Description
Hi there. Using this code:
Ti.Media.showCamera({
|
autohide : false, |
showControls : false, |
overlay : cameraControls.getView(),
|
saveToPhotoGallery : false, |
videoMaximumDuration : 60 * 1000,
|
mediaTypes : [ Titanium.Media.MEDIA_TYPE_PHOTO, Titanium.Media.MEDIA_TYPE_VIDEO ],
|
success : function(e) { |
Ti.API.info(' e.media.mimeType: ' + e.media.mimeType); |
},
|
error : function(e) { |
Ti.API.error(JSON.stringify(e));
|
},
|
cancel : function() { |
Ti.API.info('Action cancelled'); |
}
|
});
|
And calling Ti.Media.takePicture() from "cameraControls" controller, outputs "video/mp4" in the console, i.e., I've opened the camera for both, taking a photo or a video, but if I take a photo, the callback returns a video mimeType with .mp4 extension.
I've fixed this by commenting an if block in TiCameraActivity.java (package ti.modules.titanium.media):
private static File writeToFile(byte[] data, boolean saveToGallery) throws Throwable |
{
|
try { |
File imageFile = null; |
if (saveToGallery) { |
imageFile = MediaModule.createGalleryImageFile();
|
} else { |
// Save the picture in the internal data directory so it is private to this application. |
String extension = ".jpg"; |
// Rodrigo Farfán (phobeous@gmail.com): |
// This has no sense. The only point where this method is called is in jpegCallback and |
// video recording creates his own file. So this is absolutely wrong |
// Let's comment out next if block |
/* |
if (mediaType == MEDIA_TYPE_VIDEO) {
|
extension = ".mp4";
|
}
|
*/
|
imageFile = TiFileFactory.createDataFile("tia", extension); |
}
|
|
FileOutputStream imageOut = new FileOutputStream(imageFile); |
imageOut.write(data);
|
imageOut.close();
|
|
if (saveToGallery) { |
Intent mediaScanIntent = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE); |
Uri contentUri = Uri.fromFile(imageFile);
|
mediaScanIntent.setData(contentUri);
|
Activity activity = TiApplication.getAppCurrentActivity();
|
activity.sendBroadcast(mediaScanIntent);
|
}
|
return imageFile; |
|
} catch (Throwable t) { |
throw t; |
}
|
}
|
Please, review this and consider adding the fix to master branch for future releases.
Best regards