@scr2em/capacitor-plugin-recorder 0.0.2 → 0.0.3

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.
@@ -70,6 +70,12 @@ private class PlayerState: NSObject, AVAudioPlayerDelegate {
70
70
  }
71
71
  }
72
72
 
73
+ // Result struct for preparePlay
74
+ public struct PreparePlayResult {
75
+ public let playerId: String
76
+ public let duration: Int
77
+ }
78
+
73
79
  @objc public class RecorderPlayer: NSObject {
74
80
  private var audioRecorder: AVAudioRecorder?
75
81
  private var recordingSession: AVAudioSession?
@@ -111,11 +117,8 @@ private class PlayerState: NSObject, AVAudioPlayerDelegate {
111
117
  throw NSError(domain: "RecorderPlayer", code: 1, userInfo: [NSLocalizedDescriptionKey: "Recording already in progress"])
112
118
  }
113
119
 
114
- // Use Application Support directory + bundle identifier (matches Capacitor's Directory.Data)
115
- let appSupportDir = FileManager.default.urls(for: .applicationSupportDirectory, in: .userDomainMask)[0]
116
- let dataDir = appSupportDir.appendingPathComponent(Bundle.main.bundleIdentifier ?? "")
117
- // Create directory if it doesn't exist
118
- try? FileManager.default.createDirectory(at: dataDir, withIntermediateDirectories: true)
120
+ // Use Documents directory (matches Capacitor's Directory.Data on iOS)
121
+ let dataDir = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask)[0]
119
122
 
120
123
  let audioPath: URL
121
124
  if let path = path {
@@ -188,10 +191,9 @@ private class PlayerState: NSObject, AVAudioPlayerDelegate {
188
191
  notifyRecordingStatusChange()
189
192
  }
190
193
 
191
- public func preparePlay(path: String) throws -> (playerId: String, duration: Int) {
192
- // Use Application Support directory + bundle identifier (matches Capacitor's Directory.Data)
193
- let appSupportDir = FileManager.default.urls(for: .applicationSupportDirectory, in: .userDomainMask)[0]
194
- let dataDir = appSupportDir.appendingPathComponent(Bundle.main.bundleIdentifier ?? "")
194
+ public func preparePlay(path: String) throws -> PreparePlayResult {
195
+ // Use Documents directory (matches Capacitor's Directory.Data on iOS)
196
+ let dataDir = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask)[0]
195
197
  let url = dataDir.appendingPathComponent(path)
196
198
 
197
199
  guard FileManager.default.fileExists(atPath: url.path) else {
@@ -210,7 +212,7 @@ private class PlayerState: NSObject, AVAudioPlayerDelegate {
210
212
  let duration = Int(audioPlayer.duration * 1000)
211
213
  playerState.notifyStatusChange()
212
214
 
213
- return (playerId, duration)
215
+ return PreparePlayResult(playerId: playerId, duration: duration)
214
216
  } catch {
215
217
  throw NSError(domain: "RecorderPlayer", code: 7, userInfo: [NSLocalizedDescriptionKey: "Failed to load audio: \(error.localizedDescription)"])
216
218
  }
@@ -112,8 +112,8 @@ public class RecorderPlayerPlugin: CAPPlugin, CAPBridgedPlugin, RecorderPlayerDe
112
112
  "playerId": result.playerId,
113
113
  "duration": result.duration
114
114
  ])
115
- } catch {
116
- call.reject(error.localizedDescription)
115
+ } catch let error as NSError {
116
+ call.reject(error.localizedDescription, nil, error)
117
117
  }
118
118
  }
119
119
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@scr2em/capacitor-plugin-recorder",
3
- "version": "0.0.2",
3
+ "version": "0.0.3",
4
4
  "description": "record audios and play them back",
5
5
  "main": "dist/plugin.cjs.js",
6
6
  "module": "dist/esm/index.js",