@capgo/native-audio 6.0.20 → 6.1.0
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 +22 -12
- package/dist/docs.json +9 -2
- package/dist/esm/definitions.d.ts +2 -0
- package/ios/Plugin/AudioAsset.swift +2 -2
- package/ios/Plugin/Constant.swift +2 -0
- package/ios/Plugin/Plugin.swift +73 -19
- package/package.json +1 -1
package/README.md
CHANGED
@@ -1,14 +1,23 @@
|
|
1
|
-
<a href="https://capgo.app/"
|
1
|
+
<a href="https://capgo.app/">
|
2
|
+
<img
|
3
|
+
src="https://raw.githubusercontent.com/Cap-go/capgo/main/assets/capgo_banner.png"
|
4
|
+
alt="Capgo - Instant updates for capacitor"
|
5
|
+
/>
|
6
|
+
</a>
|
2
7
|
|
3
8
|
<div align="center">
|
4
|
-
<h2
|
9
|
+
<h2>
|
10
|
+
<a href="https://capgo.app/">Check out: Capgo — Instant updates for capacitor</a>
|
11
|
+
</h2>
|
5
12
|
</div>
|
6
13
|
|
7
14
|
<h3 align="center">Native Audio</h3>
|
8
|
-
<p align="center"><strong><code>@capgo/native-audio</code></strong></p>
|
9
15
|
<p align="center">
|
10
|
-
|
16
|
+
<strong>
|
17
|
+
<code>@capgo/native-audio</code>
|
18
|
+
</strong>
|
11
19
|
</p>
|
20
|
+
<p align="center">Capacitor plugin for playing sounds.</p>
|
12
21
|
|
13
22
|
<p align="center">
|
14
23
|
<img src="https://img.shields.io/maintenance/yes/2023?style=flat-square" />
|
@@ -239,12 +248,12 @@ preload(options: PreloadOptions) => Promise<void>
|
|
239
248
|
### play(...)
|
240
249
|
|
241
250
|
```typescript
|
242
|
-
play(options: { assetId: string; time?: number; }) => Promise<void>
|
251
|
+
play(options: { assetId: string; time?: number; delay?: number; }) => Promise<void>
|
243
252
|
```
|
244
253
|
|
245
|
-
| Param | Type
|
246
|
-
| ------------- |
|
247
|
-
| **`options`** | <code>{ assetId: string; time?: number; }</code> |
|
254
|
+
| Param | Type |
|
255
|
+
| ------------- | ---------------------------------------------------------------- |
|
256
|
+
| **`options`** | <code>{ assetId: string; time?: number; delay?: number; }</code> |
|
248
257
|
|
249
258
|
--------------------
|
250
259
|
|
@@ -410,10 +419,11 @@ Listen for complete event
|
|
410
419
|
|
411
420
|
#### ConfigureOptions
|
412
421
|
|
413
|
-
| Prop
|
414
|
-
|
|
415
|
-
| **`fade`**
|
416
|
-
| **`focus`**
|
422
|
+
| Prop | Type |
|
423
|
+
| ---------------- | -------------------- |
|
424
|
+
| **`fade`** | <code>boolean</code> |
|
425
|
+
| **`focus`** | <code>boolean</code> |
|
426
|
+
| **`background`** | <code>boolean</code> |
|
417
427
|
|
418
428
|
|
419
429
|
#### PreloadOptions
|
package/dist/docs.json
CHANGED
@@ -43,12 +43,12 @@
|
|
43
43
|
},
|
44
44
|
{
|
45
45
|
"name": "play",
|
46
|
-
"signature": "(options: { assetId: string; time?: number; }) => Promise<void>",
|
46
|
+
"signature": "(options: { assetId: string; time?: number; delay?: number; }) => Promise<void>",
|
47
47
|
"parameters": [
|
48
48
|
{
|
49
49
|
"name": "options",
|
50
50
|
"docs": "",
|
51
|
-
"type": "{ assetId: string; time?: number | undefined; }"
|
51
|
+
"type": "{ assetId: string; time?: number | undefined; delay?: number | undefined; }"
|
52
52
|
}
|
53
53
|
],
|
54
54
|
"returns": "Promise<void>",
|
@@ -270,6 +270,13 @@
|
|
270
270
|
"docs": "",
|
271
271
|
"complexTypes": [],
|
272
272
|
"type": "boolean | undefined"
|
273
|
+
},
|
274
|
+
{
|
275
|
+
"name": "background",
|
276
|
+
"tags": [],
|
277
|
+
"docs": "",
|
278
|
+
"complexTypes": [],
|
279
|
+
"type": "boolean | undefined"
|
273
280
|
}
|
274
281
|
]
|
275
282
|
},
|
@@ -14,6 +14,7 @@ export interface NativeAudio {
|
|
14
14
|
play(options: {
|
15
15
|
assetId: string;
|
16
16
|
time?: number;
|
17
|
+
delay?: number;
|
17
18
|
}): Promise<void>;
|
18
19
|
pause(options: {
|
19
20
|
assetId: string;
|
@@ -63,6 +64,7 @@ export interface NativeAudio {
|
|
63
64
|
export interface ConfigureOptions {
|
64
65
|
fade?: boolean;
|
65
66
|
focus?: boolean;
|
67
|
+
background?: boolean;
|
66
68
|
}
|
67
69
|
export interface PreloadOptions {
|
68
70
|
assetPath: string;
|
@@ -68,14 +68,14 @@ public class AudioAsset: NSObject, AVAudioPlayerDelegate {
|
|
68
68
|
return player.duration
|
69
69
|
}
|
70
70
|
|
71
|
-
func play(time: TimeInterval) {
|
71
|
+
func play(time: TimeInterval, delay: TimeInterval) {
|
72
72
|
let player: AVAudioPlayer
|
73
73
|
|
74
74
|
if channels.count > 0 {
|
75
75
|
player = channels[playIndex]
|
76
76
|
player.currentTime = time
|
77
77
|
player.numberOfLoops = 0
|
78
|
-
player.play()
|
78
|
+
player.play(atTime: player.deviceCurrentTime + delay)
|
79
79
|
playIndex += 1
|
80
80
|
playIndex = playIndex % channels.count
|
81
81
|
}
|
@@ -14,6 +14,8 @@ public class Constant {
|
|
14
14
|
public static let Volume = "volume"
|
15
15
|
public static let Rate = "rate"
|
16
16
|
public static let Loop = "loop"
|
17
|
+
public static let Background = "background"
|
18
|
+
public static let IgnoreSilent = "ignoreSilent"
|
17
19
|
|
18
20
|
public static let ErrorAssetId = "Asset Id is missing"
|
19
21
|
public static let ErrorAssetPath = "Asset Path is missing"
|
package/ios/Plugin/Plugin.swift
CHANGED
@@ -1,16 +1,14 @@
|
|
1
1
|
import AVFoundation
|
2
|
-
import Foundation
|
3
2
|
import Capacitor
|
4
3
|
import CoreAudio
|
4
|
+
import Foundation
|
5
5
|
|
6
6
|
enum MyError: Error {
|
7
7
|
case runtimeError(String)
|
8
8
|
}
|
9
9
|
|
10
|
-
|
11
|
-
|
12
|
-
* here: https://capacitor.ionicframework.com/docs/plugins/ios
|
13
|
-
*/
|
10
|
+
/// Please read the Capacitor iOS Plugin Development Guide
|
11
|
+
/// here: https://capacitor.ionicframework.com/docs/plugins/ios
|
14
12
|
@objc(NativeAudio)
|
15
13
|
public class NativeAudio: CAPPlugin {
|
16
14
|
|
@@ -24,7 +22,7 @@ public class NativeAudio: CAPPlugin {
|
|
24
22
|
self.fadeMusic = false
|
25
23
|
|
26
24
|
do {
|
27
|
-
try self.session.setCategory(AVAudioSession.Category.playback)
|
25
|
+
try self.session.setCategory(AVAudioSession.Category.playback, options: .mixWithOthers)
|
28
26
|
try self.session.setActive(false)
|
29
27
|
} catch {
|
30
28
|
print("Failed to set session category")
|
@@ -35,15 +33,68 @@ public class NativeAudio: CAPPlugin {
|
|
35
33
|
if let fade = call.getBool(Constant.FadeKey) {
|
36
34
|
self.fadeMusic = fade
|
37
35
|
}
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
36
|
+
|
37
|
+
let focus = call.getBool(Constant.FocusAudio) ?? false
|
38
|
+
|
39
|
+
do {
|
40
|
+
|
41
|
+
if focus {
|
42
|
+
|
43
|
+
try self.session.setCategory(AVAudioSession.Category.playback)
|
44
|
+
|
45
|
+
}
|
46
|
+
|
47
|
+
} catch {
|
48
|
+
|
49
|
+
print("Failed to set setCategory audio")
|
50
|
+
|
51
|
+
}
|
52
|
+
|
53
|
+
let background = call.getBool(Constant.Background) ?? false
|
54
|
+
|
55
|
+
do {
|
56
|
+
|
57
|
+
if background {
|
58
|
+
|
59
|
+
try self.session.setActive(true)
|
60
|
+
|
61
|
+
}
|
62
|
+
|
63
|
+
} catch {
|
64
|
+
|
65
|
+
print("Failed to set setSession true")
|
66
|
+
|
67
|
+
}
|
68
|
+
|
69
|
+
let ignoreSilent = call.getBool(Constant.IgnoreSilent) ?? true
|
70
|
+
|
71
|
+
do {
|
72
|
+
|
73
|
+
if ignoreSilent == false {
|
74
|
+
|
75
|
+
if let focus = call.getBool(Constant.FocusAudio) {
|
76
|
+
|
77
|
+
do {
|
78
|
+
|
79
|
+
if focus {
|
80
|
+
|
81
|
+
try self.session.setCategory(AVAudioSession.Category.ambient)
|
82
|
+
|
83
|
+
} else {
|
84
|
+
|
85
|
+
try self.session.setCategory(
|
86
|
+
AVAudioSession.Category.ambient, options: .mixWithOthers)
|
87
|
+
|
88
|
+
}
|
89
|
+
|
90
|
+
} catch {
|
91
|
+
|
92
|
+
print("Failed to set setCategory audio")
|
93
|
+
|
94
|
+
}
|
95
|
+
|
44
96
|
}
|
45
|
-
|
46
|
-
print("Failed to set setCategory audio")
|
97
|
+
|
47
98
|
}
|
48
99
|
}
|
49
100
|
call.resolve()
|
@@ -56,6 +107,7 @@ public class NativeAudio: CAPPlugin {
|
|
56
107
|
@objc func play(_ call: CAPPluginCall) {
|
57
108
|
let audioId = call.getString(Constant.AssetIdKey) ?? ""
|
58
109
|
let time = call.getDouble("time") ?? 0
|
110
|
+
let delay = call.getDouble("delay") ?? 0
|
59
111
|
if audioId != "" {
|
60
112
|
let queue = DispatchQueue(label: "ee.forgr.audio.complex.queue", qos: .userInitiated)
|
61
113
|
|
@@ -70,12 +122,12 @@ public class NativeAudio: CAPPlugin {
|
|
70
122
|
if self.fadeMusic {
|
71
123
|
audioAsset?.playWithFade(time: time)
|
72
124
|
} else {
|
73
|
-
audioAsset?.play(time: time)
|
125
|
+
audioAsset?.play(time: time, delay: delay)
|
74
126
|
}
|
75
127
|
call.resolve()
|
76
128
|
} else if asset is Int32 {
|
77
129
|
let audioAsset = asset as? NSNumber ?? 0
|
78
|
-
AudioServicesPlaySystemSound(SystemSoundID(audioAsset.intValue
|
130
|
+
AudioServicesPlaySystemSound(SystemSoundID(audioAsset.intValue))
|
79
131
|
call.resolve()
|
80
132
|
} else {
|
81
133
|
call.reject(Constant.ErrorAssetNotFound)
|
@@ -164,7 +216,7 @@ public class NativeAudio: CAPPlugin {
|
|
164
216
|
if self.audioList.count > 0 {
|
165
217
|
let asset = self.audioList[audioId]
|
166
218
|
if asset != nil && asset is AudioAsset {
|
167
|
-
guard let audioAsset=asset as? AudioAsset else {
|
219
|
+
guard let audioAsset = asset as? AudioAsset else {
|
168
220
|
call.reject("Cannot cast to AudioAsset")
|
169
221
|
return
|
170
222
|
}
|
@@ -256,8 +308,10 @@ public class NativeAudio: CAPPlugin {
|
|
256
308
|
self.audioList[audioId] = NSNumber(value: Int32(soundId))
|
257
309
|
call.resolve()
|
258
310
|
} else {
|
259
|
-
let audioAsset: AudioAsset = AudioAsset(
|
260
|
-
|
311
|
+
let audioAsset: AudioAsset = AudioAsset(
|
312
|
+
owner: self,
|
313
|
+
withAssetId: audioId, withPath: basePath, withChannels: channels,
|
314
|
+
withVolume: volume, withFadeDelay: delay)
|
261
315
|
self.audioList[audioId] = audioAsset
|
262
316
|
call.resolve()
|
263
317
|
}
|