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" />
|
||||
|
||||
<data android:mimeType="image/*" />
|
||||
<data android:mimeType="audio/*" />
|
||||
</intent-filter>
|
||||
</activity>
|
||||
|
||||
|
|
|
|||
|
|
@ -28,4 +28,10 @@
|
|||
<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_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>
|
||||
|
|
@ -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();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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,18 +44,22 @@ 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);
|
||||
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, imageUri);
|
||||
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);
|
||||
|
|
@ -65,7 +69,6 @@ public class ShareActivity extends AuthenticatedActivity {
|
|||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -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,10 +124,13 @@ 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 {
|
||||
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,
|
||||
|
|
@ -124,8 +139,48 @@ public class UploadService extends IntentService {
|
|||
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);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue