@capgo/native-audio 8.2.12 → 8.2.14
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.
- package/README.md +147 -34
- package/android/build.gradle +1 -1
- package/android/src/main/java/ee/forgr/audio/AudioAsset.java +352 -74
- package/android/src/main/java/ee/forgr/audio/AudioDispatcher.java +24 -3
- package/android/src/main/java/ee/forgr/audio/Constant.java +9 -1
- package/android/src/main/java/ee/forgr/audio/Logger.java +55 -0
- package/android/src/main/java/ee/forgr/audio/NativeAudio.java +336 -57
- package/android/src/main/java/ee/forgr/audio/RemoteAudioAsset.java +307 -98
- package/android/src/main/java/ee/forgr/audio/StreamAudioAsset.java +285 -96
- package/dist/docs.json +307 -41
- package/dist/esm/definitions.d.ts +116 -38
- package/dist/esm/definitions.js.map +1 -1
- package/dist/esm/web.d.ts +52 -41
- package/dist/esm/web.js +386 -41
- package/dist/esm/web.js.map +1 -1
- package/dist/plugin.cjs.js +386 -41
- package/dist/plugin.cjs.js.map +1 -1
- package/dist/plugin.js +386 -41
- package/dist/plugin.js.map +1 -1
- package/ios/Sources/NativeAudioPlugin/AudioAsset+Fade.swift +104 -0
- package/ios/Sources/NativeAudioPlugin/AudioAsset.swift +168 -324
- package/ios/Sources/NativeAudioPlugin/Constant.swift +17 -4
- package/ios/Sources/NativeAudioPlugin/Logger.swift +43 -0
- package/ios/Sources/NativeAudioPlugin/Plugin.swift +176 -87
- package/ios/Sources/NativeAudioPlugin/RemoteAudioAsset+Fade.swift +110 -0
- package/ios/Sources/NativeAudioPlugin/RemoteAudioAsset.swift +117 -273
- package/ios/Tests/NativeAudioPluginTests/PluginTests.swift +47 -72
- package/package.json +1 -1
|
@@ -3,16 +3,18 @@ import Capacitor
|
|
|
3
3
|
import AVFoundation
|
|
4
4
|
@testable import NativeAudioPlugin
|
|
5
5
|
|
|
6
|
+
// swiftlint:disable file_length
|
|
6
7
|
class PluginTests: XCTestCase {
|
|
7
8
|
|
|
8
|
-
var plugin
|
|
9
|
-
var tempFileURL:
|
|
9
|
+
var plugin = NativeAudio()
|
|
10
|
+
var tempFileURL = URL(fileURLWithPath: NSTemporaryDirectory().appending("testAudio.wav"))
|
|
10
11
|
var testAssetId = "testAssetId"
|
|
11
12
|
var testRemoteAssetId = "testRemoteAssetId"
|
|
12
13
|
|
|
13
14
|
override func setUp() {
|
|
14
15
|
super.setUp()
|
|
15
16
|
plugin = NativeAudio()
|
|
17
|
+
plugin.isRunningTests = true
|
|
16
18
|
|
|
17
19
|
// Create a temporary audio file for testing
|
|
18
20
|
let audioFilePath = NSTemporaryDirectory().appending("testAudio.wav")
|
|
@@ -51,6 +53,18 @@ class PluginTests: XCTestCase {
|
|
|
51
53
|
FileManager.default.createFile(atPath: path, contents: Data(), attributes: nil)
|
|
52
54
|
}
|
|
53
55
|
|
|
56
|
+
private func makeCall(callbackId: String, options: [String: Any], onErrorMessage: String) -> CAPPluginCall {
|
|
57
|
+
guard let call = CAPPluginCall(callbackId: callbackId, options: options, success: { _, _ in }, error: { _ in }) else {
|
|
58
|
+
XCTFail("Failed to create CAPPluginCall: \(onErrorMessage)")
|
|
59
|
+
fatalError("Failed to create CAPPluginCall")
|
|
60
|
+
}
|
|
61
|
+
return call
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
extension PluginTests {
|
|
67
|
+
|
|
54
68
|
func testAudioAssetInitialization() {
|
|
55
69
|
let expectation = XCTestExpectation(description: "Initialize AudioAsset")
|
|
56
70
|
|
|
@@ -61,8 +75,7 @@ class PluginTests: XCTestCase {
|
|
|
61
75
|
withAssetId: self.testAssetId,
|
|
62
76
|
withPath: self.tempFileURL.path,
|
|
63
77
|
withChannels: 1,
|
|
64
|
-
withVolume: 0.5
|
|
65
|
-
withFadeDelay: 0.5
|
|
78
|
+
withVolume: 0.5
|
|
66
79
|
)
|
|
67
80
|
|
|
68
81
|
// Add it to the plugin's audio list
|
|
@@ -71,7 +84,6 @@ class PluginTests: XCTestCase {
|
|
|
71
84
|
// Verify initial values
|
|
72
85
|
XCTAssertEqual(asset.assetId, self.testAssetId)
|
|
73
86
|
XCTAssertEqual(asset.initialVolume, 0.5)
|
|
74
|
-
XCTAssertEqual(asset.fadeDelay, 0.5)
|
|
75
87
|
|
|
76
88
|
expectation.fulfill()
|
|
77
89
|
}
|
|
@@ -89,8 +101,7 @@ class PluginTests: XCTestCase {
|
|
|
89
101
|
withAssetId: self.testAssetId,
|
|
90
102
|
withPath: self.tempFileURL.path,
|
|
91
103
|
withChannels: 1,
|
|
92
|
-
withVolume: 1.0
|
|
93
|
-
withFadeDelay: 0.5
|
|
104
|
+
withVolume: 1.0
|
|
94
105
|
)
|
|
95
106
|
|
|
96
107
|
// Add it to the plugin's audio list
|
|
@@ -98,7 +109,7 @@ class PluginTests: XCTestCase {
|
|
|
98
109
|
|
|
99
110
|
// Test setting volume
|
|
100
111
|
let testVolume: Float = 0.7
|
|
101
|
-
asset.setVolume(volume: NSNumber(value: testVolume))
|
|
112
|
+
asset.setVolume(volume: NSNumber(value: testVolume), fadeDuration: 0)
|
|
102
113
|
|
|
103
114
|
// We can't directly check player.volume as it may take time to set
|
|
104
115
|
// So we'll just verify the method doesn't crash
|
|
@@ -123,7 +134,6 @@ class PluginTests: XCTestCase {
|
|
|
123
134
|
withPath: testURL,
|
|
124
135
|
withChannels: 1,
|
|
125
136
|
withVolume: 0.6,
|
|
126
|
-
withFadeDelay: 0.3,
|
|
127
137
|
withHeaders: nil
|
|
128
138
|
)
|
|
129
139
|
|
|
@@ -133,7 +143,6 @@ class PluginTests: XCTestCase {
|
|
|
133
143
|
// Verify initial values
|
|
134
144
|
XCTAssertEqual(asset.assetId, self.testRemoteAssetId)
|
|
135
145
|
XCTAssertEqual(asset.initialVolume, 0.6)
|
|
136
|
-
XCTAssertEqual(asset.fadeDelay, 0.3)
|
|
137
146
|
XCTAssertNotNil(asset.asset, "AVURLAsset should be created")
|
|
138
147
|
|
|
139
148
|
expectation.fulfill()
|
|
@@ -144,16 +153,12 @@ class PluginTests: XCTestCase {
|
|
|
144
153
|
|
|
145
154
|
func testPluginPreloadMethod() {
|
|
146
155
|
// Create a plugin call to test the preload method
|
|
147
|
-
let call =
|
|
156
|
+
let call = makeCall(callbackId: "test", options: [
|
|
148
157
|
"assetId": testAssetId,
|
|
149
158
|
"assetPath": tempFileURL.path,
|
|
150
159
|
"volume": 0.8,
|
|
151
160
|
"audioChannelNum": 2
|
|
152
|
-
],
|
|
153
|
-
// Success case
|
|
154
|
-
}, error: { (_) in
|
|
155
|
-
XCTFail("Preload shouldn't fail")
|
|
156
|
-
})!
|
|
161
|
+
], onErrorMessage: "Preload call creation")
|
|
157
162
|
|
|
158
163
|
// Call the plugin method
|
|
159
164
|
plugin.preload(call)
|
|
@@ -180,8 +185,7 @@ class PluginTests: XCTestCase {
|
|
|
180
185
|
withAssetId: self.testAssetId,
|
|
181
186
|
withPath: self.tempFileURL.path,
|
|
182
187
|
withChannels: 1,
|
|
183
|
-
withVolume: 1.0
|
|
184
|
-
withFadeDelay: 0.2
|
|
188
|
+
withVolume: 1.0
|
|
185
189
|
)
|
|
186
190
|
|
|
187
191
|
// Test fade functionality (just make sure it doesn't crash)
|
|
@@ -227,7 +231,6 @@ class PluginTests: XCTestCase {
|
|
|
227
231
|
withPath: testURL,
|
|
228
232
|
withChannels: 1,
|
|
229
233
|
withVolume: 0.6,
|
|
230
|
-
withFadeDelay: 0.3,
|
|
231
234
|
withHeaders: nil
|
|
232
235
|
)
|
|
233
236
|
|
|
@@ -264,8 +267,7 @@ class PluginTests: XCTestCase {
|
|
|
264
267
|
withAssetId: self.testAssetId,
|
|
265
268
|
withPath: self.tempFileURL.path,
|
|
266
269
|
withChannels: 1,
|
|
267
|
-
withVolume: 1.0
|
|
268
|
-
withFadeDelay: 0.5
|
|
270
|
+
withVolume: 1.0
|
|
269
271
|
)
|
|
270
272
|
|
|
271
273
|
// Ensure the fade timer is nil initially
|
|
@@ -315,17 +317,13 @@ class PluginTests: XCTestCase {
|
|
|
315
317
|
let expectation = XCTestExpectation(description: "PlayOnce with auto-play")
|
|
316
318
|
var returnedAssetId: String?
|
|
317
319
|
|
|
318
|
-
let call =
|
|
320
|
+
let call = makeCall(callbackId: "test", options: [
|
|
319
321
|
"assetPath": tempFileURL.path,
|
|
320
322
|
"volume": 1.0,
|
|
321
323
|
"isUrl": true,
|
|
322
324
|
"autoPlay": true
|
|
323
|
-
],
|
|
324
|
-
|
|
325
|
-
returnedAssetId = result?.data?["assetId"] as? String
|
|
326
|
-
}, error: { (_) in
|
|
327
|
-
XCTFail("PlayOnce shouldn't fail")
|
|
328
|
-
})!
|
|
325
|
+
], onErrorMessage: "playOnce auto-play call")
|
|
326
|
+
_ = returnedAssetId
|
|
329
327
|
|
|
330
328
|
plugin.playOnce(call)
|
|
331
329
|
|
|
@@ -357,16 +355,12 @@ class PluginTests: XCTestCase {
|
|
|
357
355
|
func testPlayOnceWithoutAutoPlay() {
|
|
358
356
|
let expectation = XCTestExpectation(description: "PlayOnce without auto-play")
|
|
359
357
|
|
|
360
|
-
let call =
|
|
358
|
+
let call = makeCall(callbackId: "test", options: [
|
|
361
359
|
"assetPath": tempFileURL.path,
|
|
362
360
|
"volume": 0.8,
|
|
363
361
|
"isUrl": true,
|
|
364
362
|
"autoPlay": false
|
|
365
|
-
],
|
|
366
|
-
// Success case
|
|
367
|
-
}, error: { (_) in
|
|
368
|
-
XCTFail("PlayOnce shouldn't fail")
|
|
369
|
-
})!
|
|
363
|
+
], onErrorMessage: "playOnce no-autoplay call")
|
|
370
364
|
|
|
371
365
|
plugin.playOnce(call)
|
|
372
366
|
|
|
@@ -401,16 +395,12 @@ class PluginTests: XCTestCase {
|
|
|
401
395
|
func testPlayOnceCleanupAfterCompletion() {
|
|
402
396
|
let expectation = XCTestExpectation(description: "PlayOnce cleanup after completion")
|
|
403
397
|
|
|
404
|
-
let call =
|
|
398
|
+
let call = makeCall(callbackId: "test", options: [
|
|
405
399
|
"assetPath": tempFileURL.path,
|
|
406
400
|
"volume": 1.0,
|
|
407
401
|
"isUrl": true,
|
|
408
402
|
"autoPlay": true
|
|
409
|
-
],
|
|
410
|
-
// Success case
|
|
411
|
-
}, error: { (_) in
|
|
412
|
-
XCTFail("PlayOnce shouldn't fail")
|
|
413
|
-
})!
|
|
403
|
+
], onErrorMessage: "playOnce cleanup call")
|
|
414
404
|
|
|
415
405
|
plugin.playOnce(call)
|
|
416
406
|
|
|
@@ -470,17 +460,13 @@ class PluginTests: XCTestCase {
|
|
|
470
460
|
return
|
|
471
461
|
}
|
|
472
462
|
|
|
473
|
-
let call =
|
|
463
|
+
let call = makeCall(callbackId: "test", options: [
|
|
474
464
|
"assetPath": deletableURL.absoluteString,
|
|
475
465
|
"volume": 1.0,
|
|
476
466
|
"isUrl": true,
|
|
477
467
|
"autoPlay": true,
|
|
478
468
|
"deleteAfterPlay": true
|
|
479
|
-
],
|
|
480
|
-
// Success case
|
|
481
|
-
}, error: { (_) in
|
|
482
|
-
XCTFail("PlayOnce shouldn't fail")
|
|
483
|
-
})!
|
|
469
|
+
], onErrorMessage: "playOnce delete-after-play call")
|
|
484
470
|
|
|
485
471
|
plugin.playOnce(call)
|
|
486
472
|
|
|
@@ -518,10 +504,14 @@ class PluginTests: XCTestCase {
|
|
|
518
504
|
wait(for: [expectation], timeout: 5.0)
|
|
519
505
|
}
|
|
520
506
|
|
|
507
|
+
}
|
|
508
|
+
|
|
509
|
+
extension PluginTests {
|
|
510
|
+
|
|
521
511
|
func testPlayOnceWithNotificationMetadata() {
|
|
522
512
|
let expectation = XCTestExpectation(description: "PlayOnce with notification metadata")
|
|
523
513
|
|
|
524
|
-
let call =
|
|
514
|
+
let call = makeCall(callbackId: "test", options: [
|
|
525
515
|
"assetPath": tempFileURL.path,
|
|
526
516
|
"volume": 1.0,
|
|
527
517
|
"isUrl": true,
|
|
@@ -532,11 +522,7 @@ class PluginTests: XCTestCase {
|
|
|
532
522
|
"album": "Test Album",
|
|
533
523
|
"artworkUrl": "https://example.com/artwork.jpg"
|
|
534
524
|
]
|
|
535
|
-
],
|
|
536
|
-
// Success case
|
|
537
|
-
}, error: { (_) in
|
|
538
|
-
XCTFail("PlayOnce shouldn't fail")
|
|
539
|
-
})!
|
|
525
|
+
], onErrorMessage: "playOnce metadata call")
|
|
540
526
|
|
|
541
527
|
plugin.playOnce(call)
|
|
542
528
|
|
|
@@ -573,16 +559,12 @@ class PluginTests: XCTestCase {
|
|
|
573
559
|
let expectation = XCTestExpectation(description: "PlayOnce error handling and cleanup")
|
|
574
560
|
|
|
575
561
|
// Use an invalid file path to trigger error
|
|
576
|
-
let call =
|
|
562
|
+
let call = makeCall(callbackId: "test", options: [
|
|
577
563
|
"assetPath": "/invalid/path/to/nonexistent.wav",
|
|
578
564
|
"volume": 1.0,
|
|
579
565
|
"isUrl": true,
|
|
580
566
|
"autoPlay": true
|
|
581
|
-
],
|
|
582
|
-
XCTFail("Should not succeed with invalid path")
|
|
583
|
-
}, error: { (_) in
|
|
584
|
-
// Expected error case
|
|
585
|
-
})!
|
|
567
|
+
], onErrorMessage: "playOnce error handling call")
|
|
586
568
|
|
|
587
569
|
plugin.playOnce(call)
|
|
588
570
|
|
|
@@ -616,32 +598,24 @@ class PluginTests: XCTestCase {
|
|
|
616
598
|
var firstAssetId: String?
|
|
617
599
|
var secondAssetId: String?
|
|
618
600
|
|
|
619
|
-
let call1 =
|
|
601
|
+
let call1 = makeCall(callbackId: "test1", options: [
|
|
620
602
|
"assetPath": tempFileURL.path,
|
|
621
603
|
"volume": 1.0,
|
|
622
604
|
"isUrl": true,
|
|
623
605
|
"autoPlay": false
|
|
624
|
-
],
|
|
625
|
-
|
|
626
|
-
firstAssetId = result?.data?["assetId"] as? String
|
|
627
|
-
}, error: { (_) in
|
|
628
|
-
XCTFail("PlayOnce shouldn't fail")
|
|
629
|
-
})!
|
|
606
|
+
], onErrorMessage: "playOnce unique call1")
|
|
607
|
+
_ = firstAssetId
|
|
630
608
|
|
|
631
609
|
plugin.playOnce(call1)
|
|
632
610
|
|
|
633
611
|
// Create second playOnce
|
|
634
|
-
let call2 =
|
|
612
|
+
let call2 = makeCall(callbackId: "test2", options: [
|
|
635
613
|
"assetPath": tempFileURL.path,
|
|
636
614
|
"volume": 1.0,
|
|
637
615
|
"isUrl": true,
|
|
638
616
|
"autoPlay": false
|
|
639
|
-
],
|
|
640
|
-
|
|
641
|
-
secondAssetId = result?.data?["assetId"] as? String
|
|
642
|
-
}, error: { (_) in
|
|
643
|
-
XCTFail("PlayOnce shouldn't fail")
|
|
644
|
-
})!
|
|
617
|
+
], onErrorMessage: "playOnce unique call2")
|
|
618
|
+
_ = secondAssetId
|
|
645
619
|
|
|
646
620
|
plugin.playOnce(call2)
|
|
647
621
|
|
|
@@ -671,3 +645,4 @@ class PluginTests: XCTestCase {
|
|
|
671
645
|
wait(for: [expectation], timeout: 5.0)
|
|
672
646
|
}
|
|
673
647
|
}
|
|
648
|
+
// swiftlint:enable file_length
|