@capgo/native-audio 5.1.3 → 5.1.10

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,14 @@ 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>
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
- 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(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;
22
-
23
- if (audioChannelNum < 0) {
24
- audioChannelNum = 1;
25
- }
26
-
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
- }
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
- public void dispatchComplete() {
35
- this.owner.dispatchComplete(this.assetId);
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
- public void play(Double time, Callable<Void> callback) throws Exception {
39
- AudioDispatcher audio = audioList.get(playIndex);
42
+ public void dispatchComplete() {
43
+ this.owner.dispatchComplete(this.assetId);
44
+ }
40
45
 
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
- }
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
- public double getDuration() {
51
- if (audioList.size() != 1) return 0;
58
+ public double getDuration() {
59
+ if (audioList.size() != 1) return 0;
52
60
 
53
- AudioDispatcher audio = audioList.get(playIndex);
61
+ AudioDispatcher audio = audioList.get(playIndex);
54
62
 
55
- if (audio != null) {
56
- return audio.getDuration();
57
- }
58
- return 0;
63
+ if (audio != null) {
64
+ return audio.getDuration();
59
65
  }
66
+ return 0;
67
+ }
60
68
 
61
- public double getCurrentPosition() {
62
- if (audioList.size() != 1) return 0;
69
+ public double getCurrentPosition() {
70
+ if (audioList.size() != 1) return 0;
63
71
 
64
- AudioDispatcher audio = audioList.get(playIndex);
72
+ AudioDispatcher audio = audioList.get(playIndex);
65
73
 
66
- if (audio != null) {
67
- return audio.getCurrentPosition();
68
- }
69
- return 0;
74
+ if (audio != null) {
75
+ return audio.getCurrentPosition();
70
76
  }
77
+ return 0;
78
+ }
71
79
 
72
- public boolean pause() throws Exception {
73
- boolean wasPlaying = false;
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
- return wasPlaying;
83
+ for (int x = 0; x < audioList.size(); x++) {
84
+ AudioDispatcher audio = audioList.get(x);
85
+ wasPlaying |= audio.pause();
81
86
  }
82
87
 
83
- public void resume() throws Exception {
84
- if (audioList.size() > 0) {
85
- AudioDispatcher audio = audioList.get(0);
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
- if (audio != null) {
88
- audio.resume();
89
- } else {
90
- throw new Exception("AudioDispatcher is null");
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
- public void stop() throws Exception {
96
- for (int x = 0; x < audioList.size(); x++) {
97
- AudioDispatcher audio = audioList.get(x);
103
+ public void stop() throws Exception {
104
+ for (int x = 0; x < audioList.size(); x++) {
105
+ AudioDispatcher audio = audioList.get(x);
98
106
 
99
- if (audio != null) {
100
- audio.stop();
101
- } else {
102
- throw new Exception("AudioDispatcher is null");
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
- public void loop() throws Exception {
108
- AudioDispatcher audio = audioList.get(playIndex);
115
+ public void loop() throws Exception {
116
+ AudioDispatcher audio = audioList.get(playIndex);
109
117
 
110
- if (audio != null) {
111
- audio.loop();
112
- playIndex++;
113
- playIndex = playIndex % audioList.size();
114
- } else {
115
- throw new Exception("AudioDispatcher is null");
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
- public void unload() throws Exception {
120
- this.stop();
127
+ public void unload() throws Exception {
128
+ this.stop();
121
129
 
122
- for (int x = 0; x < audioList.size(); x++) {
123
- AudioDispatcher audio = audioList.get(x);
130
+ for (int x = 0; x < audioList.size(); x++) {
131
+ AudioDispatcher audio = audioList.get(x);
124
132
 
125
- if (audio != null) {
126
- audio.unload();
127
- } else {
128
- throw new Exception("AudioDispatcher is null");
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
- public void setVolume(float volume) throws Exception {
136
- for (int x = 0; x < audioList.size(); x++) {
137
- AudioDispatcher audio = audioList.get(x);
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
- if (audio != null) {
140
- audio.setVolume(volume);
141
- } else {
142
- throw new Exception("AudioDispatcher is null");
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
- public boolean isPlaying() throws Exception {
148
- if (audioList.size() != 1) return false;
155
+ public boolean isPlaying() throws Exception {
156
+ if (audioList.size() != 1) return false;
149
157
 
150
- return audioList.get(playIndex).isPlaying();
151
- }
158
+ return audioList.get(playIndex).isPlaying();
159
+ }
152
160
  }