@capgo/native-audio 5.1.3 → 5.1.10
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 +16 -36
- package/android/src/main/java/ee/forgr/audio/AudioAsset.java +115 -107
- package/android/src/main/java/ee/forgr/audio/AudioDispatcher.java +185 -168
- package/android/src/main/java/ee/forgr/audio/Constant.java +14 -13
- package/android/src/main/java/ee/forgr/audio/NativeAudio.java +430 -405
- package/dist/docs.json +26 -26
- package/dist/esm/index.d.ts +2 -2
- package/dist/esm/index.js +4 -4
- package/dist/esm/web.d.ts +3 -3
- package/dist/esm/web.js +20 -19
- package/dist/esm/web.js.map +1 -1
- package/dist/plugin.cjs.js +19 -18
- package/dist/plugin.cjs.js.map +1 -1
- package/dist/plugin.js +19 -18
- package/dist/plugin.js.map +1 -1
- package/ios/Plugin/AudioAsset.swift +38 -45
- package/ios/Plugin/Constant.swift +1 -0
- package/ios/Plugin/Plugin.swift +15 -11
- package/package.json +14 -13
package/README.md
CHANGED
@@ -213,164 +213,144 @@ NativeAudio.isPlaying({
|
|
213
213
|
### configure(...)
|
214
214
|
|
215
215
|
```typescript
|
216
|
-
configure(options: ConfigureOptions) =>
|
216
|
+
configure(options: ConfigureOptions) => Promise<void>
|
217
217
|
```
|
218
218
|
|
219
219
|
| Param | Type |
|
220
220
|
| ------------- | ------------------------------------------------------------- |
|
221
221
|
| **`options`** | <code><a href="#configureoptions">ConfigureOptions</a></code> |
|
222
222
|
|
223
|
-
**Returns:** <code>any</code>
|
224
|
-
|
225
223
|
--------------------
|
226
224
|
|
227
225
|
|
228
226
|
### preload(...)
|
229
227
|
|
230
228
|
```typescript
|
231
|
-
preload(options: PreloadOptions) =>
|
229
|
+
preload(options: PreloadOptions) => Promise<void>
|
232
230
|
```
|
233
231
|
|
234
232
|
| Param | Type |
|
235
233
|
| ------------- | --------------------------------------------------------- |
|
236
234
|
| **`options`** | <code><a href="#preloadoptions">PreloadOptions</a></code> |
|
237
235
|
|
238
|
-
**Returns:** <code>any</code>
|
239
|
-
|
240
236
|
--------------------
|
241
237
|
|
242
238
|
|
243
239
|
### play(...)
|
244
240
|
|
245
241
|
```typescript
|
246
|
-
play(options: { assetId: string; time?: number; }) =>
|
242
|
+
play(options: { assetId: string; time?: number; }) => Promise<void>
|
247
243
|
```
|
248
244
|
|
249
245
|
| Param | Type |
|
250
246
|
| ------------- | ------------------------------------------------ |
|
251
247
|
| **`options`** | <code>{ assetId: string; time?: number; }</code> |
|
252
248
|
|
253
|
-
**Returns:** <code>any</code>
|
254
|
-
|
255
249
|
--------------------
|
256
250
|
|
257
251
|
|
258
252
|
### pause(...)
|
259
253
|
|
260
254
|
```typescript
|
261
|
-
pause(options: { assetId: string; }) =>
|
255
|
+
pause(options: { assetId: string; }) => Promise<void>
|
262
256
|
```
|
263
257
|
|
264
258
|
| Param | Type |
|
265
259
|
| ------------- | --------------------------------- |
|
266
260
|
| **`options`** | <code>{ assetId: string; }</code> |
|
267
261
|
|
268
|
-
**Returns:** <code>any</code>
|
269
|
-
|
270
262
|
--------------------
|
271
263
|
|
272
264
|
|
273
265
|
### resume(...)
|
274
266
|
|
275
267
|
```typescript
|
276
|
-
resume(options: { assetId: string; }) =>
|
268
|
+
resume(options: { assetId: string; }) => Promise<void>
|
277
269
|
```
|
278
270
|
|
279
271
|
| Param | Type |
|
280
272
|
| ------------- | --------------------------------- |
|
281
273
|
| **`options`** | <code>{ assetId: string; }</code> |
|
282
274
|
|
283
|
-
**Returns:** <code>any</code>
|
284
|
-
|
285
275
|
--------------------
|
286
276
|
|
287
277
|
|
288
278
|
### loop(...)
|
289
279
|
|
290
280
|
```typescript
|
291
|
-
loop(options: { assetId: string; }) =>
|
281
|
+
loop(options: { assetId: string; }) => Promise<void>
|
292
282
|
```
|
293
283
|
|
294
284
|
| Param | Type |
|
295
285
|
| ------------- | --------------------------------- |
|
296
286
|
| **`options`** | <code>{ assetId: string; }</code> |
|
297
287
|
|
298
|
-
**Returns:** <code>any</code>
|
299
|
-
|
300
288
|
--------------------
|
301
289
|
|
302
290
|
|
303
291
|
### stop(...)
|
304
292
|
|
305
293
|
```typescript
|
306
|
-
stop(options: { assetId: string; }) =>
|
294
|
+
stop(options: { assetId: string; }) => Promise<void>
|
307
295
|
```
|
308
296
|
|
309
297
|
| Param | Type |
|
310
298
|
| ------------- | --------------------------------- |
|
311
299
|
| **`options`** | <code>{ assetId: string; }</code> |
|
312
300
|
|
313
|
-
**Returns:** <code>any</code>
|
314
|
-
|
315
301
|
--------------------
|
316
302
|
|
317
303
|
|
318
304
|
### unload(...)
|
319
305
|
|
320
306
|
```typescript
|
321
|
-
unload(options: { assetId: string; }) =>
|
307
|
+
unload(options: { assetId: string; }) => Promise<void>
|
322
308
|
```
|
323
309
|
|
324
310
|
| Param | Type |
|
325
311
|
| ------------- | --------------------------------- |
|
326
312
|
| **`options`** | <code>{ assetId: string; }</code> |
|
327
313
|
|
328
|
-
**Returns:** <code>any</code>
|
329
|
-
|
330
314
|
--------------------
|
331
315
|
|
332
316
|
|
333
317
|
### setVolume(...)
|
334
318
|
|
335
319
|
```typescript
|
336
|
-
setVolume(options: { assetId: string; volume: number; }) =>
|
320
|
+
setVolume(options: { assetId: string; volume: number; }) => Promise<void>
|
337
321
|
```
|
338
322
|
|
339
323
|
| Param | Type |
|
340
324
|
| ------------- | ------------------------------------------------- |
|
341
325
|
| **`options`** | <code>{ assetId: string; volume: number; }</code> |
|
342
326
|
|
343
|
-
**Returns:** <code>any</code>
|
344
|
-
|
345
327
|
--------------------
|
346
328
|
|
347
329
|
|
348
330
|
### setRate(...)
|
349
331
|
|
350
332
|
```typescript
|
351
|
-
setRate(options: { assetId: string; rate: number; }) =>
|
333
|
+
setRate(options: { assetId: string; rate: number; }) => Promise<void>
|
352
334
|
```
|
353
335
|
|
354
336
|
| Param | Type |
|
355
337
|
| ------------- | ----------------------------------------------- |
|
356
338
|
| **`options`** | <code>{ assetId: string; rate: number; }</code> |
|
357
339
|
|
358
|
-
**Returns:** <code>any</code>
|
359
|
-
|
360
340
|
--------------------
|
361
341
|
|
362
342
|
|
363
343
|
### getCurrentTime(...)
|
364
344
|
|
365
345
|
```typescript
|
366
|
-
getCurrentTime(options: { assetId: string; }) =>
|
346
|
+
getCurrentTime(options: { assetId: string; }) => Promise<{ currentTime: number; }>
|
367
347
|
```
|
368
348
|
|
369
349
|
| Param | Type |
|
370
350
|
| ------------- | --------------------------------- |
|
371
351
|
| **`options`** | <code>{ assetId: string; }</code> |
|
372
352
|
|
373
|
-
**Returns:** <code>
|
353
|
+
**Returns:** <code>Promise<{ currentTime: number; }></code>
|
374
354
|
|
375
355
|
--------------------
|
376
356
|
|
@@ -378,14 +358,14 @@ getCurrentTime(options: { assetId: string; }) => any
|
|
378
358
|
### getDuration(...)
|
379
359
|
|
380
360
|
```typescript
|
381
|
-
getDuration(options: { assetId: string; }) =>
|
361
|
+
getDuration(options: { assetId: string; }) => Promise<{ duration: number; }>
|
382
362
|
```
|
383
363
|
|
384
364
|
| Param | Type |
|
385
365
|
| ------------- | --------------------------------- |
|
386
366
|
| **`options`** | <code>{ assetId: string; }</code> |
|
387
367
|
|
388
|
-
**Returns:** <code>
|
368
|
+
**Returns:** <code>Promise<{ duration: number; }></code>
|
389
369
|
|
390
370
|
--------------------
|
391
371
|
|
@@ -393,14 +373,14 @@ getDuration(options: { assetId: string; }) => any
|
|
393
373
|
### isPlaying(...)
|
394
374
|
|
395
375
|
```typescript
|
396
|
-
isPlaying(options: { assetId: string; }) =>
|
376
|
+
isPlaying(options: { assetId: string; }) => Promise<{ isPlaying: boolean; }>
|
397
377
|
```
|
398
378
|
|
399
379
|
| Param | Type |
|
400
380
|
| ------------- | --------------------------------- |
|
401
381
|
| **`options`** | <code>{ assetId: string; }</code> |
|
402
382
|
|
403
|
-
**Returns:** <code>
|
383
|
+
**Returns:** <code>Promise<{ isPlaying: boolean; }></code>
|
404
384
|
|
405
385
|
--------------------
|
406
386
|
|
@@ -7,146 +7,154 @@ import java.util.concurrent.Callable;
|
|
7
7
|
|
8
8
|
public class AudioAsset {
|
9
9
|
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
if (audioChannelNum == 1) audioDispatcher.setOwner(this);
|
31
|
-
}
|
10
|
+
private final String TAG = "AudioAsset";
|
11
|
+
|
12
|
+
private ArrayList<AudioDispatcher> audioList;
|
13
|
+
private int playIndex = 0;
|
14
|
+
private String assetId;
|
15
|
+
private NativeAudio owner;
|
16
|
+
|
17
|
+
AudioAsset(
|
18
|
+
NativeAudio owner,
|
19
|
+
String assetId,
|
20
|
+
AssetFileDescriptor assetFileDescriptor,
|
21
|
+
int audioChannelNum,
|
22
|
+
float volume
|
23
|
+
) throws Exception {
|
24
|
+
audioList = new ArrayList<>();
|
25
|
+
this.owner = owner;
|
26
|
+
this.assetId = assetId;
|
27
|
+
|
28
|
+
if (audioChannelNum < 0) {
|
29
|
+
audioChannelNum = 1;
|
32
30
|
}
|
33
31
|
|
34
|
-
|
35
|
-
|
32
|
+
for (int x = 0; x < audioChannelNum; x++) {
|
33
|
+
AudioDispatcher audioDispatcher = new AudioDispatcher(
|
34
|
+
assetFileDescriptor,
|
35
|
+
volume
|
36
|
+
);
|
37
|
+
audioList.add(audioDispatcher);
|
38
|
+
if (audioChannelNum == 1) audioDispatcher.setOwner(this);
|
36
39
|
}
|
40
|
+
}
|
37
41
|
|
38
|
-
|
39
|
-
|
42
|
+
public void dispatchComplete() {
|
43
|
+
this.owner.dispatchComplete(this.assetId);
|
44
|
+
}
|
40
45
|
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
46
|
+
public void play(Double time) throws Exception {
|
47
|
+
AudioDispatcher audio = audioList.get(playIndex);
|
48
|
+
|
49
|
+
if (audio != null) {
|
50
|
+
audio.play(time);
|
51
|
+
playIndex++;
|
52
|
+
playIndex = playIndex % audioList.size();
|
53
|
+
} else {
|
54
|
+
throw new Exception("AudioDispatcher is null");
|
48
55
|
}
|
56
|
+
}
|
49
57
|
|
50
|
-
|
51
|
-
|
58
|
+
public double getDuration() {
|
59
|
+
if (audioList.size() != 1) return 0;
|
52
60
|
|
53
|
-
|
61
|
+
AudioDispatcher audio = audioList.get(playIndex);
|
54
62
|
|
55
|
-
|
56
|
-
|
57
|
-
}
|
58
|
-
return 0;
|
63
|
+
if (audio != null) {
|
64
|
+
return audio.getDuration();
|
59
65
|
}
|
66
|
+
return 0;
|
67
|
+
}
|
60
68
|
|
61
|
-
|
62
|
-
|
69
|
+
public double getCurrentPosition() {
|
70
|
+
if (audioList.size() != 1) return 0;
|
63
71
|
|
64
|
-
|
72
|
+
AudioDispatcher audio = audioList.get(playIndex);
|
65
73
|
|
66
|
-
|
67
|
-
|
68
|
-
}
|
69
|
-
return 0;
|
74
|
+
if (audio != null) {
|
75
|
+
return audio.getCurrentPosition();
|
70
76
|
}
|
77
|
+
return 0;
|
78
|
+
}
|
71
79
|
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
for (int x = 0; x < audioList.size(); x++) {
|
76
|
-
AudioDispatcher audio = audioList.get(x);
|
77
|
-
wasPlaying |= audio.pause();
|
78
|
-
}
|
80
|
+
public boolean pause() throws Exception {
|
81
|
+
boolean wasPlaying = false;
|
79
82
|
|
80
|
-
|
83
|
+
for (int x = 0; x < audioList.size(); x++) {
|
84
|
+
AudioDispatcher audio = audioList.get(x);
|
85
|
+
wasPlaying |= audio.pause();
|
81
86
|
}
|
82
87
|
|
83
|
-
|
84
|
-
|
85
|
-
|
88
|
+
return wasPlaying;
|
89
|
+
}
|
90
|
+
|
91
|
+
public void resume() throws Exception {
|
92
|
+
if (audioList.size() > 0) {
|
93
|
+
AudioDispatcher audio = audioList.get(0);
|
86
94
|
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
}
|
95
|
+
if (audio != null) {
|
96
|
+
audio.resume();
|
97
|
+
} else {
|
98
|
+
throw new Exception("AudioDispatcher is null");
|
99
|
+
}
|
93
100
|
}
|
101
|
+
}
|
94
102
|
|
95
|
-
|
96
|
-
|
97
|
-
|
103
|
+
public void stop() throws Exception {
|
104
|
+
for (int x = 0; x < audioList.size(); x++) {
|
105
|
+
AudioDispatcher audio = audioList.get(x);
|
98
106
|
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
}
|
107
|
+
if (audio != null) {
|
108
|
+
audio.stop();
|
109
|
+
} else {
|
110
|
+
throw new Exception("AudioDispatcher is null");
|
111
|
+
}
|
105
112
|
}
|
113
|
+
}
|
106
114
|
|
107
|
-
|
108
|
-
|
115
|
+
public void loop() throws Exception {
|
116
|
+
AudioDispatcher audio = audioList.get(playIndex);
|
109
117
|
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
}
|
118
|
+
if (audio != null) {
|
119
|
+
audio.loop();
|
120
|
+
playIndex++;
|
121
|
+
playIndex = playIndex % audioList.size();
|
122
|
+
} else {
|
123
|
+
throw new Exception("AudioDispatcher is null");
|
117
124
|
}
|
125
|
+
}
|
118
126
|
|
119
|
-
|
120
|
-
|
127
|
+
public void unload() throws Exception {
|
128
|
+
this.stop();
|
121
129
|
|
122
|
-
|
123
|
-
|
130
|
+
for (int x = 0; x < audioList.size(); x++) {
|
131
|
+
AudioDispatcher audio = audioList.get(x);
|
124
132
|
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
}
|
131
|
-
|
132
|
-
audioList.clear();
|
133
|
+
if (audio != null) {
|
134
|
+
audio.unload();
|
135
|
+
} else {
|
136
|
+
throw new Exception("AudioDispatcher is null");
|
137
|
+
}
|
133
138
|
}
|
134
139
|
|
135
|
-
|
136
|
-
|
137
|
-
|
140
|
+
audioList.clear();
|
141
|
+
}
|
142
|
+
|
143
|
+
public void setVolume(float volume) throws Exception {
|
144
|
+
for (int x = 0; x < audioList.size(); x++) {
|
145
|
+
AudioDispatcher audio = audioList.get(x);
|
138
146
|
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
}
|
147
|
+
if (audio != null) {
|
148
|
+
audio.setVolume(volume);
|
149
|
+
} else {
|
150
|
+
throw new Exception("AudioDispatcher is null");
|
151
|
+
}
|
145
152
|
}
|
153
|
+
}
|
146
154
|
|
147
|
-
|
148
|
-
|
155
|
+
public boolean isPlaying() throws Exception {
|
156
|
+
if (audioList.size() != 1) return false;
|
149
157
|
|
150
|
-
|
151
|
-
|
158
|
+
return audioList.get(playIndex).isPlaying();
|
159
|
+
}
|
152
160
|
}
|