@capgo/native-audio 8.2.12 → 8.2.13

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.
@@ -23,6 +23,10 @@ export interface AssetVolume {
23
23
  * Volume of the audio, between 0.1 and 1.0
24
24
  */
25
25
  volume: number;
26
+ /**
27
+ * Time over which to fade to the target volume, in seconds. Default is 0s (immediate).
28
+ */
29
+ duration?: number;
26
30
  }
27
31
  export interface AssetRate {
28
32
  /**
@@ -34,25 +38,106 @@ export interface AssetRate {
34
38
  */
35
39
  rate: number;
36
40
  }
41
+ export interface AssetSetTime {
42
+ /**
43
+ * Asset Id, unique identifier of the file
44
+ */
45
+ assetId: string;
46
+ /**
47
+ * Time to set the audio, in seconds
48
+ */
49
+ time: number;
50
+ }
37
51
  export interface AssetPlayOptions {
38
52
  /**
39
53
  * Asset Id, unique identifier of the file
40
54
  */
41
55
  assetId: string;
42
56
  /**
43
- * Time to start playing the audio, in milliseconds
57
+ * Time to start playing the audio, in seconds
44
58
  */
45
59
  time?: number;
46
60
  /**
47
- * Delay to start playing the audio, in milliseconds
61
+ * Delay to start playing the audio, in seconds
48
62
  */
49
63
  delay?: number;
64
+ /**
65
+ * Volume of the audio, between 0.1 and 1.0
66
+ */
67
+ volume?: number;
68
+ /**
69
+ * Whether to fade in the audio
70
+ */
71
+ fadeIn?: boolean;
72
+ /**
73
+ * Whether to fade out the audio
74
+ */
75
+ fadeOut?: boolean;
76
+ /**
77
+ * Fade in duration in seconds.
78
+ * Only used if fadeIn is true.
79
+ * Default is 1s.
80
+ */
81
+ fadeInDuration?: number;
82
+ /**
83
+ * Fade out duration in seconds.
84
+ * Only used if fadeOut is true.
85
+ * Default is 1s.
86
+ */
87
+ fadeOutDuration?: number;
88
+ /**
89
+ * Time in seconds from the start of the audio to start fading out.
90
+ * Only used if fadeOut is true.
91
+ * Default is fadeOutDuration before end of audio.
92
+ */
93
+ fadeOutStartTime?: number;
50
94
  }
