diff --git a/AndroidManifest.xml b/AndroidManifest.xml
index c28e2fe7d..4997d9697 100644
--- a/AndroidManifest.xml
+++ b/AndroidManifest.xml
@@ -36,6 +36,7 @@
+
diff --git a/res/values/strings.xml b/res/values/strings.xml
index c0b25a718..72661de3b 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -28,4 +28,10 @@
Finishing uploading %1$s
Uploading %1$s failed
Tap to retry
+
+ Starting %1$s Transcoding
+ Transcoding %1$s
+ Finished Transcoding %1$s
+ Failed Transcoding %1$s
+ Tap to try again
\ No newline at end of file
diff --git a/src/org/wikimedia/commons/CommonsApplication.java b/src/org/wikimedia/commons/CommonsApplication.java
index 005e3d6f4..f5ede4677 100644
--- a/src/org/wikimedia/commons/CommonsApplication.java
+++ b/src/org/wikimedia/commons/CommonsApplication.java
@@ -1,6 +1,7 @@
package org.wikimedia.commons;
import java.io.IOException;
+import com.gst_sdk.GStreamer;
import java.io.StringWriter;
import javax.xml.transform.*;
@@ -39,6 +40,13 @@ public class CommonsApplication extends Application {
public void onCreate() {
// TODO Auto-generated method stub
super.onCreate();
+ System.loadLibrary("gstreamer_android");
+ try {
+ GStreamer.init(this);
+ } catch (Exception e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
api = createMWApi();
}
diff --git a/src/org/wikimedia/commons/ShareActivity.java b/src/org/wikimedia/commons/ShareActivity.java
index 61a70942b..9fcf56a94 100644
--- a/src/org/wikimedia/commons/ShareActivity.java
+++ b/src/org/wikimedia/commons/ShareActivity.java
@@ -33,7 +33,7 @@ public class ShareActivity extends AuthenticatedActivity {
private EditText titleEdit;
private EditText descEdit;
- private Uri imageUri;
+ private Uri mediaUri;
@Override
protected void onAuthCookieAcquired(String authCookie) {
@@ -44,26 +44,29 @@ public class ShareActivity extends AuthenticatedActivity {
final Context that = this;
if(intent.getAction().equals(Intent.ACTION_SEND)) {
- if(intent.getType().startsWith("image/")) {
+ mediaUri = (Uri) intent.getParcelableExtra(Intent.EXTRA_STREAM);
+
+ final String mimeType = intent.getType();
+ if(mimeType.startsWith("image/")) {
ImageLoaderTask loader = new ImageLoaderTask(backgroundImageView);
- imageUri = (Uri) intent.getParcelableExtra(Intent.EXTRA_STREAM);
- loader.execute(imageUri);
-
- uploadButton.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View v) {
- Intent uploadIntent = new Intent(getApplicationContext(), UploadService.class);
- uploadIntent.putExtra(UploadService.EXTRA_MEDIA_URI, imageUri);
- uploadIntent.putExtra(UploadService.EXTRA_TARGET_FILENAME, titleEdit.getText().toString());
- uploadIntent.putExtra(UploadService.EXTRA_DESCRIPTION, descEdit.getText().toString());
- uploadIntent.putExtra(UploadService.EXTRA_EDIT_SUMMARY, "Mobile upload from Wikimedia Commons Android app");
- startService(uploadIntent);
- Toast startingToast = Toast.makeText(that, R.string.uploading_started, Toast.LENGTH_LONG);
- startingToast.show();
- finish();
- }
- });
+ loader.execute(mediaUri);
}
+
+ uploadButton.setOnClickListener(new View.OnClickListener() {
+ @Override
+ public void onClick(View v) {
+ Intent uploadIntent = new Intent(getApplicationContext(), UploadService.class);
+ uploadIntent.putExtra(UploadService.EXTRA_MEDIA_URI, mediaUri);
+ uploadIntent.putExtra(UploadService.EXTRA_TARGET_FILENAME, titleEdit.getText().toString());
+ uploadIntent.putExtra(UploadService.EXTRA_DESCRIPTION, descEdit.getText().toString());
+ uploadIntent.putExtra(UploadService.EXTRA_MIMETYPE, mimeType);
+ uploadIntent.putExtra(UploadService.EXTRA_EDIT_SUMMARY, "Mobile upload from Wikimedia Commons Android app");
+ startService(uploadIntent);
+ Toast startingToast = Toast.makeText(that, R.string.uploading_started, Toast.LENGTH_LONG);
+ startingToast.show();
+ finish();
+ }
+ });
}
}
diff --git a/src/org/wikimedia/commons/UploadService.java b/src/org/wikimedia/commons/UploadService.java
index ad68bd653..013fc3733 100644
--- a/src/org/wikimedia/commons/UploadService.java
+++ b/src/org/wikimedia/commons/UploadService.java
@@ -28,6 +28,7 @@ public class UploadService extends IntentService {
public static final String EXTRA_TARGET_FILENAME = EXTRA_PREFIX + ".filename";
public static final String EXTRA_DESCRIPTION = EXTRA_PREFIX + ".description";
public static final String EXTRA_EDIT_SUMMARY = EXTRA_PREFIX + ".summary";
+ public static final String EXTRA_MIMETYPE = EXTRA_PREFIX + ".mimetype";
private NotificationManager notificationManager;
private CommonsApplication app;
@@ -46,6 +47,9 @@ public class UploadService extends IntentService {
public static final int NOTIFICATION_DOWNLOAD_COMPLETE = 2;
public static final int NOTIFICATION_UPLOAD_FAILED = 3;
+ public static final int NOTIFICATION_TRANSCODING_IN_PROGRESS = 4;
+ public static final int NOTIFICATION_TRANSCODING_FAILED = 5;
+
private class NotificationUpdateProgressListener implements ProgressListener {
Notification curNotification;
@@ -98,12 +102,20 @@ public class UploadService extends IntentService {
app = (CommonsApplication)this.getApplicationContext();
}
+ private String getRealPathFromURI(Uri contentUri) {
+ String[] proj = { MediaStore.Images.Media.DATA };
+ CursorLoader loader = new CursorLoader(this, contentUri, proj, null, null, null);
+ Cursor cursor = loader.loadInBackground();
+ int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
+ cursor.moveToFirst();
+ return cursor.getString(column_index);
+ }
@Override
protected void onHandleIntent(Intent intent) {
MWApi api = app.getApi();
- InputStream file;
- long length;
+ InputStream file = null;
+ long length = 0;
ApiResult result;
RemoteViews notificationView;
@@ -112,20 +124,63 @@ public class UploadService extends IntentService {
String filename = intent.getStringExtra(EXTRA_TARGET_FILENAME);
String description = intent.getStringExtra(EXTRA_DESCRIPTION);
String editSummary = intent.getStringExtra(EXTRA_EDIT_SUMMARY);
+ String mimeType = intent.getStringExtra(EXTRA_MIMETYPE);
String notificationTag = mediaUri.toString();
Date dateCreated = null;
try {
- file = this.getContentResolver().openInputStream(mediaUri);
- length = this.getContentResolver().openAssetFileDescriptor(mediaUri, "r").getLength();
- Cursor cursor = this.getContentResolver().query(mediaUri,
- new String[] { MediaStore.Images.ImageColumns.DATE_TAKEN }, null, null, null);
- if(cursor.getCount() != 0) {
- cursor.moveToFirst();
- dateCreated = new Date(cursor.getInt(0));
+ Log.d("Commons", "MimeType is " + mimeType);
+ if(mimeType.startsWith("image/")) {
+ file = this.getContentResolver().openInputStream(mediaUri);
+ length = this.getContentResolver().openAssetFileDescriptor(mediaUri, "r").getLength();
+ Cursor cursor = this.getContentResolver().query(mediaUri,
+ new String[] { MediaStore.Images.ImageColumns.DATE_TAKEN }, null, null, null);
+ if(cursor.getCount() != 0) {
+ cursor.moveToFirst();
+ dateCreated = new Date(cursor.getInt(0));
+ }
+ } else if (mimeType.startsWith("audio/")) {
+ String srcPath = this.getRealPathFromURI(mediaUri);
+ File destFile = File.createTempFile("org.wikimedia.commons", ".ogg");
+ Log.d("Commons", "Path is " + srcPath);
+ Log.d("Commons", "Dest is " + destFile.getAbsolutePath());
+
+ Notification transcodeNotification = new NotificationCompat.Builder(this).setAutoCancel(true)
+ .setSmallIcon(R.drawable.ic_launcher)
+ .setAutoCancel(true)
+ .setOngoing(true)
+ .setContentTitle(String.format(getString(R.string.transcoding_progress_title_in_progress), filename))
+ .setContentIntent(PendingIntent.getActivity(getApplicationContext(), 0, new Intent(), 0))
+ .setTicker(String.format(getString(R.string.transcoding_progress_title_in_progress), filename))
+ .getNotification();
+
+ startForeground(NOTIFICATION_TRANSCODING_IN_PROGRESS, transcodeNotification);
+
+ int transcodeResult = Transcoder.transcode(srcPath, destFile.getAbsolutePath(), null);
+ stopForeground(true);
+
+ if(transcodeResult != 0) {
+ Notification failureNotification = new NotificationCompat.Builder(this).setAutoCancel(true)
+ .setSmallIcon(R.drawable.ic_launcher)
+ .setAutoCancel(true)
+ .setContentIntent(PendingIntent.getService(getApplicationContext(), 0, intent, 0))
+ .setTicker(String.format(getString(R.string.transcoding_failed_notification_title), filename))
+ .setContentTitle(String.format(getString(R.string.transcoding_failed_notification_title), filename))
+ .setContentText(getString(R.string.transcoding_failed_notification_subtitle))
+ .getNotification();
+ notificationManager.notify(NOTIFICATION_TRANSCODING_FAILED, failureNotification);
+ return;
+ }
+
+ file = new FileInputStream(destFile);
+ length = destFile.length();
+ dateCreated = new Date(destFile.lastModified());
+ Log.d("Commons", "Transcode doen!");
}
} catch (FileNotFoundException e) {
throw new RuntimeException(e);
+ } catch (IOException e) {
+ throw new RuntimeException(e);
}
notificationView = new RemoteViews(getPackageName(), R.layout.layout_upload_progress);