voice messages for Android 10+

This commit is contained in:
Thomas 2023-07-27 13:57:29 +02:00
parent e06222733c
commit 8c60348939
3 changed files with 17 additions and 8 deletions

View file

@ -304,6 +304,12 @@ public class ComposeActivity extends BaseActivity implements ComposeAdapter.Mana
public boolean onCreateOptionsMenu(@NonNull Menu menu) { public boolean onCreateOptionsMenu(@NonNull Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present. // Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_compose, menu); getMenuInflater().inflate(R.menu.menu_compose, menu);
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.Q) {
MenuItem micro = menu.findItem(R.id.action_microphone);
if (micro != null) {
micro.setVisible(false);
}
}
return true; return true;
} }

View file

@ -1282,9 +1282,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.m4a")) { if (uri.toString().endsWith("fedilab_recorded_audio.ogg")) {
extension = ".m4a"; extension = "ogg";
attachment.mimeType = "audio/mp4"; attachment.mimeType = "audio/ogg";
} }
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++;

View file

@ -274,7 +274,8 @@ 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.m4a"; //String filePath = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS).getAbsolutePath() + "/fedilab_recorded_audio.ogg";
String filePath = activity.getCacheDir() + "/fedilab_recorded_audio.ogg";
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());
@ -306,16 +307,18 @@ public class MediaHelper {
binding.counter.setText(String.format(Locale.getDefault(), "%s:%s", minutes, seconds)); binding.counter.setText(String.format(Locale.getDefault(), "%s:%s", minutes, seconds));
}); });
} }
}, 1000, 1000); }, 0, 1000);
binding.record.setOnClickListener(v -> { binding.record.setOnClickListener(v -> {
mAudioRecorder.stopRecord(); mAudioRecorder.stopRecord();
timer.cancel(); timer.cancel();
alert.dismiss(); alert.dismiss();
listener.onRecorded(filePath); listener.onRecorded(filePath);
}); });
mAudioRecorder.prepareRecord(MediaRecorder.AudioSource.MIC, if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
MediaRecorder.OutputFormat.MPEG_4, MediaRecorder.AudioEncoder.AAC, mAudioRecorder.prepareRecord(MediaRecorder.AudioSource.MIC,
mAudioFile); MediaRecorder.OutputFormat.OGG, MediaRecorder.AudioEncoder.OPUS, 48000, 384000,
mAudioFile);
}
mAudioRecorder.startRecord(); mAudioRecorder.startRecord();
} }