@scr2em/capacitor-plugin-recorder 0.0.5 → 0.0.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -3,6 +3,7 @@ package com.capacitor.recorderplayer;
|
|
|
3
3
|
import android.content.Context;
|
|
4
4
|
import android.media.AudioAttributes;
|
|
5
5
|
import android.media.AudioManager;
|
|
6
|
+
import android.media.AudioRecordingConfiguration;
|
|
6
7
|
import android.media.MediaPlayer;
|
|
7
8
|
import android.media.MediaRecorder;
|
|
8
9
|
import android.os.Build;
|
|
@@ -10,6 +11,8 @@ import android.os.Handler;
|
|
|
10
11
|
import android.os.Looper;
|
|
11
12
|
import android.util.Log;
|
|
12
13
|
|
|
14
|
+
import java.util.List;
|
|
15
|
+
|
|
13
16
|
import java.io.File;
|
|
14
17
|
import java.io.IOException;
|
|
15
18
|
import java.util.HashMap;
|
|
@@ -215,7 +218,31 @@ public class RecorderPlayer {
|
|
|
215
218
|
return "player-" + playerIdCounter.incrementAndGet() + "-" + System.currentTimeMillis();
|
|
216
219
|
}
|
|
217
220
|
|
|
221
|
+
private boolean isMicrophoneInUse() {
|
|
222
|
+
// Check if device is in a call mode
|
|
223
|
+
int audioMode = audioManager.getMode();
|
|
224
|
+
if (audioMode == AudioManager.MODE_IN_CALL || audioMode == AudioManager.MODE_IN_COMMUNICATION) {
|
|
225
|
+
Log.d(TAG, "Microphone in use: device is in call mode (" + audioMode + ")");
|
|
226
|
+
return true;
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
// On Android 7.0+, check for active recording configurations from other apps
|
|
230
|
+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
|
|
231
|
+
List<AudioRecordingConfiguration> activeConfigs = audioManager.getActiveRecordingConfigurations();
|
|
232
|
+
if (activeConfigs != null && !activeConfigs.isEmpty()) {
|
|
233
|
+
Log.d(TAG, "Microphone in use: " + activeConfigs.size() + " active recording configuration(s) found");
|
|
234
|
+
return true;
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
return false;
|
|
239
|
+
}
|
|
240
|
+
|
|
218
241
|
public StartRecordResult startRecord(String path) throws Exception {
|
|
242
|
+
// Check if microphone is already in use by another app
|
|
243
|
+
if (isMicrophoneInUse()) {
|
|
244
|
+
throw new Exception("Microphone is currently in use by another application");
|
|
245
|
+
}
|
|
219
246
|
// Use files directory (matches Capacitor's Directory.Data)
|
|
220
247
|
File dataDir = context.getFilesDir();
|
|
221
248
|
|