这是indexloc提供的服务,不要输入任何密码
Skip to content

Commit 992ce17

Browse files
Biswa96agnostic-apollo
authored andcommitted
Added(MicRecorderAPI): Add opus audio encoder
1 parent 0eae939 commit 992ce17

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

app/src/main/java/com/termux/api/apis/MicRecorderAPI.java

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import android.content.Context;
55
import android.content.Intent;
66
import android.media.MediaRecorder;
7+
import android.os.Build;
78
import android.os.Environment;
89
import android.os.IBinder;
910
import android.util.ArrayMap;
@@ -213,30 +214,36 @@ public RecorderCommandResult handle(Context context, Intent intent) {
213214
duration = MIN_RECORDING_LIMIT;
214215

215216
String sencoder = intent.hasExtra("encoder") ? intent.getStringExtra("encoder") : "";
216-
ArrayMap<String, Integer> encoder_map = new ArrayMap<>(3);
217+
ArrayMap<String, Integer> encoder_map = new ArrayMap<>(4);
217218
encoder_map.put("aac", MediaRecorder.AudioEncoder.AAC);
218219
encoder_map.put("amr_nb", MediaRecorder.AudioEncoder.AMR_NB);
219220
encoder_map.put("amr_wb", MediaRecorder.AudioEncoder.AMR_WB);
221+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q)
222+
encoder_map.put("opus", MediaRecorder.AudioEncoder.OPUS);
220223

221224
Integer encoder = encoder_map.get(sencoder.toLowerCase());
222225
if (encoder == null)
223226
encoder = MediaRecorder.AudioEncoder.AAC;
224227

225228
int format = intent.getIntExtra("format", MediaRecorder.OutputFormat.DEFAULT);
226229
if (format == MediaRecorder.OutputFormat.DEFAULT) {
227-
SparseIntArray format_map = new SparseIntArray(3);
230+
SparseIntArray format_map = new SparseIntArray(4);
228231
format_map.put(MediaRecorder.AudioEncoder.AAC,
229232
MediaRecorder.OutputFormat.MPEG_4);
230233
format_map.put(MediaRecorder.AudioEncoder.AMR_NB,
231234
MediaRecorder.OutputFormat.THREE_GPP);
232235
format_map.put(MediaRecorder.AudioEncoder.AMR_WB,
233236
MediaRecorder.OutputFormat.THREE_GPP);
237+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q)
238+
format_map.put(MediaRecorder.AudioEncoder.OPUS, MediaRecorder.OutputFormat.OGG);
234239
format = format_map.get(encoder, MediaRecorder.OutputFormat.DEFAULT);
235240
}
236241

237-
SparseArray<String> extension_map = new SparseArray<>(2);
242+
SparseArray<String> extension_map = new SparseArray<>(3);
238243
extension_map.put(MediaRecorder.OutputFormat.MPEG_4, ".m4a");
239244
extension_map.put(MediaRecorder.OutputFormat.THREE_GPP, ".3gp");
245+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q)
246+
extension_map.put(MediaRecorder.OutputFormat.OGG, ".ogg");
240247
String extension = extension_map.get(format);
241248

242249
String filename = intent.hasExtra("file") ? intent.getStringExtra("file") : getDefaultRecordingFilename() + (extension != null ? extension : "");

0 commit comments

Comments
 (0)