Comment #2- Fix audio file issue

pull/95/head
Thomas 3 years ago
parent e53a9e1f87
commit 685f0ce9a8

@ -1319,9 +1319,9 @@ public class Helper {
MimeTypeMap mime = MimeTypeMap.getSingleton(); MimeTypeMap mime = MimeTypeMap.getSingleton();
String extension = mime.getExtensionFromMimeType(cR.getType(uri)); String extension = mime.getExtensionFromMimeType(cR.getType(uri));
if (uri.toString().endsWith("fedilab_recorded_audio.wav")) { if (uri.toString().endsWith("fedilab_recorded_audio.m4a")) {
extension = "wav"; extension = ".m4a";
attachment.mimeType = "audio/x-wav"; attachment.mimeType = "audio/mp4";
} }
SimpleDateFormat formatter = new SimpleDateFormat("yyyy_MM_dd_HH_mm_ss_" + counter, Locale.getDefault()); SimpleDateFormat formatter = new SimpleDateFormat("yyyy_MM_dd_HH_mm_ss_" + counter, Locale.getDefault());
counter++; counter++;

@ -24,7 +24,6 @@ import android.content.Intent;
import android.content.SharedPreferences; import android.content.SharedPreferences;
import android.graphics.BitmapFactory; import android.graphics.BitmapFactory;
import android.graphics.drawable.Drawable; import android.graphics.drawable.Drawable;
import android.media.AudioFormat;
import android.media.MediaRecorder; import android.media.MediaRecorder;
import android.net.Uri; import android.net.Uri;
import android.os.Build; import android.os.Build;
@ -282,7 +281,7 @@ public class MediaHelper {
* @param listener ActionRecord * @param listener ActionRecord
*/ */
public static void recordAudio(Activity activity, ActionRecord listener) { public static void recordAudio(Activity activity, ActionRecord listener) {
String filePath = activity.getCacheDir() + "/fedilab_recorded_audio.wav"; String filePath = activity.getCacheDir() + "/fedilab_recorded_audio.m4a";
AudioRecorder mAudioRecorder = AudioRecorder.getInstance(); AudioRecorder mAudioRecorder = AudioRecorder.getInstance();
File mAudioFile = new File(filePath); File mAudioFile = new File(filePath);
PopupRecordBinding binding = PopupRecordBinding.inflate(activity.getLayoutInflater()); PopupRecordBinding binding = PopupRecordBinding.inflate(activity.getLayoutInflater());
@ -322,9 +321,7 @@ public class MediaHelper {
listener.onRecorded(filePath); listener.onRecorded(filePath);
}); });
mAudioRecorder.prepareRecord(MediaRecorder.AudioSource.MIC, mAudioRecorder.prepareRecord(MediaRecorder.AudioSource.MIC,
AudioFormat.ENCODING_PCM_16BIT, MediaRecorder.AudioEncoder.AAC, MediaRecorder.OutputFormat.MPEG_4, MediaRecorder.AudioEncoder.AAC,
48000,
128000,
mAudioFile); mAudioFile);
mAudioRecorder.startRecord(); mAudioRecorder.startRecord();
} }

@ -212,12 +212,13 @@ public class PostMessageService extends IntentService {
attachmentIds.add(attachment.id); attachmentIds.add(attachment.id);
} else { } else {
MultipartBody.Part fileMultipartBody; MultipartBody.Part fileMultipartBody;
if (watermark && attachment.mimeType.contains("image")) { if (watermark && attachment.mimeType != null && attachment.mimeType.contains("image")) {
fileMultipartBody = Helper.getMultipartBodyWithWM(PostMessageService.this, watermarkText, "file", attachment); fileMultipartBody = Helper.getMultipartBodyWithWM(PostMessageService.this, watermarkText, "file", attachment);
} else { } else {
fileMultipartBody = Helper.getMultipartBody("file", attachment); fileMultipartBody = Helper.getMultipartBody("file", attachment);
} }
Call<Attachment> attachmentCall = mastodonStatusesService.postMedia(token, fileMultipartBody, null, attachment.description, null); Call<Attachment> attachmentCall = mastodonStatusesService.postMedia(token, fileMultipartBody, null, attachment.description, null);
if (attachmentCall != null) { if (attachmentCall != null) {
try { try {
Response<Attachment> attachmentResponse = attachmentCall.execute(); Response<Attachment> attachmentResponse = attachmentCall.execute();

Loading…
Cancel
Save