@scr2em/capacitor-plugin-recorder 0.0.1 → 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.
|
@@ -3,7 +3,7 @@ require 'json'
|
|
|
3
3
|
package = JSON.parse(File.read(File.join(__dir__, 'package.json')))
|
|
4
4
|
|
|
5
5
|
Pod::Spec.new do |s|
|
|
6
|
-
s.name = '
|
|
6
|
+
s.name = 'Scr2emCapacitorPluginRecorder'
|
|
7
7
|
s.version = package['version']
|
|
8
8
|
s.summary = package['description']
|
|
9
9
|
s.license = package['license']
|
|
@@ -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
|
|
115
|
-
let
|
|
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 {
|
|
@@ -150,7 +153,7 @@ private class PlayerState: NSObject, AVAudioPlayerDelegate {
|
|
|
150
153
|
}
|
|
151
154
|
}
|
|
152
155
|
|
|
153
|
-
|
|
156
|
+
public func stopRecord() throws -> (path: String, duration: Int) {
|
|
154
157
|
guard let recorder = audioRecorder, recordingStatus != .stopped else {
|
|
155
158
|
throw NSError(domain: "RecorderPlayer", code: 3, userInfo: [NSLocalizedDescriptionKey: "No recording in progress"])
|
|
156
159
|
}
|
|
@@ -188,10 +191,9 @@ private class PlayerState: NSObject, AVAudioPlayerDelegate {
|
|
|
188
191
|
notifyRecordingStatusChange()
|
|
189
192
|
}
|
|
190
193
|
|
|
191
|
-
|
|
192
|
-
// Use
|
|
193
|
-
let
|
|
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
|
}
|
|
@@ -283,7 +285,7 @@ private class PlayerState: NSObject, AVAudioPlayerDelegate {
|
|
|
283
285
|
playerState.notifyStatusChange()
|
|
284
286
|
}
|
|
285
287
|
|
|
286
|
-
|
|
288
|
+
public func getPlaybackStatus(playerId: String) -> (status: String, currentPosition: Int, duration: Int)? {
|
|
287
289
|
guard let playerState = players[playerId] else {
|
|
288
290
|
return nil
|
|
289
291
|
}
|
|
@@ -293,7 +295,7 @@ private class PlayerState: NSObject, AVAudioPlayerDelegate {
|
|
|
293
295
|
return (playerState.status.rawValue, currentPosition, duration)
|
|
294
296
|
}
|
|
295
297
|
|
|
296
|
-
|
|
298
|
+
public func getRecordingStatus() -> (status: String, duration: Int) {
|
|
297
299
|
var duration = 0
|
|
298
300
|
if let recorder = audioRecorder {
|
|
299
301
|
duration = Int(recorder.currentTime * 1000)
|
|
@@ -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,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@scr2em/capacitor-plugin-recorder",
|
|
3
|
-
"version": "0.0.
|
|
4
|
-
"description": "
|
|
3
|
+
"version": "0.0.3",
|
|
4
|
+
"description": "record audios and play them back",
|
|
5
5
|
"main": "dist/plugin.cjs.js",
|
|
6
6
|
"module": "dist/esm/index.js",
|
|
7
7
|
"types": "dist/esm/index.d.ts",
|
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
"ios/Sources",
|
|
14
14
|
"ios/Tests",
|
|
15
15
|
"Package.swift",
|
|
16
|
-
"
|
|
16
|
+
"Scr2emCapacitorPluginRecorder.podspec"
|
|
17
17
|
],
|
|
18
18
|
"author": "me",
|
|
19
19
|
"license": "MIT",
|