51
- export interface ConfigureOptions {
95
+ export interface AssetStopOptions {
96
+ /**
97
+ * Asset Id, unique identifier of the file
98
+ */
99
+ assetId: string;
100
+ /**
101
+ * Whether to fade out the audio before stopping
102
+ */
103
+ fadeOut?: boolean;
104
+ /**
105
+ * Fade out duration in seconds.
106
+ * Default is 1s.
107
+ */
108
+ fadeOutDuration?: number;
109
+ }
110
+ export interface AssetPauseOptions {
111
+ /**
112
+ * Asset Id, unique identifier of the file
113
+ */
114
+ assetId: string;
115
+ /**
116
+ * Whether to fade out the audio before pausing
117
+ */
118
+ fadeOut?: boolean;
119
+ /**
120
+ * Fade out duration in seconds.
121
+ * Default is 1s.
122
+ */
123
+ fadeOutDuration?: number;
124
+ }
125
+ export interface AssetResumeOptions {
126
+ /**
127
+ * Asset Id, unique identifier of the file
128
+ */
129
+ assetId: string;
52
130
  /**
53
- * Play the audio with Fade effect, only available for IOS
131
+ * Whether to fade in the audio during resume
54
132
  */
55
- fade?: boolean;
133
+ fadeIn?: boolean;
134
+ /**
135
+ * Fade in duration in seconds.
136
+ * Default is 1s.
137
+ */
138
+ fadeInDuration?: number;
139
+ }
140
+ export interface ConfigureOptions {
56
141
  /**
57
142
  * focus the audio with Audio Focus
58
143
  */
@@ -338,28 +423,24 @@ export interface NativeAudio {
338
423
  /**
339
424
  * Play an audio file
340
425
  * @since 5.0.0
341
- * @param option {@link PlayOptions}
426
+ * @param option {@link AssetPlayOptions}
342
427
  * @returns
343
428
  */
344
- play(options: {
345
- assetId: string;
346
- time?: number;
347
- delay?: number;
348
- }): Promise<void>;
429
+ play(options: AssetPlayOptions): Promise<void>;
349
430
  /**
350
431
  * Pause an audio file
351
432
  * @since 5.0.0
352
- * @param option {@link Assets}
433
+ * @param option {@link AssetPauseOptions}
353
434
  * @returns
354
435
  */
355
- pause(options: Assets): Promise<void>;
436
+ pause(options: AssetPauseOptions): Promise<void>;
356
437
  /**
357
438
  * Resume an audio file
358
439
  * @since 5.0.0
359
- * @param option {@link Assets}
440
+ * @param option {@link AssetResumeOptions}
360
441
  * @returns
361
442
  */
362
- resume(options: Assets): Promise<void>;
443
+ resume(options: AssetResumeOptions): Promise<void>;
363
444
  /**
364
445
  * Stop an audio file
365
446
  * @since 5.0.0
@@ -370,10 +451,10 @@ export interface NativeAudio {
370
451
  /**
371
452
  * Stop an audio file
372
453
  * @since 5.0.0
373
- * @param option {@link Assets}
454
+ * @param option {@link AssetStopOptions}
374
455
  * @returns
375
456
  */
376
- stop(options: Assets): Promise<void>;
457
+ stop(options: AssetStopOptions): Promise<void>;
377
458
  /**
378
459
  * Unload an audio file
379
460
  * @since 5.0.0
@@ -387,45 +468,34 @@ export interface NativeAudio {
387
468
  * @param option {@link AssetVolume}
388
469
  * @returns {Promise<void>}
389
470
  */
390
- setVolume(options: {
391
- assetId: string;
392
- volume: number;
393
- }): Promise<void>;
471
+ setVolume(options: AssetVolume): Promise<void>;
394
472
  /**
395
473
  * Set the rate of an audio file
396
474
  * @since 5.0.0
397
- * @param option {@link AssetPlayOptions}
475
+ * @param option {@link AssetRate}
398
476
  * @returns {Promise<void>}
399
477
  */
400
- setRate(options: {
401
- assetId: string;
402
- rate: number;
403
- }): Promise<void>;
478
+ setRate(options: AssetRate): Promise<void>;
404
479
  /**
405
480
  * Set the current time of an audio file
406
481
  * @since 6.5.0
407
- * @param option {@link AssetPlayOptions}
482
+ * @param option {@link AssetSetTime}
408
483
  * @returns {Promise<void>}
409
484
  */
410
- setCurrentTime(options: {
411
- assetId: string;
412
- time: number;
413
- }): Promise<void>;
485
+ setCurrentTime(options: AssetSetTime): Promise<void>;
414
486
  /**
415
487
  * Get the current time of an audio file
416
488
  * @since 5.0.0
417
- * @param option {@link AssetPlayOptions}
489
+ * @param option {@link Assets}
418
490
  * @returns {Promise<{ currentTime: number }>}
419
491
  */
420
- getCurrentTime(options: {
421
- assetId: string;
422
- }): Promise<{
492
+ getCurrentTime(options: Assets): Promise<{
423
493
  currentTime: number;
424
494
  }>;
425
495
  /**
426
- * Get the duration of an audio file
496
+ * Get the duration of an audio file in seconds
427
497
  * @since 5.0.0
428
- * @param option {@link AssetPlayOptions}
498
+ * @param option {@link Assets}
429
499
  * @returns {Promise<{ duration: number }>}
430
500
  */
431
501
  getDuration(options: Assets): Promise<{
@@ -435,7 +505,7 @@ export interface NativeAudio {
435
505
  * Check if an audio file is playing
436
506
  *
437
507
  * @since 5.0.0
438
- * @param option {@link AssetPlayOptions}
508
+ * @param option {@link Assets}
439
509
  * @returns {Promise<boolean>}
440
510
  */
441
511
  isPlaying(options: Assets): Promise<{
@@ -462,6 +532,14 @@ export interface NativeAudio {
462
532
  * @returns {Promise<void>}
463
533
  */
464
534
  clearCache(): Promise<void>;
535
+ /**
536
+ * Set debug mode logging
537
+ * @since 6.5.0
538
+ * @param options - Options to enable or disable debug mode
539
+ */
540
+ setDebugMode(options: {
541
+ enabled: boolean;
542
+ }): Promise<void>;
465
543
  /**
466
544
  * Get the native Capacitor plugin version
467
545
  *
@@ -1 +1 @@
1
- {"version":3,"file":"definitions.js","sourceRoot":"","sources":["../../src/definitions.ts"],"names":[],"mappings":"","sourcesContent":["import type { PluginListenerHandle } from '@capacitor/core';\n\nexport interface CompletedEvent {\n /**\n * Emit when a play completes\n *\n * @since 5.0.0\n */\n assetId: string;\n}\nexport type CompletedListener = (state: CompletedEvent) => void;\nexport interface Assets {\n /**\n * Asset Id, unique identifier of the file\n */\n assetId: string;\n}\nexport interface AssetVolume {\n /**\n * Asset Id, unique identifier of the file\n */\n assetId: string;\n /**\n * Volume of the audio, between 0.1 and 1.0\n */\n volume: number;\n}\n\nexport interface AssetRate {\n /**\n * Asset Id, unique identifier of the file\n */\n assetId: string;\n /**\n * Rate of the audio, between 0.1 and 1.0\n */\n rate: number;\n}\n\nexport interface AssetPlayOptions {\n /**\n * Asset Id, unique identifier of the file\n */\n assetId: string;\n /**\n * Time to start playing the audio, in milliseconds\n */\n time?: number;\n /**\n * Delay to start playing the audio, in milliseconds\n */\n delay?: number;\n}\n\nexport interface ConfigureOptions {\n /**\n * Play the audio with Fade effect, only available for IOS\n */\n fade?: boolean;\n /**\n * focus the audio with Audio Focus\n */\n focus?: boolean;\n /**\n * Play the audio in the background\n */\n background?: boolean;\n /**\n * Ignore silent mode, works only on iOS setting this will nuke other audio apps\n */\n ignoreSilent?: boolean;\n /**\n * Show audio playback in the notification center (iOS and Android)\n * When enabled, displays audio metadata (title, artist, album, artwork) in the system notification\n * and Control Center (iOS) or lock screen.\n *\n * **Important iOS Behavior:**\n * Enabling this option changes the audio session category to `.playback` with `.default` mode,\n * which means your app's audio will **interrupt** other apps' audio (like background music from\n * Spotify, Apple Music, etc.) instead of mixing with it. This is required for the Now Playing\n * info to appear in Control Center and on the lock screen.\n *\n * **Trade-offs:**\n * - `showNotification: true` → Shows Now Playing controls, but interrupts other audio\n * - `showNotification: false` → Audio mixes with other apps, but no Now Playing controls\n *\n * Use this when your app is the primary audio source (music players, podcast apps, etc.).\n * Disable this for secondary audio like sound effects or notification sounds where mixing\n * with background music is preferred.\n *\n * @see https://github.com/Cap-go/capacitor-native-audio/issues/202\n */\n showNotification?: boolean;\n /**\n * Enable background audio playback (Android only)\n *\n * When enabled, audio will continue playing when the app is backgrounded or the screen is locked.\n * The plugin will skip the automatic pause/resume logic that normally occurs when the app\n * enters the background or returns to the foreground.\n *\n * **Important Android Requirements:**\n * To use background playback on Android, your app must:\n * 1. Declare the required permissions in `AndroidManifest.xml`:\n * - `<uses-permission android:name=\"android.permission.FOREGROUND_SERVICE\" />`\n * - `<uses-permission android:name=\"android.permission.FOREGROUND_SERVICE_MEDIA_PLAYBACK\" />`\n * - `<uses-permission android:name=\"android.permission.WAKE_LOCK\" />`\n * 2. Start a Foreground Service with a media-style notification before backgrounding\n * (the plugin does not automatically create or manage the foreground service)\n * 3. Use `showNotification: true` to display playback controls in the notification\n *\n * **Usage Example:**\n * ```typescript\n * await NativeAudio.configure({\n * backgroundPlayback: true,\n * showNotification: true\n * });\n * // Start your foreground service here\n * // Then preload and play audio as normal\n * ```\n *\n * @default false\n * @platform Android\n * @since 8.2.0\n */\n backgroundPlayback?: boolean;\n}\n\n/**\n * Metadata to display in the notification center, Control Center (iOS), and lock screen\n * when `showNotification` is enabled in `configure()`.\n *\n * Note: This metadata will only be displayed if `showNotification: true` is set in the\n * `configure()` method. See {@link ConfigureOptions.showNotification} for important\n * behavior details about audio mixing on iOS.\n */\nexport interface NotificationMetadata {\n /**\n * The title to display in the notification center\n */\n title?: string;\n /**\n * The artist name to display in the notification center\n */\n artist?: string;\n /**\n * The album name to display in the notification center\n */\n album?: string;\n /**\n * URL or local path to the artwork/album art image\n */\n artworkUrl?: string;\n}\n\nexport interface PlayOnceOptions {\n /**\n * Path to the audio file, relative path of the file, absolute url (file://) or remote url (https://)\n * Supported formats:\n * - MP3, WAV (all platforms)\n * - M3U8/HLS streams (iOS and Android)\n */\n assetPath: string;\n /**\n * Volume of the audio, between 0.1 and 1.0\n * @default 1.0\n */\n volume?: number;\n /**\n * Is the audio file a URL, pass true if assetPath is a `file://` url\n * or a streaming URL (m3u8)\n * @default false\n */\n isUrl?: boolean;\n /**\n * Automatically start playback after loading\n * @default true\n */\n autoPlay?: boolean;\n /**\n * Delete the audio file from disk after playback completes\n * Only works for local files (file:// URLs), ignored for remote URLs\n * @default false\n * @since 7.11.0\n */\n deleteAfterPlay?: boolean;\n /**\n * Metadata to display in the notification center when audio is playing.\n * Only used when `showNotification: true` is set in `configure()`.\n *\n * See {@link ConfigureOptions.showNotification} for important details about\n * how this affects audio mixing behavior on iOS.\n *\n * @see NotificationMetadata\n * @since 7.10.0\n */\n notificationMetadata?: NotificationMetadata;\n /**\n * Custom HTTP headers to include when fetching remote audio files.\n * Only used when isUrl is true and assetPath is a remote URL (http/https).\n * Example: { 'x-api-key': 'abc123', 'Authorization': 'Bearer token' }\n *\n * @since 7.10.0\n */\n headers?: Record<string, string>;\n}\n\nexport interface PlayOnceResult {\n /**\n * The internally generated asset ID for this playback\n * Can be used to control playback (pause, stop, etc.) before completion\n */\n assetId: string;\n}\n\nexport interface PreloadOptions {\n /**\n * Path to the audio file, relative path of the file, absolute url (file://) or remote url (https://)\n * Supported formats:\n * - MP3, WAV (all platforms)\n * - M3U8/HLS streams (iOS and Android)\n */\n assetPath: string;\n /**\n * Asset Id, unique identifier of the file\n */\n assetId: string;\n /**\n * Volume of the audio, between 0.1 and 1.0\n */\n volume?: number;\n /**\n * Audio channel number, default is 1\n */\n audioChannelNum?: number;\n /**\n * Is the audio file a URL, pass true if assetPath is a `file://` url\n * or a streaming URL (m3u8)\n */\n isUrl?: boolean;\n /**\n * Metadata to display in the notification center when audio is playing.\n * Only used when `showNotification: true` is set in `configure()`.\n *\n * See {@link ConfigureOptions.showNotification} for important details about\n * how this affects audio mixing behavior on iOS.\n *\n * @see NotificationMetadata\n */\n notificationMetadata?: NotificationMetadata;\n /**\n * Custom HTTP headers to include when fetching remote audio files.\n * Only used when isUrl is true and assetPath is a remote URL (http/https).\n * Example: { 'x-api-key': 'abc123', 'Authorization': 'Bearer token' }\n *\n * @since 7.10.0\n */\n headers?: Record<string, string>;\n}\n\nexport interface CurrentTimeEvent {\n /**\n * Current time of the audio in seconds\n * @since 6.5.0\n */\n currentTime: number;\n /**\n * Asset Id of the audio\n * @since 6.5.0\n */\n assetId: string;\n}\nexport type CurrentTimeListener = (state: CurrentTimeEvent) => void;\n\nexport interface NativeAudio {\n /**\n * Configure the audio player\n * @since 5.0.0\n * @param option {@link ConfigureOptions}\n * @returns\n */\n configure(options: ConfigureOptions): Promise<void>;\n /**\n * Load an audio file\n * @since 5.0.0\n * @param option {@link PreloadOptions}\n * @returns\n */\n preload(options: PreloadOptions): Promise<void>;\n /**\n * Play an audio file once with automatic cleanup\n *\n * Method designed for simple, single-shot audio playback,\n * such as notification sounds, UI feedback, or other short audio clips\n * that don't require manual state management.\n *\n * **Key Features:**\n * - **Fire-and-forget**: No need to manually preload, play, stop, or unload\n * - **Auto-cleanup**: Asset is automatically unloaded after playback completes\n * - **Optional file deletion**: Can delete local files after playback (useful for temp files)\n * - **Returns assetId**: Can still control playback if needed (pause, stop, etc.)\n *\n * **Use Cases:**\n * - Notification sounds\n * - UI sound effects (button clicks, alerts)\n * - Short audio clips that play once\n * - Temporary audio files that should be cleaned up\n *\n * **Comparison with regular play():**\n * - `play()`: Requires manual preload, play, and unload steps\n * - `playOnce()`: Handles everything automatically with a single call\n *\n * @example\n * ```typescript\n * // Simple one-shot playback\n * await NativeAudio.playOnce({ assetPath: 'audio/notification.mp3' });\n *\n * // Play and delete the file after completion\n * await NativeAudio.playOnce({\n * assetPath: 'file:///path/to/temp/audio.mp3',\n * isUrl: true,\n * deleteAfterPlay: true\n * });\n *\n * // Get the assetId to control playback\n * const { assetId } = await NativeAudio.playOnce({\n * assetPath: 'audio/long-track.mp3',\n * autoPlay: true\n * });\n * // Later, you can stop it manually if needed\n * await NativeAudio.stop({ assetId });\n * ```\n *\n * @since 7.11.0\n * @param options {@link PlayOnceOptions}\n * @returns {Promise<PlayOnceResult>} Object containing the generated assetId\n */\n playOnce(options: PlayOnceOptions): Promise<PlayOnceResult>;\n /**\n * Check if an audio file is preloaded\n *\n * @since 6.1.0\n * @param option {@link Assets}\n * @returns {Promise<boolean>}\n */\n isPreloaded(options: PreloadOptions): Promise<{ found: boolean }>;\n /**\n * Play an audio file\n * @since 5.0.0\n * @param option {@link PlayOptions}\n * @returns\n */\n play(options: { assetId: string; time?: number; delay?: number }): Promise<void>;\n /**\n * Pause an audio file\n * @since 5.0.0\n * @param option {@link Assets}\n * @returns\n */\n pause(options: Assets): Promise<void>;\n /**\n * Resume an audio file\n * @since 5.0.0\n * @param option {@link Assets}\n * @returns\n */\n resume(options: Assets): Promise<void>;\n /**\n * Stop an audio file\n * @since 5.0.0\n * @param option {@link Assets}\n * @returns\n */\n loop(options: Assets): Promise<void>;\n /**\n * Stop an audio file\n * @since 5.0.0\n * @param option {@link Assets}\n * @returns\n */\n stop(options: Assets): Promise<void>;\n /**\n * Unload an audio file\n * @since 5.0.0\n * @param option {@link Assets}\n * @returns\n */\n unload(options: Assets): Promise<void>;\n /**\n * Set the volume of an audio file\n * @since 5.0.0\n * @param option {@link AssetVolume}\n * @returns {Promise<void>}\n */\n setVolume(options: { assetId: string; volume: number }): Promise<void>;\n /**\n * Set the rate of an audio file\n * @since 5.0.0\n * @param option {@link AssetPlayOptions}\n * @returns {Promise<void>}\n */\n setRate(options: { assetId: string; rate: number }): Promise<void>;\n /**\n * Set the current time of an audio file\n * @since 6.5.0\n * @param option {@link AssetPlayOptions}\n * @returns {Promise<void>}\n */\n setCurrentTime(options: { assetId: string; time: number }): Promise<void>;\n /**\n * Get the current time of an audio file\n * @since 5.0.0\n * @param option {@link AssetPlayOptions}\n * @returns {Promise<{ currentTime: number }>}\n */\n getCurrentTime(options: { assetId: string }): Promise<{ currentTime: number }>;\n /**\n * Get the duration of an audio file\n * @since 5.0.0\n * @param option {@link AssetPlayOptions}\n * @returns {Promise<{ duration: number }>}\n */\n getDuration(options: Assets): Promise<{ duration: number }>;\n /**\n * Check if an audio file is playing\n *\n * @since 5.0.0\n * @param option {@link AssetPlayOptions}\n * @returns {Promise<boolean>}\n */\n isPlaying(options: Assets): Promise<{ isPlaying: boolean }>;\n /**\n * Listen for complete event\n *\n * @since 5.0.0\n * return {@link CompletedEvent}\n */\n addListener(eventName: 'complete', listenerFunc: CompletedListener): Promise<PluginListenerHandle>;\n /**\n * Listen for current time updates\n * Emits every 100ms while audio is playing\n *\n * @since 6.5.0\n * return {@link CurrentTimeEvent}\n */\n addListener(eventName: 'currentTime', listenerFunc: CurrentTimeListener): Promise<PluginListenerHandle>;\n /**\n * Clear the audio cache for remote audio files\n * @since 6.5.0\n * @returns {Promise<void>}\n */\n clearCache(): Promise<void>;\n\n /**\n * Get the native Capacitor plugin version\n *\n * @returns {Promise<{ id: string }>} an Promise with version for this device\n * @throws An error if the something went wrong\n */\n getPluginVersion(): Promise<{ version: string }>;\n\n /**\n * Deinitialize the plugin and restore original audio session settings\n * This method stops all playing audio and reverts any audio session changes made by the plugin\n * Use this when you need to ensure compatibility with other audio plugins\n *\n * @since 7.7.0\n * @returns {Promise<void>}\n */\n deinitPlugin(): Promise<void>;\n}\n"]}
1
+ {"version":3,"file":"definitions.js","sourceRoot":"","sources":["../../src/definitions.ts"],"names":[],"mappings":"","sourcesContent":["import type { PluginListenerHandle } from '@capacitor/core';\n\nexport interface CompletedEvent {\n /**\n * Emit when a play completes\n *\n * @since 5.0.0\n */\n assetId: string;\n}\n\nexport type CompletedListener = (state: CompletedEvent) => void;\n\nexport interface Assets {\n /**\n * Asset Id, unique identifier of the file\n */\n assetId: string;\n}\n\nexport interface AssetVolume {\n /**\n * Asset Id, unique identifier of the file\n */\n assetId: string;\n /**\n * Volume of the audio, between 0.1 and 1.0\n */\n volume: number;\n /**\n * Time over which to fade to the target volume, in seconds. Default is 0s (immediate).\n */\n duration?: number;\n}\n\nexport interface AssetRate {\n /**\n * Asset Id, unique identifier of the file\n */\n assetId: string;\n /**\n * Rate of the audio, between 0.1 and 1.0\n */\n rate: number;\n}\n\nexport interface AssetSetTime {\n /**\n * Asset Id, unique identifier of the file\n */\n assetId: string;\n /**\n * Time to set the audio, in seconds\n */\n time: number;\n}\n\nexport interface AssetPlayOptions {\n /**\n * Asset Id, unique identifier of the file\n */\n assetId: string;\n /**\n * Time to start playing the audio, in seconds\n */\n time?: number;\n /**\n * Delay to start playing the audio, in seconds\n */\n delay?: number;\n\n /**\n * Volume of the audio, between 0.1 and 1.0\n */\n volume?: number;\n\n /**\n * Whether to fade in the audio\n */\n fadeIn?: boolean;\n\n /**\n * Whether to fade out the audio\n */\n fadeOut?: boolean;\n\n /**\n * Fade in duration in seconds.\n * Only used if fadeIn is true.\n * Default is 1s.\n */\n fadeInDuration?: number;\n\n /**\n * Fade out duration in seconds.\n * Only used if fadeOut is true.\n * Default is 1s.\n */\n fadeOutDuration?: number;\n\n /**\n * Time in seconds from the start of the audio to start fading out.\n * Only used if fadeOut is true.\n * Default is fadeOutDuration before end of audio.\n */\n fadeOutStartTime?: number;\n}\n\nexport interface AssetStopOptions {\n /**\n * Asset Id, unique identifier of the file\n */\n assetId: string;\n\n /**\n * Whether to fade out the audio before stopping\n */\n fadeOut?: boolean;\n\n /**\n * Fade out duration in seconds.\n * Default is 1s.\n */\n fadeOutDuration?: number;\n}\n\nexport interface AssetPauseOptions {\n /**\n * Asset Id, unique identifier of the file\n */\n assetId: string;\n\n /**\n * Whether to fade out the audio before pausing\n */\n fadeOut?: boolean;\n\n /**\n * Fade out duration in seconds.\n * Default is 1s.\n */\n fadeOutDuration?: number;\n}\n\nexport interface AssetResumeOptions {\n /**\n * Asset Id, unique identifier of the file\n */\n assetId: string;\n\n /**\n * Whether to fade in the audio during resume\n */\n fadeIn?: boolean;\n\n /**\n * Fade in duration in seconds.\n * Default is 1s.\n */\n fadeInDuration?: number;\n}\n\nexport interface ConfigureOptions {\n /**\n * focus the audio with Audio Focus\n */\n focus?: boolean;\n /**\n * Play the audio in the background\n */\n background?: boolean;\n /**\n * Ignore silent mode, works only on iOS setting this will nuke other audio apps\n */\n ignoreSilent?: boolean;\n /**\n * Show audio playback in the notification center (iOS and Android)\n * When enabled, displays audio metadata (title, artist, album, artwork) in the system notification\n * and Control Center (iOS) or lock screen.\n *\n * **Important iOS Behavior:**\n * Enabling this option changes the audio session category to `.playback` with `.default` mode,\n * which means your app's audio will **interrupt** other apps' audio (like background music from\n * Spotify, Apple Music, etc.) instead of mixing with it. This is required for the Now Playing\n * info to appear in Control Center and on the lock screen.\n *\n * **Trade-offs:**\n * - `showNotification: true` → Shows Now Playing controls, but interrupts other audio\n * - `showNotification: false` → Audio mixes with other apps, but no Now Playing controls\n *\n * Use this when your app is the primary audio source (music players, podcast apps, etc.).\n * Disable this for secondary audio like sound effects or notification sounds where mixing\n * with background music is preferred.\n *\n * @see https://github.com/Cap-go/capacitor-native-audio/issues/202\n */\n showNotification?: boolean;\n /**\n * Enable background audio playback (Android only)\n *\n * When enabled, audio will continue playing when the app is backgrounded or the screen is locked.\n * The plugin will skip the automatic pause/resume logic that normally occurs when the app\n * enters the background or returns to the foreground.\n *\n * **Important Android Requirements:**\n * To use background playback on Android, your app must:\n * 1. Declare the required permissions in `AndroidManifest.xml`:\n * - `<uses-permission android:name=\"android.permission.FOREGROUND_SERVICE\" />`\n * - `<uses-permission android:name=\"android.permission.FOREGROUND_SERVICE_MEDIA_PLAYBACK\" />`\n * - `<uses-permission android:name=\"android.permission.WAKE_LOCK\" />`\n * 2. Start a Foreground Service with a media-style notification before backgrounding\n * (the plugin does not automatically create or manage the foreground service)\n * 3. Use `showNotification: true` to display playback controls in the notification\n *\n * **Usage Example:**\n * ```typescript\n * await NativeAudio.configure({\n * backgroundPlayback: true,\n * showNotification: true\n * });\n * // Start your foreground service here\n * // Then preload and play audio as normal\n * ```\n *\n * @default false\n * @platform Android\n * @since 8.2.0\n */\n backgroundPlayback?: boolean;\n}\n\n/**\n * Metadata to display in the notification center, Control Center (iOS), and lock screen\n * when `showNotification` is enabled in `configure()`.\n *\n * Note: This metadata will only be displayed if `showNotification: true` is set in the\n * `configure()` method. See {@link ConfigureOptions.showNotification} for important\n * behavior details about audio mixing on iOS.\n */\nexport interface NotificationMetadata {\n /**\n * The title to display in the notification center\n */\n title?: string;\n /**\n * The artist name to display in the notification center\n */\n artist?: string;\n /**\n * The album name to display in the notification center\n */\n album?: string;\n /**\n * URL or local path to the artwork/album art image\n */\n artworkUrl?: string;\n}\n\nexport interface PlayOnceOptions {\n /**\n * Path to the audio file, relative path of the file, absolute url (file://) or remote url (https://)\n * Supported formats:\n * - MP3, WAV (all platforms)\n * - M3U8/HLS streams (iOS and Android)\n */\n assetPath: string;\n /**\n * Volume of the audio, between 0.1 and 1.0\n * @default 1.0\n */\n volume?: number;\n /**\n * Is the audio file a URL, pass true if assetPath is a `file://` url\n * or a streaming URL (m3u8)\n * @default false\n */\n isUrl?: boolean;\n /**\n * Automatically start playback after loading\n * @default true\n */\n autoPlay?: boolean;\n /**\n * Delete the audio file from disk after playback completes\n * Only works for local files (file:// URLs), ignored for remote URLs\n * @default false\n * @since 7.11.0\n */\n deleteAfterPlay?: boolean;\n /**\n * Metadata to display in the notification center when audio is playing.\n * Only used when `showNotification: true` is set in `configure()`.\n *\n * See {@link ConfigureOptions.showNotification} for important details about\n * how this affects audio mixing behavior on iOS.\n *\n * @see NotificationMetadata\n * @since 7.10.0\n */\n notificationMetadata?: NotificationMetadata;\n /**\n * Custom HTTP headers to include when fetching remote audio files.\n * Only used when isUrl is true and assetPath is a remote URL (http/https).\n * Example: { 'x-api-key': 'abc123', 'Authorization': 'Bearer token' }\n *\n * @since 7.10.0\n */\n headers?: Record<string, string>;\n}\n\nexport interface PlayOnceResult {\n /**\n * The internally generated asset ID for this playback\n * Can be used to control playback (pause, stop, etc.) before completion\n */\n assetId: string;\n}\n\nexport interface PreloadOptions {\n /**\n * Path to the audio file, relative path of the file, absolute url (file://) or remote url (https://)\n * Supported formats:\n * - MP3, WAV (all platforms)\n * - M3U8/HLS streams (iOS and Android)\n */\n assetPath: string;\n /**\n * Asset Id, unique identifier of the file\n */\n assetId: string;\n /**\n * Volume of the audio, between 0.1 and 1.0\n */\n volume?: number;\n /**\n * Audio channel number, default is 1\n */\n audioChannelNum?: number;\n /**\n * Is the audio file a URL, pass true if assetPath is a `file://` url\n * or a streaming URL (m3u8)\n */\n isUrl?: boolean;\n /**\n * Metadata to display in the notification center when audio is playing.\n * Only used when `showNotification: true` is set in `configure()`.\n *\n * See {@link ConfigureOptions.showNotification} for important details about\n * how this affects audio mixing behavior on iOS.\n *\n * @see NotificationMetadata\n */\n notificationMetadata?: NotificationMetadata;\n /**\n * Custom HTTP headers to include when fetching remote audio files.\n * Only used when isUrl is true and assetPath is a remote URL (http/https).\n * Example: { 'x-api-key': 'abc123', 'Authorization': 'Bearer token' }\n *\n * @since 7.10.0\n */\n headers?: Record<string, string>;\n}\n\nexport interface CurrentTimeEvent {\n /**\n * Current time of the audio in seconds\n * @since 6.5.0\n */\n currentTime: number;\n /**\n * Asset Id of the audio\n * @since 6.5.0\n */\n assetId: string;\n}\n\nexport type CurrentTimeListener = (state: CurrentTimeEvent) => void;\n\nexport interface NativeAudio {\n /**\n * Configure the audio player\n * @since 5.0.0\n * @param option {@link ConfigureOptions}\n * @returns\n */\n configure(options: ConfigureOptions): Promise<void>;\n\n /**\n * Load an audio file\n * @since 5.0.0\n * @param option {@link PreloadOptions}\n * @returns\n */\n preload(options: PreloadOptions): Promise<void>;\n /**\n * Play an audio file once with automatic cleanup\n *\n * Method designed for simple, single-shot audio playback,\n * such as notification sounds, UI feedback, or other short audio clips\n * that don't require manual state management.\n *\n * **Key Features:**\n * - **Fire-and-forget**: No need to manually preload, play, stop, or unload\n * - **Auto-cleanup**: Asset is automatically unloaded after playback completes\n * - **Optional file deletion**: Can delete local files after playback (useful for temp files)\n * - **Returns assetId**: Can still control playback if needed (pause, stop, etc.)\n *\n * **Use Cases:**\n * - Notification sounds\n * - UI sound effects (button clicks, alerts)\n * - Short audio clips that play once\n * - Temporary audio files that should be cleaned up\n *\n * **Comparison with regular play():**\n * - `play()`: Requires manual preload, play, and unload steps\n * - `playOnce()`: Handles everything automatically with a single call\n *\n * @example\n * ```typescript\n * // Simple one-shot playback\n * await NativeAudio.playOnce({ assetPath: 'audio/notification.mp3' });\n *\n * // Play and delete the file after completion\n * await NativeAudio.playOnce({\n * assetPath: 'file:///path/to/temp/audio.mp3',\n * isUrl: true,\n * deleteAfterPlay: true\n * });\n *\n * // Get the assetId to control playback\n * const { assetId } = await NativeAudio.playOnce({\n * assetPath: 'audio/long-track.mp3',\n * autoPlay: true\n * });\n * // Later, you can stop it manually if needed\n * await NativeAudio.stop({ assetId });\n * ```\n *\n * @since 7.11.0\n * @param options {@link PlayOnceOptions}\n * @returns {Promise<PlayOnceResult>} Object containing the generated assetId\n */\n playOnce(options: PlayOnceOptions): Promise<PlayOnceResult>;\n /**\n * Check if an audio file is preloaded\n *\n * @since 6.1.0\n * @param option {@link Assets}\n * @returns {Promise<boolean>}\n */\n isPreloaded(options: PreloadOptions): Promise<{ found: boolean }>;\n\n /**\n * Play an audio file\n * @since 5.0.0\n * @param option {@link AssetPlayOptions}\n * @returns\n */\n play(options: AssetPlayOptions): Promise<void>;\n\n /**\n * Pause an audio file\n * @since 5.0.0\n * @param option {@link AssetPauseOptions}\n * @returns\n */\n pause(options: AssetPauseOptions): Promise<void>;\n\n /**\n * Resume an audio file\n * @since 5.0.0\n * @param option {@link AssetResumeOptions}\n * @returns\n */\n resume(options: AssetResumeOptions): Promise<void>;\n\n /**\n * Stop an audio file\n * @since 5.0.0\n * @param option {@link Assets}\n * @returns\n */\n loop(options: Assets): Promise<void>;\n\n /**\n * Stop an audio file\n * @since 5.0.0\n * @param option {@link AssetStopOptions}\n * @returns\n */\n stop(options: AssetStopOptions): Promise<void>;\n\n /**\n * Unload an audio file\n * @since 5.0.0\n * @param option {@link Assets}\n * @returns\n */\n unload(options: Assets): Promise<void>;\n\n /**\n * Set the volume of an audio file\n * @since 5.0.0\n * @param option {@link AssetVolume}\n * @returns {Promise<void>}\n */\n setVolume(options: AssetVolume): Promise<void>;\n\n /**\n * Set the rate of an audio file\n * @since 5.0.0\n * @param option {@link AssetRate}\n * @returns {Promise<void>}\n */\n setRate(options: AssetRate): Promise<void>;\n\n /**\n * Set the current time of an audio file\n * @since 6.5.0\n * @param option {@link AssetSetTime}\n * @returns {Promise<void>}\n */\n setCurrentTime(options: AssetSetTime): Promise<void>;\n\n /**\n * Get the current time of an audio file\n * @since 5.0.0\n * @param option {@link Assets}\n * @returns {Promise<{ currentTime: number }>}\n */\n getCurrentTime(options: Assets): Promise<{ currentTime: number }>;\n\n /**\n * Get the duration of an audio file in seconds\n * @since 5.0.0\n * @param option {@link Assets}\n * @returns {Promise<{ duration: number }>}\n */\n getDuration(options: Assets): Promise<{ duration: number }>;\n\n /**\n * Check if an audio file is playing\n *\n * @since 5.0.0\n * @param option {@link Assets}\n * @returns {Promise<boolean>}\n */\n isPlaying(options: Assets): Promise<{ isPlaying: boolean }>;\n\n /**\n * Listen for complete event\n *\n * @since 5.0.0\n * return {@link CompletedEvent}\n */\n addListener(eventName: 'complete', listenerFunc: CompletedListener): Promise<PluginListenerHandle>;\n\n /**\n * Listen for current time updates\n * Emits every 100ms while audio is playing\n *\n * @since 6.5.0\n * return {@link CurrentTimeEvent}\n */\n addListener(eventName: 'currentTime', listenerFunc: CurrentTimeListener): Promise<PluginListenerHandle>;\n /**\n * Clear the audio cache for remote audio files\n * @since 6.5.0\n * @returns {Promise<void>}\n */\n clearCache(): Promise<void>;\n\n /**\n * Set debug mode logging\n * @since 6.5.0\n * @param options - Options to enable or disable debug mode\n */\n setDebugMode(options: { enabled: boolean }): Promise<void>;\n\n /**\n * Get the native Capacitor plugin version\n *\n * @returns {Promise<{ id: string }>} an Promise with version for this device\n * @throws An error if the something went wrong\n */\n getPluginVersion(): Promise<{ version: string }>;\n\n /**\n * Deinitialize the plugin and restore original audio session settings\n * This method stops all playing audio and reverts any audio session changes made by the plugin\n * Use this when you need to ensure compatibility with other audio plugins\n *\n * @since 7.7.0\n * @returns {Promise<void>}\n */\n deinitPlugin(): Promise<void>;\n}\n"]}
package/dist/esm/web.d.ts CHANGED
@@ -1,31 +1,36 @@
1
1
  import { WebPlugin } from '@capacitor/core';
2
- import type { ConfigureOptions, PlayOnceOptions, PlayOnceResult, PreloadOptions } from './definitions';
2
+ import type { Assets, AssetPauseOptions, AssetPlayOptions, AssetRate, AssetResumeOptions, AssetSetTime, AssetStopOptions, AssetVolume, ConfigureOptions, PlayOnceOptions, PlayOnceResult, PreloadOptions } from './definitions';
3
3
  import { NativeAudio } from './definitions';
4
4
  export declare class NativeAudioWeb extends WebPlugin implements NativeAudio {
5
+ private static readonly LOG_TAG;
5
6
  private static readonly FILE_LOCATION;
7
+ private static readonly DEFAULT_FADE_DURATION_SEC;
8
+ private static readonly CURRENT_TIME_UPDATE_INTERVAL;
9
+ private static readonly AUDIO_PRELOAD_OPTIONS_MAP;
10
+ private static readonly AUDIO_DATA_MAP;
6
11
  private static readonly AUDIO_ASSET_BY_ASSET_ID;
12
+ private static readonly AUDIO_CONTEXT_MAP;
13
+ private static readonly MEDIA_ELEMENT_SOURCE_MAP;
14
+ private static readonly GAIN_NODE_MAP;
7
15
  private static readonly playOnceAssets;
16
+ private debugMode;
17
+ private currentTimeIntervals;
18
+ private readonly zeroVolume;
8
19
  constructor();
9
- resume(options: {
10
- assetId: string;
11
- }): Promise<void>;
12
- pause(options: {
13
- assetId: string;
14
- }): Promise<void>;
15
- setCurrentTime(options: {
16
- assetId: string;
17
- time: number;
18
- }): Promise<void>;
19
- getCurrentTime(options: {
20
- assetId: string;
21
- }): Promise<{
20
+ resume(options: AssetResumeOptions): Promise<void>;
21
+ private doResume;
22
+ pause(options: AssetPauseOptions): Promise<void>;
23
+ private doPause;
24
+ setCurrentTime(options: AssetSetTime): Promise<void>;
25
+ getCurrentTime(options: Assets): Promise<{
22
26
  currentTime: number;
23
27
  }>;
24
- getDuration(options: {
25
- assetId: string;
26
- }): Promise<{
28
+ getDuration(options: Assets): Promise<{
27
29
  duration: number;
28
30
  }>;
31
+ setDebugMode(options: {
32
+ enabled: boolean;
33
+ }): Promise<void>;
29
34
  configure(options: ConfigureOptions): Promise<void>;
30
35
  isPreloaded(options: PreloadOptions): Promise<{
31
36
  found: boolean;
@@ -33,35 +38,41 @@ export declare class NativeAudioWeb extends WebPlugin implements NativeAudio {
33
38
  preload(options: PreloadOptions): Promise<void>;
34
39
  playOnce(options: PlayOnceOptions): Promise<PlayOnceResult>;
35
40
  private onEnded;
36
- play(options: {
37
- assetId: string;
38
- time?: number;
39
- }): Promise<void>;
40
- loop(options: {
41
- assetId: string;
42
- }): Promise<void>;
43
- stop(options: {
44
- assetId: string;
45
- }): Promise<void>;
46
- unload(options: {
47
- assetId: string;
48
- }): Promise<void>;
49
- setVolume(options: {
50
- assetId: string;
51
- volume: number;
52
- }): Promise<void>;
53
- setRate(options: {
54
- assetId: string;
55
- rate: number;
56
- }): Promise<void>;
57
- isPlaying(options: {
58
- assetId: string;
59
- }): Promise<{
41
+ play(options: AssetPlayOptions): Promise<void>;
42
+ private doPlay;
43
+ private doFadeIn;
44
+ private doFadeOut;
45
+ loop(options: Assets): Promise<void>;
46
+ stop(options: AssetStopOptions): Promise<void>;
47
+ private doStop;
48
+ private reset;
49
+ private clearFadeOutToStopTimer;
50
+ private clearStartTimer;
51
+ unload(options: Assets): Promise<void>;
52
+ private cleanupAudioContext;
53
+ setVolume(options: AssetVolume): Promise<void>;
54
+ setRate(options: AssetRate): Promise<void>;
55
+ isPlaying(options: Assets): Promise<{
60
56
  isPlaying: boolean;
61
57
  }>;
62
58
  clearCache(): Promise<void>;
63
59
  private getAudioAsset;
64
60
  private checkAssetId;
61
+ private getOrCreateAudioContext;
62
+ private getOrCreateMediaElementSource;
63
+ private getOrCreateGainNode;
64
+ private setGainNodeVolume;
65
+ private exponentialRampGainNodeVolume;
66
+ private linearRampGainNodeVolume;
67
+ private cancelGainNodeRamp;
68
+ private startCurrentTimeUpdates;
69
+ private stopCurrentTimeUpdates;
70
+ private getAudioAssetData;
71
+ private setAudioAssetData;
72
+ private logError;
73
+ private logWarning;
74
+ private logInfo;
75
+ private logDebug;
65
76
  getPluginVersion(): Promise<{
66
77
  version: string;
67
78
  }>;