MultimediaConversionRequest request = new MultimediaConversionRequest();
request.setInFile( file );
request.setThumbnailRequested(true);
request.setProgress( new MultimediaProgressAdaptor() );
MultimediaClass mmClass = MimeUtils.getMultimediaClassFromMimeType(mimeType);
if( MultimediaClass.VIDEO == mmClass ) {
// For video file, convert to appropriate file type
mmConverter.convertVideo(request);
} else if( MultimediaClass.AUDIO == mmClass ) {
// For audio file, convert to appropriate file type
mmConverter.convertAudio(request);
} else if( MultimediaClass.IMAGE == mmClass ) {
// For image file, convert to appropriate file type
mmConverter.convertImage(request);
} else {
// No conversion required. Go directly to waiting for approval
doc.put(UploadConstants.UPLOAD_KEY, UploadConstants.UPLOAD_VALUE_WAITING_FOR_APPROVAL);
dd.getDatabase().updateDocument(doc);
sendContributionApprovalRequest(docId, doc);
return;
}
// Report original size
if( request.getInHeight() != 0 && request.getInWidth() != 0 ) {
originalObj.put("height", request.getInHeight());
originalObj.put("width", request.getInWidth());
}
// Report converted object
{
File convertedFile = request.getOutFile();
SystemFile convertedSf = SystemFile.getSystemFile(convertedFile);
JSONObject convertedObj = new JSONObject();
convertedObj.put("conversionPerformed", request.isConversionPerformed());
convertedObj.put("media", convertedFile.getName());
convertedObj.put(UploadConstants.SIZE_KEY, convertedFile.length());
convertedObj.put(UploadConstants.MIME_KEY, convertedSf.getMimeType());
convertedObj.put(UploadConstants.ENCODING_KEY, convertedSf.getMimeEncoding());
if( request.getOutHeight() != 0 && request.getOutWidth() != 0 ) {
convertedObj.put("height", request.getOutHeight());
convertedObj.put("width", request.getOutWidth());
}
doc.put("converted",convertedObj);
}
// Report thumbnail object
if( request.isThumbnailCreated() ) {
File thumbFile = request.getThumbnailFile();
SystemFile thumbSf = SystemFile.getSystemFile(thumbFile);
// Report converted object
JSONObject thumbObj = new JSONObject();
thumbObj.put("media", thumbFile.getName());
thumbObj.put(UploadConstants.SIZE_KEY, thumbFile.length());
thumbObj.put(UploadConstants.MIME_KEY, thumbSf.getMimeType());
thumbObj.put(UploadConstants.ENCODING_KEY, thumbSf.getMimeEncoding());
if( request.getThumbnailHeight() != 0 && request.getThumbnailWidth() != 0 ) {
thumbObj.put("height", request.getThumbnailHeight());
thumbObj.put("width", request.getThumbnailWidth());
}
doc.put("thumbnail",thumbObj);
}
// Mark end of this phase
doc.put(UploadConstants.UPLOAD_KEY, UploadConstants.UPLOAD_VALUE_WAITING_FOR_APPROVAL);
doc.put(UploadConstants.MIME_CLASS_KEY, mmClass.getValue());
dd.getDatabase().updateDocument(doc);
// Notify that upload is available
sendContributionApprovalRequest(docId, doc);