capacitor-voice-recorder-wav-stereo 7.0.5 → 7.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.
@@ -106,31 +106,52 @@ public class VoiceRecorder: CAPPlugin {
106
106
  let audioSession = AVAudioSession.sharedInstance()
107
107
  var devices = [[String: Any]]()
108
108
 
109
- // 入力デバイス(マイクなど)
110
- let inputs = audioSession.currentRoute.inputs
111
- for port in inputs {
112
- devices.append([
113
- "deviceId": port.uid,
114
- "kind": "audioinput", // MediaDeviceKind.audioinput
115
- "label": port.portName,
116
- "groupId": NSNull()
117
- ])
118
- }
109
+ // 現在の設定を保持
110
+ let originalCategory = audioSession.category
111
+ let originalMode = audioSession.mode
112
+ var didActivate = false
119
113
 
120
- // 出力デバイス(スピーカーなど)
121
- let outputs = audioSession.currentRoute.outputs
122
- for port in outputs {
123
- devices.append([
124
- "deviceId": port.uid,
125
- "kind": "audiooutput", // MediaDeviceKind.audiooutput
126
- "label": port.portName,
127
- "groupId": NSNull()
128
- ])
114
+ do {
115
+ // セッションをアクティブ化せずにデバイス情報を取得
116
+ if !audioSession.isOtherAudioPlaying {
117
+ try audioSession.setActive(false)
118
+ didActivate = true
119
+ }
120
+
121
+ // 入力デバイス(マイクなど)
122
+ let availableInputs = audioSession.availableInputs ?? []
123
+ for port in availableInputs {
124
+ devices.append([
125
+ "deviceId": port.uid,
126
+ "kind": "audioinput",
127
+ "label": port.portName,
128
+ "groupId": NSNull()
129
+ ])
130
+ }
131
+
132
+ // 出力デバイス(現在のルートから取得)
133
+ let currentOutputs = audioSession.currentRoute.outputs
134
+ for port in currentOutputs {
135
+ devices.append([
136
+ "deviceId": port.uid,
137
+ "kind": "audiooutput",
138
+ "label": port.portName,
139
+ "groupId": NSNull()
140
+ ])
141
+ }
142
+
143
+ // 元の設定に戻す
144
+ if didActivate {
145
+ try audioSession.setCategory(originalCategory, mode: originalMode)
146
+ try audioSession.setActive(true)
147
+ }
148
+
149
+ } catch {
150
+ call.reject("Failed to get audio devices: \(error.localizedDescription)")
151
+ return
129
152
  }
130
153
 
131
- call.resolve([
132
- "devices": devices
133
- ])
154
+ call.resolve(["devices": devices])
134
155
  }
135
156
 
136
157
  func doesUserGaveAudioRecordingPermission() -> Bool {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "capacitor-voice-recorder-wav-stereo",
3
- "version": "7.0.5",
3
+ "version": "7.0.6",
4
4
  "description": "Capacitor plugin for voice recording in wav format",
5
5
  "main": "dist/plugin.cjs.js",
6
6
  "module": "dist/esm/index.js",