@scr2em/capacitor-plugin-recorder 0.0.2 → 0.0.4

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.
@@ -36,9 +36,11 @@ private class PlayerState: NSObject, AVAudioPlayerDelegate {
36
36
 
37
37
  func startTimer() {
38
38
  stopTimer()
39
- playbackTimer = Timer.scheduledTimer(withTimeInterval: 0.25, repeats: true) { [weak self] _ in
39
+ let timer = Timer(timeInterval: 0.25, repeats: true) { [weak self] _ in
40
40
  self?.notifyStatusChange()
41
41
  }
42
+ RunLoop.main.add(timer, forMode: .common)
43
+ playbackTimer = timer
42
44
  }
43
45
 
44
46
  func stopTimer() {
@@ -70,6 +72,12 @@ private class PlayerState: NSObject, AVAudioPlayerDelegate {
70
72
  }
71
73
  }
72
74
 
75
+ // Result struct for preparePlay
76
+ public struct PreparePlayResult {
77
+ public let playerId: String
78
+ public let duration: Int
79
+ }
80
+
73
81
  @objc public class RecorderPlayer: NSObject {
74
82
  private var audioRecorder: AVAudioRecorder?
75
83
  private var recordingSession: AVAudioSession?
@@ -111,11 +119,8 @@ private class PlayerState: NSObject, AVAudioPlayerDelegate {
111
119
  throw NSError(domain: "RecorderPlayer", code: 1, userInfo: [NSLocalizedDescriptionKey: "Recording already in progress"])
112
120
  }
113
121
 
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)
122
+ // Use Documents directory (matches Capacitor's Directory.Data on iOS)
123
+ let dataDir = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask)[0]
119
124
 
120
125
  let audioPath: URL
121
126
  if let path = path {
@@ -188,10 +193,9 @@ private class PlayerState: NSObject, AVAudioPlayerDelegate {
188
193
  notifyRecordingStatusChange()
189
194
  }
190
195
 
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 ?? "")
196
+ public func preparePlay(path: String) throws -> PreparePlayResult {
197
+ // Use Documents directory (matches Capacitor's Directory.Data on iOS)
198
+ let dataDir = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask)[0]
195
199
  let url = dataDir.appendingPathComponent(path)
196
200
 
197
201
  guard FileManager.default.fileExists(atPath: url.path) else {
@@ -210,7 +214,7 @@ private class PlayerState: NSObject, AVAudioPlayerDelegate {
210
214
  let duration = Int(audioPlayer.duration * 1000)
211
215
  playerState.notifyStatusChange()
212
216
 
213
- return (playerId, duration)
217
+ return PreparePlayResult(playerId: playerId, duration: duration)
214
218
  } catch {
215
219
  throw NSError(domain: "RecorderPlayer", code: 7, userInfo: [NSLocalizedDescriptionKey: "Failed to load audio: \(error.localizedDescription)"])
216
220
  }
@@ -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.4",
4
4
  "description": "record audios and play them back",
5
5
  "main": "dist/plugin.cjs.js",
6
6
  "module": "dist/esm/index.js",