mirror of
https://github.com/commons-app/apps-android-commons.git
synced 2025-10-26 20:33:53 +01:00
Initial support for GStreamer Audio Encoding to Ogg
This commit is contained in:
parent
81aacd7b11
commit
836d35e708
5 changed files with 101 additions and 28 deletions
|
|
@ -36,6 +36,7 @@
|
||||||
<category android:name="android.intent.category.DEFAULT" />
|
<category android:name="android.intent.category.DEFAULT" />
|
||||||
|
|
||||||
<data android:mimeType="image/*" />
|
<data android:mimeType="image/*" />
|
||||||
|
<data android:mimeType="audio/*" />
|
||||||
</intent-filter>
|
</intent-filter>
|
||||||
</activity>
|
</activity>
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -28,4 +28,10 @@
|
||||||
<string name="upload_progress_notification_title_finishing">Finishing uploading %1$s</string>
|
<string name="upload_progress_notification_title_finishing">Finishing uploading %1$s</string>
|
||||||
<string name="upload_failed_notification_title">Uploading %1$s failed</string>
|
<string name="upload_failed_notification_title">Uploading %1$s failed</string>
|
||||||
<string name="upload_failed_notification_subtitle">Tap to retry</string>
|
<string name="upload_failed_notification_subtitle">Tap to retry</string>
|
||||||
|
|
||||||
|
<string name="transcoding_progress_title_start">Starting %1$s Transcoding</string>
|
||||||
|
<string name="transcoding_progress_title_in_progress">Transcoding %1$s</string>
|
||||||
|
<string name="transcoding_progress_title_finishing">Finished Transcoding %1$s</string>
|
||||||
|
<string name="transcoding_failed_notification_title">Failed Transcoding %1$s</string>
|
||||||
|
<string name="transcoding_failed_notification_subtitle">Tap to try again</string>
|
||||||
</resources>
|
</resources>
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
package org.wikimedia.commons;
|
package org.wikimedia.commons;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import com.gst_sdk.GStreamer;
|
||||||
import java.io.StringWriter;
|
import java.io.StringWriter;
|
||||||
|
|
||||||
import javax.xml.transform.*;
|
import javax.xml.transform.*;
|
||||||
|
|
@ -39,6 +40,13 @@ public class CommonsApplication extends Application {
|
||||||
public void onCreate() {
|
public void onCreate() {
|
||||||
// TODO Auto-generated method stub
|
// TODO Auto-generated method stub
|
||||||
super.onCreate();
|
super.onCreate();
|
||||||
|
System.loadLibrary("gstreamer_android");
|
||||||
|
try {
|
||||||
|
GStreamer.init(this);
|
||||||
|
} catch (Exception e) {
|
||||||
|
// TODO Auto-generated catch block
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
api = createMWApi();
|
api = createMWApi();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -33,7 +33,7 @@ public class ShareActivity extends AuthenticatedActivity {
|
||||||
private EditText titleEdit;
|
private EditText titleEdit;
|
||||||
private EditText descEdit;
|
private EditText descEdit;
|
||||||
|
|
||||||
private Uri imageUri;
|
private Uri mediaUri;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onAuthCookieAcquired(String authCookie) {
|
protected void onAuthCookieAcquired(String authCookie) {
|
||||||
|
|
@ -44,26 +44,29 @@ public class ShareActivity extends AuthenticatedActivity {
|
||||||
final Context that = this;
|
final Context that = this;
|
||||||
|
|
||||||
if(intent.getAction().equals(Intent.ACTION_SEND)) {
|
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);
|
ImageLoaderTask loader = new ImageLoaderTask(backgroundImageView);
|
||||||
imageUri = (Uri) intent.getParcelableExtra(Intent.EXTRA_STREAM);
|
loader.execute(mediaUri);
|
||||||
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();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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();
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -28,6 +28,7 @@ public class UploadService extends IntentService {
|
||||||
public static final String EXTRA_TARGET_FILENAME = EXTRA_PREFIX + ".filename";
|
public static final String EXTRA_TARGET_FILENAME = EXTRA_PREFIX + ".filename";
|
||||||
public static final String EXTRA_DESCRIPTION = EXTRA_PREFIX + ".description";
|
public static final String EXTRA_DESCRIPTION = EXTRA_PREFIX + ".description";
|
||||||
public static final String EXTRA_EDIT_SUMMARY = EXTRA_PREFIX + ".summary";
|
public static final String EXTRA_EDIT_SUMMARY = EXTRA_PREFIX + ".summary";
|
||||||
|
public static final String EXTRA_MIMETYPE = EXTRA_PREFIX + ".mimetype";
|
||||||
|
|
||||||
private NotificationManager notificationManager;
|
private NotificationManager notificationManager;
|
||||||
private CommonsApplication app;
|
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_DOWNLOAD_COMPLETE = 2;
|
||||||
public static final int NOTIFICATION_UPLOAD_FAILED = 3;
|
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 {
|
private class NotificationUpdateProgressListener implements ProgressListener {
|
||||||
|
|
||||||
Notification curNotification;
|
Notification curNotification;
|
||||||
|
|
@ -98,12 +102,20 @@ public class UploadService extends IntentService {
|
||||||
app = (CommonsApplication)this.getApplicationContext();
|
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
|
@Override
|
||||||
protected void onHandleIntent(Intent intent) {
|
protected void onHandleIntent(Intent intent) {
|
||||||
MWApi api = app.getApi();
|
MWApi api = app.getApi();
|
||||||
InputStream file;
|
InputStream file = null;
|
||||||
long length;
|
long length = 0;
|
||||||
ApiResult result;
|
ApiResult result;
|
||||||
RemoteViews notificationView;
|
RemoteViews notificationView;
|
||||||
|
|
||||||
|
|
@ -112,20 +124,63 @@ public class UploadService extends IntentService {
|
||||||
String filename = intent.getStringExtra(EXTRA_TARGET_FILENAME);
|
String filename = intent.getStringExtra(EXTRA_TARGET_FILENAME);
|
||||||
String description = intent.getStringExtra(EXTRA_DESCRIPTION);
|
String description = intent.getStringExtra(EXTRA_DESCRIPTION);
|
||||||
String editSummary = intent.getStringExtra(EXTRA_EDIT_SUMMARY);
|
String editSummary = intent.getStringExtra(EXTRA_EDIT_SUMMARY);
|
||||||
|
String mimeType = intent.getStringExtra(EXTRA_MIMETYPE);
|
||||||
String notificationTag = mediaUri.toString();
|
String notificationTag = mediaUri.toString();
|
||||||
Date dateCreated = null;
|
Date dateCreated = null;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
file = this.getContentResolver().openInputStream(mediaUri);
|
Log.d("Commons", "MimeType is " + mimeType);
|
||||||
length = this.getContentResolver().openAssetFileDescriptor(mediaUri, "r").getLength();
|
if(mimeType.startsWith("image/")) {
|
||||||
Cursor cursor = this.getContentResolver().query(mediaUri,
|
file = this.getContentResolver().openInputStream(mediaUri);
|
||||||
new String[] { MediaStore.Images.ImageColumns.DATE_TAKEN }, null, null, null);
|
length = this.getContentResolver().openAssetFileDescriptor(mediaUri, "r").getLength();
|
||||||
if(cursor.getCount() != 0) {
|
Cursor cursor = this.getContentResolver().query(mediaUri,
|
||||||
cursor.moveToFirst();
|
new String[] { MediaStore.Images.ImageColumns.DATE_TAKEN }, null, null, null);
|
||||||
dateCreated = new Date(cursor.getInt(0));
|
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) {
|
} catch (FileNotFoundException e) {
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
|
} catch (IOException e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
}
|
}
|
||||||
|
|
||||||
notificationView = new RemoteViews(getPackageName(), R.layout.layout_upload_progress);
|
notificationView = new RemoteViews(getPackageName(), R.layout.layout_upload_progress);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue