@capgo/capacitor-native-audio 8.4.3

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.
Files changed (46) hide show
  1. package/CapgoCapacitorNativeAudio.podspec +16 -0
  2. package/LICENSE +373 -0
  3. package/Package.swift +31 -0
  4. package/README.md +1229 -0
  5. package/android/build.gradle +89 -0
  6. package/android/src/main/AndroidManifest.xml +3 -0
  7. package/android/src/main/java/ee/forgr/audio/AudioAsset.java +611 -0
  8. package/android/src/main/java/ee/forgr/audio/AudioCompletionListener.java +5 -0
  9. package/android/src/main/java/ee/forgr/audio/AudioDispatcher.java +208 -0
  10. package/android/src/main/java/ee/forgr/audio/Constant.java +36 -0
  11. package/android/src/main/java/ee/forgr/audio/HlsAvailabilityChecker.java +84 -0
  12. package/android/src/main/java/ee/forgr/audio/Logger.java +55 -0
  13. package/android/src/main/java/ee/forgr/audio/NativeAudio.java +2022 -0
  14. package/android/src/main/java/ee/forgr/audio/RemoteAudioAsset.java +886 -0
  15. package/android/src/main/java/ee/forgr/audio/StreamAudioAsset.java +708 -0
  16. package/android/src/main/res/values/colors.xml +3 -0
  17. package/android/src/main/res/values/strings.xml +3 -0
  18. package/android/src/main/res/values/styles.xml +3 -0
  19. package/dist/docs.json +1470 -0
  20. package/dist/esm/audio-asset.d.ts +4 -0
  21. package/dist/esm/audio-asset.js +6 -0
  22. package/dist/esm/audio-asset.js.map +1 -0
  23. package/dist/esm/definitions.d.ts +597 -0
  24. package/dist/esm/definitions.js +2 -0
  25. package/dist/esm/definitions.js.map +1 -0
  26. package/dist/esm/index.d.ts +4 -0
  27. package/dist/esm/index.js +7 -0
  28. package/dist/esm/index.js.map +1 -0
  29. package/dist/esm/web.d.ts +82 -0
  30. package/dist/esm/web.js +553 -0
  31. package/dist/esm/web.js.map +1 -0
  32. package/dist/plugin.cjs.js +571 -0
  33. package/dist/plugin.cjs.js.map +1 -0
  34. package/dist/plugin.js +574 -0
  35. package/dist/plugin.js.map +1 -0
  36. package/ios/Sources/NativeAudioPlugin/AudioAsset+Fade.swift +157 -0
  37. package/ios/Sources/NativeAudioPlugin/AudioAsset.swift +403 -0
  38. package/ios/Sources/NativeAudioPlugin/Constant.swift +52 -0
  39. package/ios/Sources/NativeAudioPlugin/Logger.swift +43 -0
  40. package/ios/Sources/NativeAudioPlugin/Plugin.swift +1786 -0
  41. package/ios/Sources/NativeAudioPlugin/RemoteAudioAsset+Fade.swift +152 -0
  42. package/ios/Sources/NativeAudioPlugin/RemoteAudioAsset.swift +405 -0
  43. package/ios/Tests/NativeAudioPluginTests/PluginTests.swift +648 -0
  44. package/ios/Tests/README.md +39 -0
  45. package/package.json +101 -0
  46. package/scripts/configure-dependencies.js +251 -0
package/README.md ADDED
@@ -0,0 +1,1229 @@
1
+ # Native audio
2
+
3
+ <a href="https://capgo.app/"><img src="https://capgo.app/readme-banner.svg?repo=Cap-go/capacitor-native-audio" alt="Capgo - Instant updates for Capacitor" /></a>
4
+
5
+ <div align="center">
6
+ <h2><a href="https://capgo.app/?ref=plugin_native_audio"> ➡️ Get Instant updates for your App with Capgo</a></h2>
7
+ <h2><a href="https://capgo.app/consulting/?ref=plugin_native_audio"> Missing a feature? We’ll build the plugin for you 💪</a></h2>
8
+ </div>
9
+
10
+ <h3 align="center">Native Audio</h3>
11
+ <p align="center">
12
+ <strong>
13
+ <code>@capgo/capacitor-native-audio</code>
14
+ </strong>
15
+ </p>
16
+ <p align="center">Capacitor plugin for playing sounds.</p>
17
+
18
+ <p align="center">
19
+ <img src="https://img.shields.io/maintenance/yes/2023?style=flat-square" alt="Maintenance status badge" />
20
+ <a href="https://github.com/Cap-go/capacitor-native-audio/actions?query=workflow%3A%22Test+and+Build+Plugin%22"><img src="https://img.shields.io/github/workflow/status/Cap-go/capacitor-native-audio/Test%20and%20Build%20Plugin?style=flat-square" alt="CI status badge" /></a>
21
+ <a href="https://www.npmjs.com/package/@capgo/capacitor-native-audio"><img src="https://img.shields.io/npm/l/@capgo/capacitor-native-audio?style=flat-square" alt="NPM license badge" /></a>
22
+ <br>
23
+ <a href="https://www.npmjs.com/package/@capgo/capacitor-native-audio"><img src="https://img.shields.io/npm/dw/@capgo/capacitor-native-audio?style=flat-square" alt="NPM weekly downloads badge" /></a>
24
+ <a href="https://www.npmjs.com/package/@capgo/capacitor-native-audio"><img src="https://img.shields.io/npm/v/@capgo/capacitor-native-audio?style=flat-square" alt="NPM version badge" /></a>
25
+ <!-- ALL-CONTRIBUTORS-BADGE:START - Do not remove or modify this section -->
26
+ <a href="#contributors-"><img src="https://img.shields.io/badge/all%20contributors-6-orange?style=flat-square" alt="All contributors badge" /></a>
27
+ <!-- ALL-CONTRIBUTORS-BADGE:END -->
28
+ </p>
29
+
30
+ # Capacitor Native Audio Plugin
31
+
32
+ Capacitor plugin for native audio engine.
33
+ Capacitor V8 - ✅ Support!
34
+
35
+ Support local file, remote URL, and m3u8 stream
36
+
37
+ Click on video to see example 💥
38
+
39
+ [![YouTube Example](https://img.youtube.com/vi/XpUGlWWtwHs/0.jpg)](https://www.youtube.com/watch?v=XpUGlWWtwHs)
40
+
41
+ ## Why Native Audio?
42
+
43
+ The only **free**, **full-featured** audio playback plugin for Capacitor:
44
+
45
+ - **HLS/M3U8 streaming** - Play live audio streams and adaptive bitrate content
46
+ - **Remote URLs** - Stream from HTTP/HTTPS sources with built-in caching
47
+ - **Low-latency playback** - Optimized native audio engine for sound effects and music
48
+ - **Full control** - Play, pause, resume, loop, seek, volume, playback rate
49
+ - **Multiple channels** - Play multiple audio files simultaneously
50
+ - **Background playback** - Continue playing when app is backgrounded
51
+ - **Notification center display** - Show audio metadata in iOS Control Center and Android notifications
52
+ - **Position tracking** - Real-time currentTime events (100ms intervals)
53
+ - **Modern package management** - Supports both Swift Package Manager (SPM) and CocoaPods (SPM-ready for Capacitor 8)
54
+ - **Same JavaScript API** - Compatible interface with paid alternatives
55
+ - **Support player notification center** - Play, pause, show cover for your user when long playing audio.
56
+
57
+ Perfect for music players, podcast apps, games, meditation apps, and any audio-heavy application.
58
+
59
+ ## Maintainers
60
+
61
+ | Maintainer | GitHub | Social |
62
+ | --------------- | ----------------------------------- | --------------------------------------- |
63
+ | Martin Donadieu | [riderx](https://github.com/riderx) | [Telegram](https://t.me/martindonadieu) |
64
+
65
+ Mainteinance Status: Actively Maintained
66
+
67
+ ## Preparation
68
+
69
+ All audio files must be with the rest of your source files.
70
+
71
+ First make your sound file end up in your built code folder, example in folder `BUILDFOLDER/assets/sounds/FILENAME.mp3`
72
+ Then use it in preload like that `assets/sounds/FILENAME.mp3`
73
+
74
+ ## Documentation
75
+
76
+ The most complete doc is available here: https://capgo.app/docs/plugins/native-audio/
77
+
78
+ ## Compatibility
79
+
80
+ | Plugin version | Capacitor compatibility | Maintained |
81
+ | -------------- | ----------------------- | ---------- |
82
+ | v8.\*.\* | v8.\*.\* | ✅ |
83
+ | v7.\*.\* | v7.\*.\* | On demand |
84
+ | v6.\*.\* | v6.\*.\* | ❌ |
85
+ | v5.\*.\* | v5.\*.\* | ❌ |
86
+
87
+ > **Note:** The major version of this plugin follows the major version of Capacitor. Use the version that matches your Capacitor installation (e.g., plugin v8 for Capacitor 8). Only the latest major version is actively maintained.
88
+
89
+ ## Installation
90
+
91
+ To use npm
92
+
93
+ ```bash
94
+ npm install @capgo/capacitor-native-audio
95
+ ```
96
+
97
+ To use yarn
98
+
99
+ ```bash
100
+ yarn add @capgo/capacitor-native-audio
101
+ ```
102
+
103
+ Sync native files
104
+
105
+ ```bash
106
+ npx cap sync
107
+ ```
108
+
109
+ On iOS, Android and Web, no further steps are needed.
110
+
111
+ ### Swift Package Manager
112
+
113
+ You can also consume the iOS implementation via Swift Package Manager. In Xcode open **File → Add Package…**, point it at `https://github.com/Cap-go/capacitor-native-audio.git`, and select the `CapgoCapacitorNativeAudio` library product. The package supports iOS 14 and newer alongside Capacitor 8.
114
+
115
+ ## Configuration
116
+
117
+ ### Optional HLS/m3u8 Streaming (Android)
118
+
119
+ By default, HLS streaming support is **enabled** for backward compatibility. However, it adds approximately **4MB** to your Android APK size due to the `media3-exoplayer-hls` dependency.
120
+
121
+ If you don't need HLS/m3u8 streaming support, you can disable it to reduce your APK size:
122
+
123
+ ```typescript
124
+ // capacitor.config.ts
125
+ import type { CapacitorConfig } from '@capacitor/cli';
126
+
127
+ const config: CapacitorConfig = {
128
+ appId: 'com.example.app',
129
+ appName: 'My App',
130
+ plugins: {
131
+ NativeAudio: {
132
+ hls: false // Disable HLS to reduce APK size by ~4MB
133
+ }
134
+ }
135
+ };
136
+
137
+ export default config;
138
+ ```
139
+
140
+ After changing the configuration, run:
141
+
142
+ ```bash
143
+ npx cap sync
144
+ ```
145
+
146
+ **Notes:**
147
+ - iOS uses native AVPlayer for HLS, so this setting only affects Android
148
+ - If HLS is disabled and you try to play an `.m3u8` file, you'll get a clear error message explaining how to enable it
149
+ - The default is `hls: true` to maintain backward compatibility
150
+
151
+ <docgen-config>
152
+ <!--Update the source file JSDoc comments and rerun docgen to update the docs below-->
153
+
154
+
155
+
156
+ </docgen-config>
157
+
158
+ ## Supported methods
159
+
160
+ | Name | Android | iOS | Web |
161
+ |:---------------| :------ | :-- | :-- |
162
+ | configure | ✅ | ✅ | ❌ |
163
+ | preload | ✅ | ✅ | ✅ |
164
+ | play | ✅ | ✅ | ✅ |
165
+ | pause | ✅ | ✅ | ✅ |
166
+ | resume | ✅ | ✅ | ✅ |
167
+ | loop | ✅ | ✅ | ✅ |
168
+ | stop | ✅ | ✅ | ✅ |
169
+ | unload | ✅ | ✅ | ✅ |
170
+ | setVolume | ✅ | ✅ | ✅ |
171
+ | getDuration | ✅ | ✅ | ✅ |
172
+ | setCurrentTime | ✅ | ✅ | ✅ |
173
+ | getCurrentTime | ✅ | ✅ | ✅ |
174
+ | isPlaying | ✅ | ✅ | ✅ |
175
+
176
+ ## Usage
177
+
178
+ [Example repository](https://github.com/bazuka5801/native-audio-example)
179
+
180
+ ### Notification Center Display (iOS & Android)
181
+
182
+ You can display audio playback information in the system notification center. This is perfect for music players, podcast apps, and any app that plays audio in the background.
183
+
184
+ > **⚠️ Important iOS Behavior**
185
+ >
186
+ > Enabling `showNotification: true` changes how your app's audio interacts with other apps on iOS:
187
+ >
188
+ > - **With notifications enabled** (showNotification: true): Your audio will **interrupt** other apps' audio (like Spotify, Apple Music, etc.). This is required for Now Playing controls to appear in Control Center and on the lock screen.
189
+ > - **With notifications disabled** (showNotification: false): Your audio will **mix** with other apps' audio, allowing background music to continue playing.
190
+ >
191
+ > **When to use each:**
192
+ > - ✅ Use `showNotification: true` for: Music players, podcast apps, audiobook players (primary audio source)
193
+ > - ❌ Use `showNotification: false` for: Sound effects, notification sounds, secondary audio where mixing is preferred
194
+ >
195
+ > See [Issue #202](https://github.com/Cap-go/capacitor-native-audio/issues/202) for technical details.
196
+
197
+ **Step 1: Configure the plugin with notification support**
198
+
199
+ ```typescript
200
+ import { NativeAudio } from '@capgo/capacitor-native-audio'
201
+
202
+ // Enable notification center display
203
+ await NativeAudio.configure({
204
+ showNotification: true,
205
+ background: true // Also enable background playback
206
+ });
207
+ ```
208
+
209
+ **Step 2: Preload audio with metadata**
210
+
211
+ ```typescript
212
+ await NativeAudio.preload({
213
+ assetId: 'song1',
214
+ assetPath: 'https://example.com/song.mp3',
215
+ isUrl: true,
216
+ notificationMetadata: {
217
+ title: 'My Song Title',
218
+ artist: 'Artist Name',
219
+ album: 'Album Name',
220
+ artworkUrl: 'https://example.com/artwork.jpg' // Can be local or remote URL
221
+ }
222
+ });
223
+ ```
224
+
225
+ **Step 3: Play the audio**
226
+
227
+ ```typescript
228
+ // When you play the audio, it will automatically appear in the notification center
229
+ await NativeAudio.play({ assetId: 'song1' });
230
+ ```
231
+
232
+ The notification will:
233
+ - Show the title, artist, and album information
234
+ - Display the artwork/album art (if provided)
235
+ - Include media controls (play/pause/stop buttons)
236
+ - Automatically update when audio is paused/resumed
237
+ - Automatically clear when audio is stopped
238
+ - Work on both iOS and Android
239
+
240
+ **Media Controls:**
241
+ Users can control playback directly from:
242
+ - iOS: Control Center, Lock Screen, CarPlay
243
+ - Android: Notification tray, Lock Screen, Android Auto
244
+
245
+ The media control buttons automatically handle:
246
+ - **Play** - Resumes paused audio
247
+ - **Pause** - Pauses playing audio
248
+ - **Stop** - Stops audio and clears the notification
249
+ - **Rewind 15s** (Android only) - Skips backward 15 seconds
250
+ - **Forward 15s** (Android only) - Skips forward 15 seconds
251
+
252
+ If you need to keep your app UI synchronized with Android notification or lock-screen controls,
253
+ listen for the `playbackState` event. It emits the `assetId`, resolved state, reason, and the latest
254
+ position/duration snapshot after remote transport actions.
255
+
256
+ **Android Notification Controls:**
257
+ On Android, the notification displays three action buttons in this order:
258
+ 1. ⏪ **Rewind 15s** - Skip backward 15 seconds
259
+ 2. ▶️/⏸️ **Play/Pause** - Toggle playback (icon updates automatically)
260
+ 3. ⏩ **Forward 15s** - Skip forward 15 seconds
261
+
262
+ The skip forward/backward buttons are automatically available when `showNotification: true` is configured. No additional setup is required.
263
+
264
+ **Notes:**
265
+ - All metadata fields are optional
266
+ - Artwork can be a local file path or remote URL
267
+ - The notification only appears when `showNotification: true` is set in configure()
268
+ - ⚠️ **iOS:** Enabling notifications will interrupt other apps' audio (see warning above)
269
+ - iOS: Uses MPNowPlayingInfoCenter with MPRemoteCommandCenter
270
+ - Android: Uses MediaSession with NotificationCompat.MediaStyle
271
+
272
+ ### Android Background Playback @since 8.2.0
273
+
274
+ By default, Android apps pause audio when the app is backgrounded or the screen is locked. To enable continuous audio playback in the background (for meditation apps, music players, podcast players, etc.), use the `backgroundPlayback` flag.
275
+
276
+ > **⚠️ Important Android Requirements**
277
+ >
278
+ > To use background playback on Android, your app must meet these requirements:
279
+ > 1. Declare the required permissions in `AndroidManifest.xml`
280
+ > 2. Start an Android Foreground Service with a media notification
281
+ > 3. Configure the plugin with `backgroundPlayback: true`
282
+
283
+ **Step 1: Add required permissions to `AndroidManifest.xml`**
284
+
285
+ ```xml
286
+ <manifest xmlns:android="http://schemas.android.com/apk/res/android">
287
+ <!-- Required for background audio playback -->
288
+ <uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
289
+ <uses-permission android:name="android.permission.FOREGROUND_SERVICE_MEDIA_PLAYBACK" />
290
+ <uses-permission android:name="android.permission.WAKE_LOCK" />
291
+
292
+ <application>
293
+ <!-- Your app configuration -->
294
+ </application>
295
+ </manifest>
296
+ ```
297
+
298
+ **Step 2: Configure the plugin with background playback enabled**
299
+
300
+ ```typescript
301
+ import { NativeAudio } from '@capgo/capacitor-native-audio';
302
+
303
+ // Enable background playback and notification center
304
+ await NativeAudio.configure({
305
+ backgroundPlayback: true, // Prevent automatic pause when backgrounded
306
+ showNotification: true, // Show playback controls in notification
307
+ focus: true // Request audio focus (optional but recommended)
308
+ });
309
+ ```
310
+
311
+ **Step 3: Start a Foreground Service (your responsibility)**
312
+
313
+ The plugin does NOT automatically create or manage the Android Foreground Service. You must create and start your own foreground service using a Capacitor plugin like [`@capacitor/local-notifications`](https://capacitorjs.com/docs/apis/local-notifications) or a custom Android service.
314
+
315
+ Here's a conceptual example:
316
+
317
+ ```typescript
318
+ // 1. Configure the audio plugin
319
+ await NativeAudio.configure({
320
+ backgroundPlayback: true,
321
+ showNotification: true
322
+ });
323
+
324
+ // 2. Start your foreground service (implementation depends on your app)
325
+ // This is typically done with a native Android service or a plugin
326
+ // that provides foreground service capabilities
327
+ await startForegroundService();
328
+
329
+ // 3. Preload and play audio as normal
330
+ await NativeAudio.preload({
331
+ assetId: 'meditation',
332
+ assetPath: 'audio/meditation.mp3',
333
+ notificationMetadata: {
334
+ title: 'Meditation Session',
335
+ artist: 'Your App Name'
336
+ }
337
+ });
338
+
339
+ await NativeAudio.play({ assetId: 'meditation' });
340
+
341
+ // Audio will continue playing when app is backgrounded
342
+ // The foreground service ensures Android allows background playback
343
+ ```
344
+
345
+ **Important timing notes:**
346
+ - The foreground service should be started **before** the app enters the background
347
+ - Start the service immediately after configuring the audio plugin and before playing audio
348
+ - If the foreground service is not running, Android may still kill your audio playback
349
+
350
+ **How it works:**
351
+ - Without `backgroundPlayback: true`: The plugin automatically pauses all audio when the app enters the background
352
+ - With `backgroundPlayback: true`: The plugin skips automatic pause/resume, allowing continuous playback
353
+
354
+ **Important notes:**
355
+ - This flag is **Android-only** (iOS already supports background playback via AVAudioSession)
356
+ - You **must** start an Android Foreground Service separately (plugin does not handle this)
357
+ - Combine with `showNotification: true` to display playback controls
358
+ - Starting Android 14+, foreground services require the `FOREGROUND_SERVICE_MEDIA_PLAYBACK` permission type
359
+
360
+ **Alternative approach:**
361
+ If you need a complete solution including foreground service management, consider using a dedicated media playback plugin or implementing a custom Android service in your app's native code.
362
+
363
+ ## Play Once (Fire-and-Forget) @since 7.11.0
364
+
365
+ For simple one-shot audio playback (sound effects, notifications, etc.), use `playOnce()` which handles the entire asset lifecycle automatically:
366
+
367
+ ```typescript
368
+ // Basic usage - automatic cleanup after playback
369
+ await NativeAudio.playOnce({
370
+ assetPath: 'audio/notification.mp3',
371
+ });
372
+
373
+ // With volume control
374
+ await NativeAudio.playOnce({
375
+ assetPath: 'audio/beep.wav',
376
+ volume: 0.8,
377
+ });
378
+
379
+ // Remote audio with notification metadata
380
+ await NativeAudio.playOnce({
381
+ assetPath: 'https://example.com/audio.mp3',
382
+ isUrl: true,
383
+ autoPlay: true,
384
+ notificationMetadata: {
385
+ title: 'Song Name',
386
+ artist: 'Artist Name',
387
+ }
388
+ });
389
+
390
+ // Temporary file with automatic deletion
391
+ await NativeAudio.playOnce({
392
+ assetPath: 'file:///path/to/temp-audio.wav',
393
+ deleteAfterPlay: true, // File deleted after playback completes
394
+ volume: 0.5,
395
+ });
396
+ ```
397
+
398
+ #### Advanced: Manual Control
399
+
400
+ If you need to control playback timing, set `autoPlay: false` and use the returned `assetId`:
401
+
402
+ ```typescript
403
+ const { assetId } = await NativeAudio.playOnce({
404
+ assetPath: 'audio/sound.wav',
405
+ autoPlay: false,
406
+ });
407
+
408
+ // Play later when needed
409
+ await NativeAudio.play({ assetId });
410
+
411
+ // Stop if needed (will auto-cleanup)
412
+ await NativeAudio.stop({ assetId });
413
+ ```
414
+
415
+ **Key Features:**
416
+ - ✅ Automatic asset loading and unloading
417
+ - ✅ Cleanup on completion or error
418
+ - ✅ Optional file deletion after playback
419
+ - ✅ Notification metadata support
420
+ - ✅ Works with local files and remote URLs
421
+
422
+ **Notes:**
423
+ - Assets are automatically cleaned up after playback completes or on error
424
+ - `deleteAfterPlay` only works for local `file://` URLs, not remote URLs
425
+ - The returned `assetId` can be used with `play()`, `stop()`, `unload()` methods
426
+ - Manual cleanup via `stop()` or `unload()` is optional but supported
427
+
428
+ ## Example app
429
+
430
+ This repository now ships with an interactive Capacitor project under `example-app/` that exercises the main APIs on web, iOS, and Android shells.
431
+
432
+ ```bash
433
+ cd example-app
434
+ bun install
435
+ bun run dev # start the web playground
436
+ bun run sync # optional: generate iOS/Android platforms
437
+ bun run ios # open the iOS shell app
438
+ bun run android # open the Android shell app
439
+ ```
440
+
441
+ The UI demonstrates local asset preloading, remote streaming, playback controls, looping, live position updates, and cache clearing for remote audio.
442
+
443
+ ```typescript
444
+ import {NativeAudio} from '@capgo/capacitor-native-audio'
445
+
446
+
447
+ /**
448
+ * This method will load more optimized audio files for background into memory.
449
+ * @param assetPath - relative path of the file, absolute url (file://) or remote url (https://)
450
+ * assetId - unique identifier of the file
451
+ * audioChannelNum - number of audio channels
452
+ * isUrl - pass true if assetPath is a `file://` url
453
+ * @returns void
454
+ */
455
+ NativeAudio.preload({
456
+ assetId: "fire",
457
+ assetPath: "assets/sounds/fire.mp3",
458
+ audioChannelNum: 1,
459
+ isUrl: false
460
+ });
461
+
462
+ /**
463
+ * This method will play the loaded audio file if present in the memory.
464
+ * @param assetId - identifier of the asset
465
+ * @param time - (optional) play with seek. example: 6.0 - start playing track from 6 sec
466
+ * @param delay - (optional) delay the audio. default is 0s
467
+ * @param fadeIn - (optional) whether fade in the audio. default is false
468
+ * @param fadeOut - (optional) whether fade out the audio. default is false
469
+ * @param fadeInDuration - (optional) fade in duration in seconds. only used if fadeIn is true. default is 1s
470
+ * @param fadeOutDuration - (optional) fade out duration in seconds. only used if fadeOut is true. default is 1s
471
+ * @param fadeOutStartTime - (optional) time in seconds from the start of the audio to start fading out. only used if fadeOut is true. default is fadeOutDuration before end of audio.
472
+ * @returns void
473
+ */
474
+ NativeAudio.play({
475
+ assetId: 'fire',
476
+ // time: 6.0 - seek time
477
+ // volume: 0.4,
478
+ // delay: 1.0,
479
+ // fadeIn: true,
480
+ // fadeOut: true,
481
+ // fadeInDuration: 2,
482
+ // fadeOutDuration: 2
483
+ // fadeOutStartTime: 2
484
+ });
485
+
486
+ /**
487
+ * This method will loop the audio file for playback.
488
+ * @param assetId - identifier of the asset
489
+ * @returns void
490
+ */
491
+ NativeAudio.loop({
492
+ assetId: 'fire',
493
+ });
494
+
495
+
496
+ /**
497
+ * This method will stop the audio file if it's currently playing.
498
+ * @param assetId - identifier of the asset
499
+ * @param fadeOut - (optional) whether fade out the audio before stopping. default is false
500
+ * @param fadeOutDuration - (optional) fade out duration in seconds. default is 1s
501
+ * @returns void
502
+ */
503
+ NativeAudio.stop({
504
+ assetId: 'fire',
505
+ // fadeOut: true,
506
+ // fadeOutDuration: 2
507
+ });
508
+
509
+ /**
510
+ * This method will unload the audio file from the memory.
511
+ * @param assetId - identifier of the asset
512
+ * @returns void
513
+ */
514
+ NativeAudio.unload({
515
+ assetId: 'fire',
516
+ });
517
+
518
+ /**
519
+ * This method will set the new volume for a audio file.
520
+ * @param assetId - identifier of the asset
521
+ * volume - numerical value of the volume between 0.1 - 1.0 default 1.0
522
+ * duration - time over which to fade to the target volume, in seconds. default is 0s (immediate)
523
+ * @returns void
524
+ */
525
+ NativeAudio.setVolume({
526
+ assetId: 'fire',
527
+ volume: 0.4,
528
+ // duration: 2
529
+ });
530
+
531
+ /**
532
+ * this method will get the duration of an audio file.
533
+ * only works if channels == 1
534
+ */
535
+ NativeAudio.getDuration({
536
+ assetId: 'fire'
537
+ })
538
+ .then(result => {
539
+ console.log(result.duration);
540
+ })
541
+
542
+ /**
543
+ * this method will get the current time of a playing audio file.
544
+ * only works if channels == 1
545
+ */
546
+ NativeAudio.getCurrentTime({
547
+ assetId: 'fire'
548
+ })
549
+ .then(result => {
550
+ console.log(result.currentTime);
551
+ })
552
+
553
+ /**
554
+ * this method will set the current time of a playing audio file.
555
+ * @param assetId - identifier of the asset
556
+ * time - time to set the audio, in seconds
557
+ */
558
+ NativeAudio.setCurrentTime({
559
+ assetId: 'fire',
560
+ time: 6.0
561
+ })
562
+
563
+ /**
564
+ * This method will return false if audio is paused or not loaded.
565
+ * @param assetId - identifier of the asset
566
+ * @returns {isPlaying: boolean}
567
+ */
568
+ NativeAudio.isPlaying({
569
+ assetId: 'fire'
570
+ })
571
+ .then(result => {
572
+ console.log(result.isPlaying);
573
+ })
574
+ ```
575
+
576
+ ## API
577
+
578
+ <docgen-index>
579
+
580
+ <docgen-api>
581
+ <!--Update the source file JSDoc comments and rerun docgen to update the docs below-->
582
+
583
+ ### configure(...)
584
+
585
+ ```typescript
586
+ configure(options: ConfigureOptions) => Promise<void>
587
+ ```
588
+
589
+ Configure the audio player
590
+
591
+ | Param | Type |
592
+ | ------------- | ------------------------------------------------------------- |
593
+ | **`options`** | <code><a href="#configureoptions">ConfigureOptions</a></code> |
594
+
595
+ **Since:** 5.0.0
596
+
597
+ --------------------
598
+
599
+
600
+ ### preload(...)
601
+
602
+ ```typescript
603
+ preload(options: PreloadOptions) => Promise<void>
604
+ ```
605
+
606
+ Load an audio file
607
+
608
+ | Param | Type |
609
+ | ------------- | --------------------------------------------------------- |
610
+ | **`options`** | <code><a href="#preloadoptions">PreloadOptions</a></code> |
611
+
612
+ **Since:** 5.0.0
613
+
614
+ --------------------
615
+
616
+
617
+ ### playOnce(...)
618
+
619
+ ```typescript
620
+ playOnce(options: PlayOnceOptions) => Promise<PlayOnceResult>
621
+ ```
622
+
623
+ Play an audio file once with automatic cleanup
624
+
625
+ Method designed for simple, single-shot audio playback,
626
+ such as notification sounds, UI feedback, or other short audio clips
627
+ that don't require manual state management.
628
+
629
+ **Key Features:**
630
+ - **Fire-and-forget**: No need to manually preload, play, stop, or unload
631
+ - **Auto-cleanup**: Asset is automatically unloaded after playback completes
632
+ - **Optional file deletion**: Can delete local files after playback (useful for temp files)
633
+ - **Returns assetId**: Can still control playback if needed (pause, stop, etc.)
634
+
635
+ **Use Cases:**
636
+ - Notification sounds
637
+ - UI sound effects (button clicks, alerts)
638
+ - Short audio clips that play once
639
+ - Temporary audio files that should be cleaned up
640
+
641
+ **Comparison with regular play():**
642
+ - `play()`: Requires manual preload, play, and unload steps
643
+ - `playOnce()`: Handles everything automatically with a single call
644
+
645
+ | Param | Type |
646
+ | ------------- | ----------------------------------------------------------- |
647
+ | **`options`** | <code><a href="#playonceoptions">PlayOnceOptions</a></code> |
648
+
649
+ **Returns:** <code>Promise&lt;<a href="#playonceresult">PlayOnceResult</a>&gt;</code>
650
+
651
+ **Since:** 7.11.0
652
+
653
+ --------------------
654
+
655
+
656
+ ### isPreloaded(...)
657
+
658
+ ```typescript
659
+ isPreloaded(options: PreloadOptions) => Promise<{ found: boolean; }>
660
+ ```
661
+
662
+ Check if an audio file is preloaded
663
+
664
+ | Param | Type |
665
+ | ------------- | --------------------------------------------------------- |
666
+ | **`options`** | <code><a href="#preloadoptions">PreloadOptions</a></code> |
667
+
668
+ **Returns:** <code>Promise&lt;{ found: boolean; }&gt;</code>
669
+
670
+ **Since:** 6.1.0
671
+
672
+ --------------------
673
+
674
+
675
+ ### play(...)
676
+
677
+ ```typescript
678
+ play(options: AssetPlayOptions) => Promise<void>
679
+ ```
680
+
681
+ Play an audio file
682
+
683
+ | Param | Type |
684
+ | ------------- | ------------------------------------------------------------- |
685
+ | **`options`** | <code><a href="#assetplayoptions">AssetPlayOptions</a></code> |
686
+
687
+ **Since:** 5.0.0
688
+
689
+ --------------------
690
+
691
+
692
+ ### pause(...)
693
+
694
+ ```typescript
695
+ pause(options: AssetPauseOptions) => Promise<void>
696
+ ```
697
+
698
+ Pause an audio file
699
+
700
+ | Param | Type |
701
+ | ------------- | --------------------------------------------------------------- |
702
+ | **`options`** | <code><a href="#assetpauseoptions">AssetPauseOptions</a></code> |
703
+
704
+ **Since:** 5.0.0
705
+
706
+ --------------------
707
+
708
+
709
+ ### resume(...)
710
+
711
+ ```typescript
712
+ resume(options: AssetResumeOptions) => Promise<void>
713
+ ```
714
+
715
+ Resume an audio file
716
+
717
+ | Param | Type |
718
+ | ------------- | ----------------------------------------------------------------- |
719
+ | **`options`** | <code><a href="#assetresumeoptions">AssetResumeOptions</a></code> |
720
+
721
+ **Since:** 5.0.0
722
+
723
+ --------------------
724
+
725
+
726
+ ### loop(...)
727
+
728
+ ```typescript
729
+ loop(options: Assets) => Promise<void>
730
+ ```
731
+
732
+ Stop an audio file
733
+
734
+ | Param | Type |
735
+ | ------------- | ----------------------------------------- |
736
+ | **`options`** | <code><a href="#assets">Assets</a></code> |
737
+
738
+ **Since:** 5.0.0
739
+
740
+ --------------------
741
+
742
+
743
+ ### stop(...)
744
+
745
+ ```typescript
746
+ stop(options: AssetStopOptions) => Promise<void>
747
+ ```
748
+
749
+ Stop an audio file
750
+
751
+ | Param | Type |
752
+ | ------------- | ------------------------------------------------------------- |
753
+ | **`options`** | <code><a href="#assetstopoptions">AssetStopOptions</a></code> |
754
+
755
+ **Since:** 5.0.0
756
+
757
+ --------------------
758
+
759
+
760
+ ### unload(...)
761
+
762
+ ```typescript
763
+ unload(options: Assets) => Promise<void>
764
+ ```
765
+
766
+ Unload an audio file
767
+
768
+ | Param | Type |
769
+ | ------------- | ----------------------------------------- |
770
+ | **`options`** | <code><a href="#assets">Assets</a></code> |
771
+
772
+ **Since:** 5.0.0
773
+
774
+ --------------------
775
+
776
+
777
+ ### setVolume(...)
778
+
779
+ ```typescript
780
+ setVolume(options: AssetVolume) => Promise<void>
781
+ ```
782
+
783
+ Set the volume of an audio file
784
+
785
+ | Param | Type |
786
+ | ------------- | --------------------------------------------------- |
787
+ | **`options`** | <code><a href="#assetvolume">AssetVolume</a></code> |
788
+
789
+ **Since:** 5.0.0
790
+
791
+ --------------------
792
+
793
+
794
+ ### setRate(...)
795
+
796
+ ```typescript
797
+ setRate(options: AssetRate) => Promise<void>
798
+ ```
799
+
800
+ Set the rate of an audio file
801
+
802
+ | Param | Type |
803
+ | ------------- | ----------------------------------------------- |
804
+ | **`options`** | <code><a href="#assetrate">AssetRate</a></code> |
805
+
806
+ **Since:** 5.0.0
807
+
808
+ --------------------
809
+
810
+
811
+ ### setCurrentTime(...)
812
+
813
+ ```typescript
814
+ setCurrentTime(options: AssetSetTime) => Promise<void>
815
+ ```
816
+
817
+ Set the current time of an audio file
818
+
819
+ | Param | Type |
820
+ | ------------- | ----------------------------------------------------- |
821
+ | **`options`** | <code><a href="#assetsettime">AssetSetTime</a></code> |
822
+
823
+ **Since:** 6.5.0
824
+
825
+ --------------------
826
+
827
+
828
+ ### getCurrentTime(...)
829
+
830
+ ```typescript
831
+ getCurrentTime(options: Assets) => Promise<{ currentTime: number; }>
832
+ ```
833
+
834
+ Get the current time of an audio file
835
+
836
+ | Param | Type |
837
+ | ------------- | ----------------------------------------- |
838
+ | **`options`** | <code><a href="#assets">Assets</a></code> |
839
+
840
+ **Returns:** <code>Promise&lt;{ currentTime: number; }&gt;</code>
841
+
842
+ **Since:** 5.0.0
843
+
844
+ --------------------
845
+
846
+
847
+ ### getDuration(...)
848
+
849
+ ```typescript
850
+ getDuration(options: Assets) => Promise<{ duration: number; }>
851
+ ```
852
+
853
+ Get the duration of an audio file in seconds
854
+
855
+ | Param | Type |
856
+ | ------------- | ----------------------------------------- |
857
+ | **`options`** | <code><a href="#assets">Assets</a></code> |
858
+
859
+ **Returns:** <code>Promise&lt;{ duration: number; }&gt;</code>
860
+
861
+ **Since:** 5.0.0
862
+
863
+ --------------------
864
+
865
+
866
+ ### isPlaying(...)
867
+
868
+ ```typescript
869
+ isPlaying(options: Assets) => Promise<{ isPlaying: boolean; }>
870
+ ```
871
+
872
+ Check if an audio file is playing
873
+
874
+ | Param | Type |
875
+ | ------------- | ----------------------------------------- |
876
+ | **`options`** | <code><a href="#assets">Assets</a></code> |
877
+
878
+ **Returns:** <code>Promise&lt;{ isPlaying: boolean; }&gt;</code>
879
+
880
+ **Since:** 5.0.0
881
+
882
+ --------------------
883
+
884
+
885
+ ### addListener('complete', ...)
886
+
887
+ ```typescript
888
+ addListener(eventName: 'complete', listenerFunc: CompletedListener) => Promise<PluginListenerHandle>
889
+ ```
890
+
891
+ Listen for complete event
892
+
893
+ | Param | Type |
894
+ | ------------------ | --------------------------------------------------------------- |
895
+ | **`eventName`** | <code>'complete'</code> |
896
+ | **`listenerFunc`** | <code><a href="#completedlistener">CompletedListener</a></code> |
897
+
898
+ **Returns:** <code>Promise&lt;<a href="#pluginlistenerhandle">PluginListenerHandle</a>&gt;</code>
899
+
900
+ **Since:** 5.0.0
901
+ return {@link CompletedEvent}
902
+
903
+ --------------------
904
+
905
+
906
+ ### addListener('currentTime', ...)
907
+
908
+ ```typescript
909
+ addListener(eventName: 'currentTime', listenerFunc: CurrentTimeListener) => Promise<PluginListenerHandle>
910
+ ```
911
+
912
+ Listen for current time updates
913
+ Emits every 100ms while audio is playing
914
+
915
+ | Param | Type |
916
+ | ------------------ | ------------------------------------------------------------------- |
917
+ | **`eventName`** | <code>'currentTime'</code> |
918
+ | **`listenerFunc`** | <code><a href="#currenttimelistener">CurrentTimeListener</a></code> |
919
+
920
+ **Returns:** <code>Promise&lt;<a href="#pluginlistenerhandle">PluginListenerHandle</a>&gt;</code>
921
+
922
+ **Since:** 6.5.0
923
+ return {@link CurrentTimeEvent}
924
+
925
+ --------------------
926
+
927
+
928
+ ### addListener('playbackState', ...)
929
+
930
+ ```typescript
931
+ addListener(eventName: 'playbackState', listenerFunc: PlaybackStateListener) => Promise<PluginListenerHandle>
932
+ ```
933
+
934
+ Listen for playback state changes, including notification and lock-screen transport controls.
935
+ Emitted by Android and iOS. The current Web implementation does not emit this event.
936
+
937
+ | Param | Type |
938
+ | ------------------ | ----------------------------------------------------------------------- |
939
+ | **`eventName`** | <code>'playbackState'</code> |
940
+ | **`listenerFunc`** | <code><a href="#playbackstatelistener">PlaybackStateListener</a></code> |
941
+
942
+ **Returns:** <code>Promise&lt;<a href="#pluginlistenerhandle">PluginListenerHandle</a>&gt;</code>
943
+
944
+ **Since:** 8.3.15
945
+ return {@link PlaybackStateEvent}
946
+
947
+ --------------------
948
+
949
+
950
+ ### clearCache()
951
+
952
+ ```typescript
953
+ clearCache() => Promise<void>
954
+ ```
955
+
956
+ Clear the audio cache for remote audio files
957
+
958
+ **Since:** 6.5.0
959
+
960
+ --------------------
961
+
962
+
963
+ ### setDebugMode(...)
964
+
965
+ ```typescript
966
+ setDebugMode(options: { enabled: boolean; }) => Promise<void>
967
+ ```
968
+
969
+ Set debug mode logging
970
+
971
+ | Param | Type | Description |
972
+ | ------------- | ---------------------------------- | ----------------------------------------- |
973
+ | **`options`** | <code>{ enabled: boolean; }</code> | - Options to enable or disable debug mode |
974
+
975
+ **Since:** 6.5.0
976
+
977
+ --------------------
978
+
979
+
980
+ ### getPluginVersion()
981
+
982
+ ```typescript
983
+ getPluginVersion() => Promise<{ version: string; }>
984
+ ```
985
+
986
+ Get the native Capacitor plugin version
987
+
988
+ **Returns:** <code>Promise&lt;{ version: string; }&gt;</code>
989
+
990
+ --------------------
991
+
992
+
993
+ ### deinitPlugin()
994
+
995
+ ```typescript
996
+ deinitPlugin() => Promise<void>
997
+ ```
998
+
999
+ Deinitialize the plugin and restore original audio session settings
1000
+ This method stops all playing audio and reverts any audio session changes made by the plugin
1001
+ Use this when you need to ensure compatibility with other audio plugins
1002
+
1003
+ **Since:** 7.7.0
1004
+
1005
+ --------------------
1006
+
1007
+
1008
+ ### Interfaces
1009
+
1010
+
1011
+ #### ConfigureOptions
1012
+
1013
+ | Prop | Type | Description | Default | Since |
1014
+ | ------------------------ | -------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------ | ----- |
1015
+ | **`focus`** | <code>boolean</code> | focus the audio with Audio Focus | | |
1016
+ | **`background`** | <code>boolean</code> | Play the audio in the background | | |
1017
+ | **`ignoreSilent`** | <code>boolean</code> | Ignore silent mode, works only on iOS setting this will nuke other audio apps | | |
1018
+ | **`showNotification`** | <code>boolean</code> | Show audio playback in the notification center (iOS and Android) When enabled, displays audio metadata (title, artist, album, artwork) in the system notification and Control Center (iOS) or lock screen. **Important iOS Behavior:** Enabling this option changes the audio session category to `.playback` with `.default` mode, which means your app's audio will **interrupt** other apps' audio (like background music from Spotify, Apple Music, etc.) instead of mixing with it. This is required for the Now Playing info to appear in Control Center and on the lock screen. **Trade-offs:** - `showNotification: true` → Shows Now Playing controls, but interrupts other audio - `showNotification: false` → Audio mixes with other apps, but no Now Playing controls Use this when your app is the primary audio source (music players, podcast apps, etc.). Disable this for secondary audio like sound effects or notification sounds where mixing with background music is preferred. | | |
1019
+ | **`backgroundPlayback`** | <code>boolean</code> | Enable background audio playback (Android only) When enabled, audio will continue playing when the app is backgrounded or the screen is locked. The plugin will skip the automatic pause/resume logic that normally occurs when the app enters the background or returns to the foreground. **Important Android Requirements:** To use background playback on Android, your app must: 1. Declare the required permissions in `AndroidManifest.xml`: - `&lt;uses-permission android:name="android.permission.FOREGROUND_SERVICE" /&gt;` - `&lt;uses-permission android:name="android.permission.FOREGROUND_SERVICE_MEDIA_PLAYBACK" /&gt;` - `&lt;uses-permission android:name="android.permission.WAKE_LOCK" /&gt;` 2. Start a Foreground Service with a media-style notification before backgrounding (the plugin does not automatically create or manage the foreground service) 3. Use `showNotification: true` to display playback controls in the notification **Usage Example:** ```typescript await NativeAudio.configure({ backgroundPlayback: true, showNotification: true }); // Start your foreground service here // Then preload and play audio as normal ``` | <code>false</code> | 8.2.0 |
1020
+
1021
+
1022
+ #### PreloadOptions
1023
+
1024
+ | Prop | Type | Description | Since |
1025
+ | -------------------------- | --------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------ |
1026
+ | **`assetPath`** | <code>string</code> | Path to the audio file, relative path of the file, absolute url (file://) or remote url (https://) Supported formats: - MP3, WAV (all platforms) - M3U8/HLS streams (iOS and Android) | |
1027
+ | **`assetId`** | <code>string</code> | Asset Id, unique identifier of the file | |
1028
+ | **`volume`** | <code>number</code> | Volume of the audio, between 0.1 and 1.0 | |
1029
+ | **`audioChannelNum`** | <code>number</code> | Audio channel number, default is 1 | |
1030
+ | **`isUrl`** | <code>boolean</code> | Is the audio file a URL, pass true if assetPath is a `file://` url or a streaming URL (m3u8) | |
1031
+ | **`notificationMetadata`** | <code><a href="#notificationmetadata">NotificationMetadata</a></code> | Metadata to display in the notification center when audio is playing. Only used when `showNotification: true` is set in `configure()`. See {@link <a href="#configureoptions">ConfigureOptions.showNotification</a>} for important details about how this affects audio mixing behavior on iOS. | |
1032
+ | **`headers`** | <code><a href="#record">Record</a>&lt;string, string&gt;</code> | Custom HTTP headers to include when fetching remote audio files. Only used when isUrl is true and assetPath is a remote URL (http/https). Example: { 'x-api-key': 'abc123', 'Authorization': 'Bearer token' } | 7.10.0 |
1033
+
1034
+
1035
+ #### NotificationMetadata
1036
+
1037
+ Metadata to display in the notification center, Control Center (iOS), and lock screen
1038
+ when `showNotification` is enabled in `configure()`.
1039
+
1040
+ Note: This metadata will only be displayed if `showNotification: true` is set in the
1041
+ `configure()` method. See {@link <a href="#configureoptions">ConfigureOptions.showNotification</a>} for important
1042
+ behavior details about audio mixing on iOS.
1043
+
1044
+ | Prop | Type | Description |
1045
+ | ---------------- | ------------------- | ----------------------------------------------------- |
1046
+ | **`title`** | <code>string</code> | The title to display in the notification center |
1047
+ | **`artist`** | <code>string</code> | The artist name to display in the notification center |
1048
+ | **`album`** | <code>string</code> | The album name to display in the notification center |
1049
+ | **`artworkUrl`** | <code>string</code> | URL or local path to the artwork/album art image |
1050
+
1051
+
1052
+ #### PlayOnceResult
1053
+
1054
+ | Prop | Type | Description |
1055
+ | ------------- | ------------------- | ------------------------------------------------------------------------------------------------------------------------- |
1056
+ | **`assetId`** | <code>string</code> | The internally generated asset ID for this playback Can be used to control playback (pause, stop, etc.) before completion |
1057
+
1058
+
1059
+ #### PlayOnceOptions
1060
+
1061
+ | Prop | Type | Description | Default | Since |
1062
+ | -------------------------- | --------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------ | ------ |
1063
+ | **`assetPath`** | <code>string</code> | Path to the audio file, relative path of the file, absolute url (file://) or remote url (https://) Supported formats: - MP3, WAV (all platforms) - M3U8/HLS streams (iOS and Android) | | |
1064
+ | **`volume`** | <code>number</code> | Volume of the audio, between 0.1 and 1.0 | <code>1.0</code> | |
1065
+ | **`isUrl`** | <code>boolean</code> | Is the audio file a URL, pass true if assetPath is a `file://` url or a streaming URL (m3u8) | <code>false</code> | |
1066
+ | **`autoPlay`** | <code>boolean</code> | Automatically start playback after loading | <code>true</code> | |
1067
+ | **`deleteAfterPlay`** | <code>boolean</code> | Delete the audio file from disk after playback completes Only works for local files (file:// URLs), ignored for remote URLs | <code>false</code> | 7.11.0 |
1068
+ | **`notificationMetadata`** | <code><a href="#notificationmetadata">NotificationMetadata</a></code> | Metadata to display in the notification center when audio is playing. Only used when `showNotification: true` is set in `configure()`. See {@link <a href="#configureoptions">ConfigureOptions.showNotification</a>} for important details about how this affects audio mixing behavior on iOS. | | 7.10.0 |
1069
+ | **`headers`** | <code><a href="#record">Record</a>&lt;string, string&gt;</code> | Custom HTTP headers to include when fetching remote audio files. Only used when isUrl is true and assetPath is a remote URL (http/https). Example: { 'x-api-key': 'abc123', 'Authorization': 'Bearer token' } | | 7.10.0 |
1070
+
1071
+
1072
+ #### AssetPlayOptions
1073
+
1074
+ | Prop | Type | Description |
1075
+ | ---------------------- | -------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------- |
1076
+ | **`assetId`** | <code>string</code> | Asset Id, unique identifier of the file |
1077
+ | **`time`** | <code>number</code> | Time to start playing the audio, in seconds |
1078
+ | **`delay`** | <code>number</code> | Delay to start playing the audio, in seconds |
1079
+ | **`volume`** | <code>number</code> | Volume of the audio, between 0.1 and 1.0 |
1080
+ | **`fadeIn`** | <code>boolean</code> | Whether to fade in the audio |
1081
+ | **`fadeOut`** | <code>boolean</code> | Whether to fade out the audio |
1082
+ | **`fadeInDuration`** | <code>number</code> | Fade in duration in seconds. Only used if fadeIn is true. Default is 1s. |
1083
+ | **`fadeOutDuration`** | <code>number</code> | Fade out duration in seconds. Only used if fadeOut is true. Default is 1s. |
1084
+ | **`fadeOutStartTime`** | <code>number</code> | Time in seconds from the start of the audio to start fading out. Only used if fadeOut is true. Default is fadeOutDuration before end of audio. |
1085
+
1086
+
1087
+ #### AssetPauseOptions
1088
+
1089
+ | Prop | Type | Description |
1090
+ | --------------------- | -------------------- | -------------------------------------------- |
1091
+ | **`assetId`** | <code>string</code> | Asset Id, unique identifier of the file |
1092
+ | **`fadeOut`** | <code>boolean</code> | Whether to fade out the audio before pausing |
1093
+ | **`fadeOutDuration`** | <code>number</code> | Fade out duration in seconds. Default is 1s. |
1094
+
1095
+
1096
+ #### AssetResumeOptions
1097
+
1098
+ | Prop | Type | Description |
1099
+ | -------------------- | -------------------- | ------------------------------------------- |
1100
+ | **`assetId`** | <code>string</code> | Asset Id, unique identifier of the file |
1101
+ | **`fadeIn`** | <code>boolean</code> | Whether to fade in the audio during resume |
1102
+ | **`fadeInDuration`** | <code>number</code> | Fade in duration in seconds. Default is 1s. |
1103
+
1104
+
1105
+ #### Assets
1106
+
1107
+ | Prop | Type | Description |
1108
+ | ------------- | ------------------- | --------------------------------------- |
1109
+ | **`assetId`** | <code>string</code> | Asset Id, unique identifier of the file |
1110
+
1111
+
1112
+ #### AssetStopOptions
1113
+
1114
+ | Prop | Type | Description |
1115
+ | --------------------- | -------------------- | --------------------------------------------- |
1116
+ | **`assetId`** | <code>string</code> | Asset Id, unique identifier of the file |
1117
+ | **`fadeOut`** | <code>boolean</code> | Whether to fade out the audio before stopping |
1118
+ | **`fadeOutDuration`** | <code>number</code> | Fade out duration in seconds. Default is 1s. |
1119
+
1120
+
1121
+ #### AssetVolume
1122
+
1123
+ | Prop | Type | Description |
1124
+ | -------------- | ------------------- | ------------------------------------------------------------------------------------ |
1125
+ | **`assetId`** | <code>string</code> | Asset Id, unique identifier of the file |
1126
+ | **`volume`** | <code>number</code> | Volume of the audio, between 0.1 and 1.0 |
1127
+ | **`duration`** | <code>number</code> | Time over which to fade to the target volume, in seconds. Default is 0s (immediate). |
1128
+
1129
+
1130
+ #### AssetRate
1131
+
1132
+ | Prop | Type | Description |
1133
+ | ------------- | ------------------- | --------------------------------------- |
1134
+ | **`assetId`** | <code>string</code> | Asset Id, unique identifier of the file |
1135
+ | **`rate`** | <code>number</code> | Rate of the audio, between 0.1 and 1.0 |
1136
+
1137
+
1138
+ #### AssetSetTime
1139
+
1140
+ | Prop | Type | Description |
1141
+ | ------------- | ------------------- | --------------------------------------- |
1142
+ | **`assetId`** | <code>string</code> | Asset Id, unique identifier of the file |
1143
+ | **`time`** | <code>number</code> | Time to set the audio, in seconds |
1144
+
1145
+
1146
+ #### PluginListenerHandle
1147
+
1148
+ | Prop | Type |
1149
+ | ------------ | ----------------------------------------- |
1150
+ | **`remove`** | <code>() =&gt; Promise&lt;void&gt;</code> |
1151
+
1152
+
1153
+ #### CompletedEvent
1154
+
1155
+ | Prop | Type | Description | Since |
1156
+ | ------------- | ------------------- | -------------------------- | ----- |
1157
+ | **`assetId`** | <code>string</code> | Emit when a play completes | 5.0.0 |
1158
+
1159
+
1160
+ #### CurrentTimeEvent
1161
+
1162
+ | Prop | Type | Description | Since |
1163
+ | ----------------- | ------------------- | ------------------------------------ | ----- |
1164
+ | **`currentTime`** | <code>number</code> | Current time of the audio in seconds | 6.5.0 |
1165
+ | **`assetId`** | <code>string</code> | Asset Id of the audio | 6.5.0 |
1166
+
1167
+
1168
+ #### PlaybackStateEvent
1169
+
1170
+ | Prop | Type | Description |
1171
+ | ----------------- | ----------------------------------------------------------------- | -------------------------------------------------------------------------------------- |
1172
+ | **`assetId`** | <code>string</code> | Asset Id of the audio |
1173
+ | **`state`** | <code><a href="#playbackstatevalue">PlaybackStateValue</a></code> | Resolved playback state after a local or remote transport action. |
1174
+ | **`reason`** | <code>string</code> | Reason for the state change, for example `play`, `pause`, `remotePlay`, or `complete`. |
1175
+ | **`isPlaying`** | <code>boolean</code> | Whether the asset is currently playing. |
1176
+ | **`currentTime`** | <code>number</code> | Current playback position in seconds when available. |
1177
+ | **`duration`** | <code>number</code> | Total playback duration in seconds when available. |
1178
+
1179
+
1180
+ ### Type Aliases
1181
+
1182
+
1183
+ #### Record
1184
+
1185
+ Construct a type with a set of properties K of type T
1186
+
1187
+ <code>{
1188
  [P in K]: T;
1
1189
  }</code>
1190
+
1191
+
1192
+ #### CompletedListener
1193
+
1194
+ <code>(state: <a href="#completedevent">CompletedEvent</a>): void</code>
1195
+
1196
+
1197
+ #### CurrentTimeListener
1198
+
1199
+ <code>(state: <a href="#currenttimeevent">CurrentTimeEvent</a>): void</code>
1200
+
1201
+
1202
+ #### PlaybackStateListener
1203
+
1204
+ <code>(state: <a href="#playbackstateevent">PlaybackStateEvent</a>): void</code>
1205
+
1206
+
1207
+ #### PlaybackStateValue
1208
+
1209
+ <code>'playing' | 'paused' | 'stopped'</code>
1210
+
1211
+ </docgen-api>
1212
+
1213
+ ## Development and Testing
1214
+
1215
+ ### Building
1216
+
1217
+ ```bash
1218
+ bun run build
1219
+ ```
1220
+
1221
+ ### Testing
1222
+
1223
+ This plugin includes native unit coverage plus Maestro smoke tests for the example app on iOS and Android:
1224
+
1225
+ 1. Run plugin verification with `bun run verify`
1226
+ 2. Build and sync the example app from `example-app/`
1227
+ 3. With a booted device and the shell app installed, run the Android smoke flow with `bun run test:e2e:android`
1228
+ 4. With a booted simulator and the shell app installed, run the iOS smoke flow with `bun run test:e2e:ios`
1229
+ 5. For native unit tests in Xcode, open the example app iOS project with `cd example-app && bunx cap open ios` and run Product > Test (⌘+U)
1230
+
1231
+ The tests cover core functionality including audio asset initialization, playback, volume control, fade effects, and smoke-tested example app playback flows. See the [test documentation](ios/Tests/README.md) for more details.