|
4 | 4 | import android.content.Context; |
5 | 5 | import android.content.Intent; |
6 | 6 | import android.media.MediaRecorder; |
| 7 | +import android.os.Build; |
7 | 8 | import android.os.Environment; |
8 | 9 | import android.os.IBinder; |
9 | 10 | import android.util.ArrayMap; |
@@ -213,30 +214,36 @@ public RecorderCommandResult handle(Context context, Intent intent) { |
213 | 214 | duration = MIN_RECORDING_LIMIT; |
214 | 215 |
|
215 | 216 | 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); |
217 | 218 | encoder_map.put("aac", MediaRecorder.AudioEncoder.AAC); |
218 | 219 | encoder_map.put("amr_nb", MediaRecorder.AudioEncoder.AMR_NB); |
219 | 220 | 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); |
220 | 223 |
|
221 | 224 | Integer encoder = encoder_map.get(sencoder.toLowerCase()); |
222 | 225 | if (encoder == null) |
223 | 226 | encoder = MediaRecorder.AudioEncoder.AAC; |
224 | 227 |
|
225 | 228 | int format = intent.getIntExtra("format", MediaRecorder.OutputFormat.DEFAULT); |
226 | 229 | if (format == MediaRecorder.OutputFormat.DEFAULT) { |
227 | | - SparseIntArray format_map = new SparseIntArray(3); |
| 230 | + SparseIntArray format_map = new SparseIntArray(4); |
228 | 231 | format_map.put(MediaRecorder.AudioEncoder.AAC, |
229 | 232 | MediaRecorder.OutputFormat.MPEG_4); |
230 | 233 | format_map.put(MediaRecorder.AudioEncoder.AMR_NB, |
231 | 234 | MediaRecorder.OutputFormat.THREE_GPP); |
232 | 235 | format_map.put(MediaRecorder.AudioEncoder.AMR_WB, |
233 | 236 | MediaRecorder.OutputFormat.THREE_GPP); |
| 237 | + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) |
| 238 | + format_map.put(MediaRecorder.AudioEncoder.OPUS, MediaRecorder.OutputFormat.OGG); |
234 | 239 | format = format_map.get(encoder, MediaRecorder.OutputFormat.DEFAULT); |
235 | 240 | } |
236 | 241 |
|
237 | | - SparseArray<String> extension_map = new SparseArray<>(2); |
| 242 | + SparseArray<String> extension_map = new SparseArray<>(3); |
238 | 243 | extension_map.put(MediaRecorder.OutputFormat.MPEG_4, ".m4a"); |
239 | 244 | 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"); |
240 | 247 | String extension = extension_map.get(format); |
241 | 248 |
|
242 | 249 | String filename = intent.hasExtra("file") ? intent.getStringExtra("file") : getDefaultRecordingFilename() + (extension != null ? extension : ""); |
|
0 commit comments