Comment #2- Fix audio file issue

This commit is contained in:
Thomas 2022-05-10 18:53:04 +02:00
parent e53a9e1f87
commit 685f0ce9a8
3 changed files with 7 additions and 9 deletions

View file

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

View file

@ -24,7 +24,6 @@ import android.content.Intent;
import android.content.SharedPreferences;
import android.graphics.BitmapFactory;
import android.graphics.drawable.Drawable;
import android.media.AudioFormat;
import android.media.MediaRecorder;
import android.net.Uri;
import android.os.Build;
@ -282,7 +281,7 @@ public class MediaHelper {
* @param listener ActionRecord
*/
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();
File mAudioFile = new File(filePath);
PopupRecordBinding binding = PopupRecordBinding.inflate(activity.getLayoutInflater());
@ -322,9 +321,7 @@ public class MediaHelper {
listener.onRecorded(filePath);
});
mAudioRecorder.prepareRecord(MediaRecorder.AudioSource.MIC,
AudioFormat.ENCODING_PCM_16BIT, MediaRecorder.AudioEncoder.AAC,
48000,
128000,
MediaRecorder.OutputFormat.MPEG_4, MediaRecorder.AudioEncoder.AAC,
mAudioFile);
mAudioRecorder.startRecord();
}

View file

@ -212,12 +212,13 @@ public class PostMessageService extends IntentService {
attachmentIds.add(attachment.id);
} else {
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);
} else {
fileMultipartBody = Helper.getMultipartBody("file", attachment);
}
Call<Attachment> attachmentCall = mastodonStatusesService.postMedia(token, fileMultipartBody, null, attachment.description, null);
if (attachmentCall != null) {
try {
Response<Attachment> attachmentResponse = attachmentCall.execute();