@capgo/native-audio 5.1.3 → 5.1.13

Sign up to get free protection for your applications and to get access to all the features.
package/README.md CHANGED
@@ -213,164 +213,144 @@ NativeAudio.isPlaying({
213
213
  ### configure(...)
214
214
 
215
215
  ```typescript
216
- configure(options: ConfigureOptions) => any
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) => any
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; }) => any
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; }) => any
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; }) => any
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; }) => any
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; }) => any
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; }) => any
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; }) => any
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; }) => any
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; }) => any
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>any</code>
353
+ **Returns:** <code>Promise&lt;{ currentTime: number; }&gt;</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; }) => any
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>any</code>
368
+ **Returns:** <code>Promise&lt;{ duration: number; }&gt;</code>
389
369
 
390
370
  --------------------
391
371
 
@@ -393,14 +373,34 @@ getDuration(options: { assetId: string; }) => any
393
373
  ### isPlaying(...)
394
374
 
395
375
  ```typescript
396
- isPlaying(options: { assetId: string; }) => any
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>any</code>
383
+ **Returns:** <code>Promise&lt;{ isPlaying: boolean; }&gt;</code>
384
+
385
+ --------------------
386
+
387
+
388
+ ### addListener('complete', ...)
389
+
390
+ ```typescript
391
+ addListener(eventName: "complete", listenerFunc: CompletedListener) => Promise<PluginListenerHandle> & PluginListenerHandle
392
+ ```
393
+
394
+ Listen for complete event
395
+
396
+ | Param | Type |
397
+ | ------------------ | --------------------------------------------------------------- |
398
+ | **`eventName`** | <code>'complete'</code> |
399
+ | **`listenerFunc`** | <code><a href="#completedlistener">CompletedListener</a></code> |
400
+
401
+ **Returns:** <code>Promise&lt;<a href="#pluginlistenerhandle">PluginListenerHandle</a>&gt; & <a href="#pluginlistenerhandle">PluginListenerHandle</a></code>
402
+
403
+ **Since:** 5.0.0
404
404
 
405
405
  --------------------
406
406
 
@@ -426,4 +426,26 @@ isPlaying(options: { assetId: string; }) => any
426
426
  | **`audioChannelNum`** | <code>number</code> |
427
427
  | **`isUrl`** | <code>boolean</code> |
428
428
 
429
+
430
+ #### PluginListenerHandle
431
+
432
+ | Prop | Type |
433
+ | ------------ | ----------------------------------------- |
434
+ | **`remove`** | <code>() =&gt; Promise&lt;void&gt;</code> |
435
+
436
+
437
+ #### CompletedEvent
438
+
439
+ | Prop | Type | Description | Since |
440
+ | ------------- | ------------------- | -------------------------- | ----- |
441
+ | **`assetId`** | <code>string</code> | Emit when a play completes | 5.0.0 |
442
+
443
+
444
+ ### Type Aliases
445
+
446
+
447
+ #### CompletedListener
448
+
449
+ <code>(state: <a href="#completedevent">CompletedEvent</a>): void</code>
450
+
429
451
  </docgen-api>
@@ -1,152 +1,172 @@
1
1
  package ee.forgr.audio;
2
2
 
3
3
  import android.content.res.AssetFileDescriptor;
4
+ import android.os.Build;
5
+ import androidx.annotation.RequiresApi;
4
6
  import com.getcapacitor.JSObject;
5
7
  import java.util.ArrayList;
6
8
  import java.util.concurrent.Callable;
7
9
 
8
10
  public class AudioAsset {
9
11
 
10
- private final String TAG = "AudioAsset";
12
+ private final String TAG = "AudioAsset";
13
+
14
+ private ArrayList<AudioDispatcher> audioList;
15
+ private int playIndex = 0;
16
+ private String assetId;
17
+ private NativeAudio owner;
18
+
19
+ AudioAsset(
20
+ NativeAudio owner,
21
+ String assetId,
22
+ AssetFileDescriptor assetFileDescriptor,
23
+ int audioChannelNum,
24
+ float volume
25
+ ) throws Exception {
26
+ audioList = new ArrayList<>();
27
+ this.owner = owner;
28
+ this.assetId = assetId;
29
+
30
+ if (audioChannelNum < 0) {
31
+ audioChannelNum = 1;
32
+ }
11
33
 
12
- private ArrayList<AudioDispatcher> audioList;
13
- private int playIndex = 0;
14
- private String assetId;
15
- private NativeAudio owner;
34
+ for (int x = 0; x < audioChannelNum; x++) {
35
+ AudioDispatcher audioDispatcher = new AudioDispatcher(
36
+ assetFileDescriptor,
37
+ volume
38
+ );
39
+ audioList.add(audioDispatcher);
40
+ if (audioChannelNum == 1) audioDispatcher.setOwner(this);
41
+ }
42
+ }
16
43
 
17
- AudioAsset(NativeAudio owner, String assetId, AssetFileDescriptor assetFileDescriptor, int audioChannelNum, float volume)
18
- throws Exception {
19
- audioList = new ArrayList<>();
20
- this.owner = owner;
21
- this.assetId = assetId;
44
+ public void dispatchComplete() {
45
+ this.owner.dispatchComplete(this.assetId);
46
+ }
22
47
 
23
- if (audioChannelNum < 0) {
24
- audioChannelNum = 1;
25
- }
48
+ public void play(Double time) throws Exception {
49
+ AudioDispatcher audio = audioList.get(playIndex);
26
50
 
27
- for (int x = 0; x < audioChannelNum; x++) {
28
- AudioDispatcher audioDispatcher = new AudioDispatcher(assetFileDescriptor, volume);
29
- audioList.add(audioDispatcher);
30
- if (audioChannelNum == 1) audioDispatcher.setOwner(this);
31
- }
51
+ if (audio != null) {
52
+ audio.play(time);
53
+ playIndex++;
54
+ playIndex = playIndex % audioList.size();
55
+ } else {
56
+ throw new Exception("AudioDispatcher is null");
32
57
  }
58
+ }
33
59
 
34
- public void dispatchComplete() {
35
- this.owner.dispatchComplete(this.assetId);
36
- }
60
+ public double getDuration() {
61
+ if (audioList.size() != 1) return 0;
37
62
 
38
- public void play(Double time, Callable<Void> callback) throws Exception {
39
- AudioDispatcher audio = audioList.get(playIndex);
63
+ AudioDispatcher audio = audioList.get(playIndex);
40
64
 
41
- if (audio != null) {
42
- audio.play(time, callback);
43
- playIndex++;
44
- playIndex = playIndex % audioList.size();
45
- } else {
46
- throw new Exception("AudioDispatcher is null");
47
- }
65
+ if (audio != null) {
66
+ return audio.getDuration();
48
67
  }
68
+ return 0;
69
+ }
49
70
 
50
- public double getDuration() {
51
- if (audioList.size() != 1) return 0;
71
+ public double getCurrentPosition() {
72
+ if (audioList.size() != 1) return 0;
52
73
 
53
- AudioDispatcher audio = audioList.get(playIndex);
74
+ AudioDispatcher audio = audioList.get(playIndex);
54
75
 
55
- if (audio != null) {
56
- return audio.getDuration();
57
- }
58
- return 0;
76
+ if (audio != null) {
77
+ return audio.getCurrentPosition();
59
78
  }
79
+ return 0;
80
+ }
60
81
 
61
- public double getCurrentPosition() {
62
- if (audioList.size() != 1) return 0;
82
+ public boolean pause() throws Exception {
83
+ boolean wasPlaying = false;
63
84
 
64
- AudioDispatcher audio = audioList.get(playIndex);
65
-
66
- if (audio != null) {
67
- return audio.getCurrentPosition();
68
- }
69
- return 0;
85
+ for (int x = 0; x < audioList.size(); x++) {
86
+ AudioDispatcher audio = audioList.get(x);
87
+ wasPlaying |= audio.pause();
70
88
  }
71
89
 
72
- public boolean pause() throws Exception {
73
- boolean wasPlaying = false;
90
+ return wasPlaying;
91
+ }
74
92
 
75
- for (int x = 0; x < audioList.size(); x++) {
76
- AudioDispatcher audio = audioList.get(x);
77
- wasPlaying |= audio.pause();
78
- }
93
+ public void resume() throws Exception {
94
+ if (audioList.size() > 0) {
95
+ AudioDispatcher audio = audioList.get(0);
79
96
 
80
- return wasPlaying;
97
+ if (audio != null) {
98
+ audio.resume();
99
+ } else {
100
+ throw new Exception("AudioDispatcher is null");
101
+ }
81
102
  }
103
+ }
82
104
 
83
- public void resume() throws Exception {
84
- if (audioList.size() > 0) {
85
- AudioDispatcher audio = audioList.get(0);
105
+ public void stop() throws Exception {
106
+ for (int x = 0; x < audioList.size(); x++) {
107
+ AudioDispatcher audio = audioList.get(x);
86
108
 
87
- if (audio != null) {
88
- audio.resume();
89
- } else {
90
- throw new Exception("AudioDispatcher is null");
91
- }
92
- }
109
+ if (audio != null) {
110
+ audio.stop();
111
+ } else {
112
+ throw new Exception("AudioDispatcher is null");
113
+ }
93
114
  }
115
+ }
94
116
 
95
- public void stop() throws Exception {
96
- for (int x = 0; x < audioList.size(); x++) {
97
- AudioDispatcher audio = audioList.get(x);
117
+ public void loop() throws Exception {
118
+ AudioDispatcher audio = audioList.get(playIndex);
98
119
 
99
- if (audio != null) {
100
- audio.stop();
101
- } else {
102
- throw new Exception("AudioDispatcher is null");
103
- }
104
- }
120
+ if (audio != null) {
121
+ audio.loop();
122
+ playIndex++;
123
+ playIndex = playIndex % audioList.size();
124
+ } else {
125
+ throw new Exception("AudioDispatcher is null");
105
126
  }
127
+ }
106
128
 
107
- public void loop() throws Exception {
108
- AudioDispatcher audio = audioList.get(playIndex);
129
+ public void unload() throws Exception {
130
+ this.stop();
109
131
 
110
- if (audio != null) {
111
- audio.loop();
112
- playIndex++;
113
- playIndex = playIndex % audioList.size();
114
- } else {
115
- throw new Exception("AudioDispatcher is null");
116
- }
117
- }
132
+ for (int x = 0; x < audioList.size(); x++) {
133
+ AudioDispatcher audio = audioList.get(x);
118
134
 
119
- public void unload() throws Exception {
120
- this.stop();
135
+ if (audio != null) {
136
+ audio.unload();
137
+ } else {
138
+ throw new Exception("AudioDispatcher is null");
139
+ }
140
+ }
121
141
 
122
- for (int x = 0; x < audioList.size(); x++) {
123
- AudioDispatcher audio = audioList.get(x);
142
+ audioList.clear();
143
+ }
124
144
 
125
- if (audio != null) {
126
- audio.unload();
127
- } else {
128
- throw new Exception("AudioDispatcher is null");
129
- }
130
- }
145
+ public void setVolume(float volume) throws Exception {
146
+ for (int x = 0; x < audioList.size(); x++) {
147
+ AudioDispatcher audio = audioList.get(x);
131
148
 
132
- audioList.clear();
149
+ if (audio != null) {
150
+ audio.setVolume(volume);
151
+ } else {
152
+ throw new Exception("AudioDispatcher is null");
153
+ }
133
154
  }
134
-
135
- public void setVolume(float volume) throws Exception {
136
- for (int x = 0; x < audioList.size(); x++) {
137
- AudioDispatcher audio = audioList.get(x);
138
-
139
- if (audio != null) {
140
- audio.setVolume(volume);
141
- } else {
142
- throw new Exception("AudioDispatcher is null");
143
- }
144
- }
155
+ }
156
+
157
+ @RequiresApi(api = Build.VERSION_CODES.M)
158
+ public void setRate(float rate) throws Exception {
159
+ for (int x = 0; x < audioList.size(); x++) {
160
+ AudioDispatcher audio = audioList.get(x);
161
+ if (audio != null) {
162
+ audio.setRate(rate);
163
+ }
145
164
  }
165
+ }
146
166
 
147
- public boolean isPlaying() throws Exception {
148
- if (audioList.size() != 1) return false;
167
+ public boolean isPlaying() throws Exception {
168
+ if (audioList.size() != 1) return false;
149
169
 
150
- return audioList.get(playIndex).isPlaying();
151
- }
170
+ return audioList.get(playIndex).isPlaying();
171
+ }
152
172
  }