@capgo/native-audio 5.1.10 → 5.1.13
Sign up to get free protection for your applications and to get access to all the features.
package/README.md
CHANGED
@@ -385,6 +385,26 @@ isPlaying(options: { assetId: string; }) => Promise<{ isPlaying: boolean; }>
|
|
385
385
|
--------------------
|
386
386
|
|
387
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<<a href="#pluginlistenerhandle">PluginListenerHandle</a>> & <a href="#pluginlistenerhandle">PluginListenerHandle</a></code>
|
402
|
+
|
403
|
+
**Since:** 5.0.0
|
404
|
+
|
405
|
+
--------------------
|
406
|
+
|
407
|
+
|
388
408
|
### Interfaces
|
389
409
|
|
390
410
|
|
@@ -406,4 +426,26 @@ isPlaying(options: { assetId: string; }) => Promise<{ isPlaying: boolean; }>
|
|
406
426
|
| **`audioChannelNum`** | <code>number</code> |
|
407
427
|
| **`isUrl`** | <code>boolean</code> |
|
408
428
|
|
429
|
+
|
430
|
+
#### PluginListenerHandle
|
431
|
+
|
432
|
+
| Prop | Type |
|
433
|
+
| ------------ | ----------------------------------------- |
|
434
|
+
| **`remove`** | <code>() => Promise<void></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
|
+
|
409
451
|
</docgen-api>
|
@@ -1,6 +1,8 @@
|
|
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;
|
@@ -152,6 +154,16 @@ public class AudioAsset {
|
|
152
154
|
}
|
153
155
|
}
|
154
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
|
+
}
|
164
|
+
}
|
165
|
+
}
|
166
|
+
|
155
167
|
public boolean isPlaying() throws Exception {
|
156
168
|
if (audioList.size() != 1) return false;
|
157
169
|
|
@@ -11,6 +11,7 @@ import static ee.forgr.audio.Constant.ERROR_AUDIO_ID_MISSING;
|
|
11
11
|
import static ee.forgr.audio.Constant.LOOP;
|
12
12
|
import static ee.forgr.audio.Constant.OPT_FADE_MUSIC;
|
13
13
|
import static ee.forgr.audio.Constant.OPT_FOCUS_AUDIO;
|
14
|
+
import static ee.forgr.audio.Constant.RATE;
|
14
15
|
import static ee.forgr.audio.Constant.VOLUME;
|
15
16
|
|
16
17
|
import android.Manifest;
|
@@ -18,8 +19,10 @@ import android.content.Context;
|
|
18
19
|
import android.content.res.AssetFileDescriptor;
|
19
20
|
import android.content.res.AssetManager;
|
20
21
|
import android.media.AudioManager;
|
22
|
+
import android.os.Build;
|
21
23
|
import android.os.ParcelFileDescriptor;
|
22
24
|
import android.util.Log;
|
25
|
+
import androidx.annotation.RequiresApi;
|
23
26
|
import com.getcapacitor.JSObject;
|
24
27
|
import com.getcapacitor.Plugin;
|
25
28
|
import com.getcapacitor.PluginCall;
|
@@ -363,6 +366,28 @@ public class NativeAudio
|
|
363
366
|
}
|
364
367
|
}
|
365
368
|
|
369
|
+
@RequiresApi(api = Build.VERSION_CODES.M)
|
370
|
+
@PluginMethod
|
371
|
+
public void setRate(PluginCall call) {
|
372
|
+
try {
|
373
|
+
initSoundPool();
|
374
|
+
|
375
|
+
String audioId = call.getString(ASSET_ID);
|
376
|
+
float rate = call.getFloat(RATE);
|
377
|
+
|
378
|
+
if (audioAssetList.containsKey(audioId)) {
|
379
|
+
AudioAsset asset = audioAssetList.get(audioId);
|
380
|
+
if (asset != null) {
|
381
|
+
asset.setRate(rate);
|
382
|
+
}
|
383
|
+
} else {
|
384
|
+
call.reject(ERROR_AUDIO_ASSET_MISSING);
|
385
|
+
}
|
386
|
+
} catch (Exception ex) {
|
387
|
+
call.reject(ex.getMessage());
|
388
|
+
}
|
389
|
+
}
|
390
|
+
|
366
391
|
@PluginMethod
|
367
392
|
public void isPlaying(final PluginCall call) {
|
368
393
|
try {
|
package/dist/docs.json
CHANGED
@@ -216,6 +216,35 @@
|
|
216
216
|
"docs": "",
|
217
217
|
"complexTypes": [],
|
218
218
|
"slug": "isplaying"
|
219
|
+
},
|
220
|
+
{
|
221
|
+
"name": "addListener",
|
222
|
+
"signature": "(eventName: \"complete\", listenerFunc: CompletedListener) => Promise<PluginListenerHandle> & PluginListenerHandle",
|
223
|
+
"parameters": [
|
224
|
+
{
|
225
|
+
"name": "eventName",
|
226
|
+
"docs": "",
|
227
|
+
"type": "'complete'"
|
228
|
+
},
|
229
|
+
{
|
230
|
+
"name": "listenerFunc",
|
231
|
+
"docs": "",
|
232
|
+
"type": "CompletedListener"
|
233
|
+
}
|
234
|
+
],
|
235
|
+
"returns": "Promise<PluginListenerHandle> & PluginListenerHandle",
|
236
|
+
"tags": [
|
237
|
+
{
|
238
|
+
"name": "since",
|
239
|
+
"text": "5.0.0"
|
240
|
+
}
|
241
|
+
],
|
242
|
+
"docs": "Listen for complete event",
|
243
|
+
"complexTypes": [
|
244
|
+
"PluginListenerHandle",
|
245
|
+
"CompletedListener"
|
246
|
+
],
|
247
|
+
"slug": "addlistenercomplete"
|
219
248
|
}
|
220
249
|
],
|
221
250
|
"properties": []
|
@@ -287,9 +316,60 @@
|
|
287
316
|
"type": "boolean | undefined"
|
288
317
|
}
|
289
318
|
]
|
319
|
+
},
|
320
|
+
{
|
321
|
+
"name": "PluginListenerHandle",
|
322
|
+
"slug": "pluginlistenerhandle",
|
323
|
+
"docs": "",
|
324
|
+
"tags": [],
|
325
|
+
"methods": [],
|
326
|
+
"properties": [
|
327
|
+
{
|
328
|
+
"name": "remove",
|
329
|
+
"tags": [],
|
330
|
+
"docs": "",
|
331
|
+
"complexTypes": [],
|
332
|
+
"type": "() => Promise<void>"
|
333
|
+
}
|
334
|
+
]
|
335
|
+
},
|
336
|
+
{
|
337
|
+
"name": "CompletedEvent",
|
338
|
+
"slug": "completedevent",
|
339
|
+
"docs": "",
|
340
|
+
"tags": [],
|
341
|
+
"methods": [],
|
342
|
+
"properties": [
|
343
|
+
{
|
344
|
+
"name": "assetId",
|
345
|
+
"tags": [
|
346
|
+
{
|
347
|
+
"text": "5.0.0",
|
348
|
+
"name": "since"
|
349
|
+
}
|
350
|
+
],
|
351
|
+
"docs": "Emit when a play completes",
|
352
|
+
"complexTypes": [],
|
353
|
+
"type": "string"
|
354
|
+
}
|
355
|
+
]
|
290
356
|
}
|
291
357
|
],
|
292
358
|
"enums": [],
|
293
|
-
"typeAliases": [
|
359
|
+
"typeAliases": [
|
360
|
+
{
|
361
|
+
"name": "CompletedListener",
|
362
|
+
"slug": "completedlistener",
|
363
|
+
"docs": "",
|
364
|
+
"types": [
|
365
|
+
{
|
366
|
+
"text": "(state: CompletedEvent): void",
|
367
|
+
"complexTypes": [
|
368
|
+
"CompletedEvent"
|
369
|
+
]
|
370
|
+
}
|
371
|
+
]
|
372
|
+
}
|
373
|
+
],
|
294
374
|
"pluginConfigs": []
|
295
375
|
}
|
@@ -1,3 +1,13 @@
|
|
1
|
+
import type { PluginListenerHandle } from "@capacitor/core";
|
2
|
+
export interface CompletedEvent {
|
3
|
+
/**
|
4
|
+
* Emit when a play completes
|
5
|
+
*
|
6
|
+
* @since 5.0.0
|
7
|
+
*/
|
8
|
+
assetId: string;
|
9
|
+
}
|
10
|
+
export type CompletedListener = (state: CompletedEvent) => void;
|
1
11
|
export interface NativeAudio {
|
2
12
|
configure(options: ConfigureOptions): Promise<void>;
|
3
13
|
preload(options: PreloadOptions): Promise<void>;
|
@@ -43,6 +53,12 @@ export interface NativeAudio {
|
|
43
53
|
}): Promise<{
|
44
54
|
isPlaying: boolean;
|
45
55
|
}>;
|
56
|
+
/**
|
57
|
+
* Listen for complete event
|
58
|
+
*
|
59
|
+
* @since 5.0.0
|
60
|
+
*/
|
61
|
+
addListener(eventName: "complete", listenerFunc: CompletedListener): Promise<PluginListenerHandle> & PluginListenerHandle;
|
46
62
|
}
|
47
63
|
export interface ConfigureOptions {
|
48
64
|
fade?: boolean;
|