@capgo/native-audio 7.9.8 → 7.9.10

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.
package/LICENSE CHANGED
@@ -1,21 +1,373 @@
1
- MIT License
2
-
3
- Copyright (c) 2022 Capgo
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in all
13
- copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- SOFTWARE.
1
+ Mozilla Public License Version 2.0
2
+ ==================================
3
+
4
+ 1. Definitions
5
+ --------------
6
+
7
+ 1.1. "Contributor"
8
+ means each individual or legal entity that creates, contributes to
9
+ the creation of, or owns Covered Software.
10
+
11
+ 1.2. "Contributor Version"
12
+ means the combination of the Contributions of others (if any) used
13
+ by a Contributor and that particular Contributor's Contribution.
14
+
15
+ 1.3. "Contribution"
16
+ means Covered Software of a particular Contributor.
17
+
18
+ 1.4. "Covered Software"
19
+ means Source Code Form to which the initial Contributor has attached
20
+ the notice in Exhibit A, the Executable Form of such Source Code
21
+ Form, and Modifications of such Source Code Form, in each case
22
+ including portions thereof.
23
+
24
+ 1.5. "Incompatible With Secondary Licenses"
25
+ means
26
+
27
+ (a) that the initial Contributor has attached the notice described
28
+ in Exhibit B to the Covered Software; or
29
+
30
+ (b) that the Covered Software was made available under the terms of
31
+ version 1.1 or earlier of the License, but not also under the
32
+ terms of a Secondary License.
33
+
34
+ 1.6. "Executable Form"
35
+ means any form of the work other than Source Code Form.
36
+
37
+ 1.7. "Larger Work"
38
+ means a work that combines Covered Software with other material, in
39
+ a separate file or files, that is not Covered Software.
40
+
41
+ 1.8. "License"
42
+ means this document.
43
+
44
+ 1.9. "Licensable"
45
+ means having the right to grant, to the maximum extent possible,
46
+ whether at the time of the initial grant or subsequently, any and
47
+ all of the rights conveyed by this License.
48
+
49
+ 1.10. "Modifications"
50
+ means any of the following:
51
+
52
+ (a) any file in Source Code Form that results from an addition to,
53
+ deletion from, or modification of the contents of Covered
54
+ Software; or
55
+
56
+ (b) any new file in Source Code Form that contains any Covered
57
+ Software.
58
+
59
+ 1.11. "Patent Claims" of a Contributor
60
+ means any patent claim(s), including without limitation, method,
61
+ process, and apparatus claims, in any patent Licensable by such
62
+ Contributor that would be infringed, but for the grant of the
63
+ License, by the making, using, selling, offering for sale, having
64
+ made, import, or transfer of either its Contributions or its
65
+ Contributor Version.
66
+
67
+ 1.12. "Secondary License"
68
+ means either the GNU General Public License, Version 2.0, the GNU
69
+ Lesser General Public License, Version 2.1, the GNU Affero General
70
+ Public License, Version 3.0, or any later versions of those
71
+ licenses.
72
+
73
+ 1.13. "Source Code Form"
74
+ means the form of the work preferred for making modifications.
75
+
76
+ 1.14. "You" (or "Your")
77
+ means an individual or a legal entity exercising rights under this
78
+ License. For legal entities, "You" includes any entity that
79
+ controls, is controlled by, or is under common control with You. For
80
+ purposes of this definition, "control" means (a) the power, direct
81
+ or indirect, to cause the direction or management of such entity,
82
+ whether by contract or otherwise, or (b) ownership of more than
83
+ fifty percent (50%) of the outstanding shares or beneficial
84
+ ownership of such entity.
85
+
86
+ 2. License Grants and Conditions
87
+ --------------------------------
88
+
89
+ 2.1. Grants
90
+
91
+ Each Contributor hereby grants You a world-wide, royalty-free,
92
+ non-exclusive license:
93
+
94
+ (a) under intellectual property rights (other than patent or trademark)
95
+ Licensable by such Contributor to use, reproduce, make available,
96
+ modify, display, perform, distribute, and otherwise exploit its
97
+ Contributions, either on an unmodified basis, with Modifications, or
98
+ as part of a Larger Work; and
99
+
100
+ (b) under Patent Claims of such Contributor to make, use, sell, offer
101
+ for sale, have made, import, and otherwise transfer either its
102
+ Contributions or its Contributor Version.
103
+
104
+ 2.2. Effective Date
105
+
106
+ The licenses granted in Section 2.1 with respect to any Contribution
107
+ become effective for each Contribution on the date the Contributor first
108
+ distributes such Contribution.
109
+
110
+ 2.3. Limitations on Grant Scope
111
+
112
+ The licenses granted in this Section 2 are the only rights granted under
113
+ this License. No additional rights or licenses will be implied from the
114
+ distribution or licensing of Covered Software under this License.
115
+ Notwithstanding Section 2.1(b) above, no patent license is granted by a
116
+ Contributor:
117
+
118
+ (a) for any code that a Contributor has removed from Covered Software;
119
+ or
120
+
121
+ (b) for infringements caused by: (i) Your and any other third party's
122
+ modifications of Covered Software, or (ii) the combination of its
123
+ Contributions with other software (except as part of its Contributor
124
+ Version); or
125
+
126
+ (c) under Patent Claims infringed by Covered Software in the absence of
127
+ its Contributions.
128
+
129
+ This License does not grant any rights in the trademarks, service marks,
130
+ or logos of any Contributor (except as may be necessary to comply with
131
+ the notice requirements in Section 3.4).
132
+
133
+ 2.4. Subsequent Licenses
134
+
135
+ No Contributor makes additional grants as a result of Your choice to
136
+ distribute the Covered Software under a subsequent version of this
137
+ License (see Section 10.2) or under the terms of a Secondary License (if
138
+ permitted under the terms of Section 3.3).
139
+
140
+ 2.5. Representation
141
+
142
+ Each Contributor represents that the Contributor believes its
143
+ Contributions are its original creation(s) or it has sufficient rights
144
+ to grant the rights to its Contributions conveyed by this License.
145
+
146
+ 2.6. Fair Use
147
+
148
+ This License is not intended to limit any rights You have under
149
+ applicable copyright doctrines of fair use, fair dealing, or other
150
+ equivalents.
151
+
152
+ 2.7. Conditions
153
+
154
+ Sections 3.1, 3.2, 3.3, and 3.4 are conditions of the licenses granted
155
+ in Section 2.1.
156
+
157
+ 3. Responsibilities
158
+ -------------------
159
+
160
+ 3.1. Distribution of Source Form
161
+
162
+ All distribution of Covered Software in Source Code Form, including any
163
+ Modifications that You create or to which You contribute, must be under
164
+ the terms of this License. You must inform recipients that the Source
165
+ Code Form of the Covered Software is governed by the terms of this
166
+ License, and how they can obtain a copy of this License. You may not
167
+ attempt to alter or restrict the recipients' rights in the Source Code
168
+ Form.
169
+
170
+ 3.2. Distribution of Executable Form
171
+
172
+ If You distribute Covered Software in Executable Form then:
173
+
174
+ (a) such Covered Software must also be made available in Source Code
175
+ Form, as described in Section 3.1, and You must inform recipients of
176
+ the Executable Form how they can obtain a copy of such Source Code
177
+ Form by reasonable means in a timely manner, at a charge no more
178
+ than the cost of distribution to the recipient; and
179
+
180
+ (b) You may distribute such Executable Form under the terms of this
181
+ License, or sublicense it under different terms, provided that the
182
+ license for the Executable Form does not attempt to limit or alter
183
+ the recipients' rights in the Source Code Form under this License.
184
+
185
+ 3.3. Distribution of a Larger Work
186
+
187
+ You may create and distribute a Larger Work under terms of Your choice,
188
+ provided that You also comply with the requirements of this License for
189
+ the Covered Software. If the Larger Work is a combination of Covered
190
+ Software with a work governed by one or more Secondary Licenses, and the
191
+ Covered Software is not Incompatible With Secondary Licenses, this
192
+ License permits You to additionally distribute such Covered Software
193
+ under the terms of such Secondary License(s), so that the recipient of
194
+ the Larger Work may, at their option, further distribute the Covered
195
+ Software under the terms of either this License or such Secondary
196
+ License(s).
197
+
198
+ 3.4. Notices
199
+
200
+ You may not remove or alter the substance of any license notices
201
+ (including copyright notices, patent notices, disclaimers of warranty,
202
+ or limitations of liability) contained within the Source Code Form of
203
+ the Covered Software, except that You may alter any license notices to
204
+ the extent required to remedy known factual inaccuracies.
205
+
206
+ 3.5. Application of Additional Terms
207
+
208
+ You may choose to offer, and to charge a fee for, warranty, support,
209
+ indemnity or liability obligations to one or more recipients of Covered
210
+ Software. However, You may do so only on Your own behalf, and not on
211
+ behalf of any Contributor. You must make it absolutely clear that any
212
+ such warranty, support, indemnity, or liability obligation is offered by
213
+ You alone, and You hereby agree to indemnify every Contributor for any
214
+ liability incurred by such Contributor as a result of warranty, support,
215
+ indemnity or liability terms You offer. You may include additional
216
+ disclaimers of warranty and limitations of liability specific to any
217
+ jurisdiction.
218
+
219
+ 4. Inability to Comply Due to Statute or Regulation
220
+ ---------------------------------------------------
221
+
222
+ If it is impossible for You to comply with any of the terms of this
223
+ License with respect to some or all of the Covered Software due to
224
+ statute, judicial order, or regulation then You must: (a) comply with
225
+ the terms of this License to the maximum extent possible; and (b)
226
+ describe the limitations and the code they affect. Such description must
227
+ be placed in a text file included with all distributions of the Covered
228
+ Software under this License. Except to the extent prohibited by statute
229
+ or regulation, such description must be sufficiently detailed for a
230
+ recipient of ordinary skill to be able to understand it.
231
+
232
+ 5. Termination
233
+ --------------
234
+
235
+ 5.1. The rights granted under this License will terminate automatically
236
+ if You fail to comply with any of its terms. However, if You become
237
+ compliant, then the rights granted under this License from a particular
238
+ Contributor are reinstated (a) provisionally, unless and until such
239
+ Contributor explicitly and finally terminates Your grants, and (b) on an
240
+ ongoing basis, if such Contributor fails to notify You of the
241
+ non-compliance by some reasonable means prior to 60 days after You have
242
+ come back into compliance. Moreover, Your grants from a particular
243
+ Contributor are reinstated on an ongoing basis if such Contributor
244
+ notifies You of the non-compliance by some reasonable means, this is the
245
+ first time You have received notice of non-compliance with this License
246
+ from such Contributor, and You become compliant prior to 30 days after
247
+ Your receipt of the notice.
248
+
249
+ 5.2. If You initiate litigation against any entity by asserting a patent
250
+ infringement claim (excluding declaratory judgment actions,
251
+ counter-claims, and cross-claims) alleging that a Contributor Version
252
+ directly or indirectly infringes any patent, then the rights granted to
253
+ You by any and all Contributors for the Covered Software under Section
254
+ 2.1 of this License shall terminate.
255
+
256
+ 5.3. In the event of termination under Sections 5.1 or 5.2 above, all
257
+ end user license agreements (excluding distributors and resellers) which
258
+ have been validly granted by You or Your distributors under this License
259
+ prior to termination shall survive termination.
260
+
261
+ ************************************************************************
262
+ * *
263
+ * 6. Disclaimer of Warranty *
264
+ * ------------------------- *
265
+ * *
266
+ * Covered Software is provided under this License on an "as is" *
267
+ * basis, without warranty of any kind, either expressed, implied, or *
268
+ * statutory, including, without limitation, warranties that the *
269
+ * Covered Software is free of defects, merchantable, fit for a *
270
+ * particular purpose or non-infringing. The entire risk as to the *
271
+ * quality and performance of the Covered Software is with You. *
272
+ * Should any Covered Software prove defective in any respect, You *
273
+ * (not any Contributor) assume the cost of any necessary servicing, *
274
+ * repair, or correction. This disclaimer of warranty constitutes an *
275
+ * essential part of this License. No use of any Covered Software is *
276
+ * authorized under this License except under this disclaimer. *
277
+ * *
278
+ ************************************************************************
279
+
280
+ ************************************************************************
281
+ * *
282
+ * 7. Limitation of Liability *
283
+ * -------------------------- *
284
+ * *
285
+ * Under no circumstances and under no legal theory, whether tort *
286
+ * (including negligence), contract, or otherwise, shall any *
287
+ * Contributor, or anyone who distributes Covered Software as *
288
+ * permitted above, be liable to You for any direct, indirect, *
289
+ * special, incidental, or consequential damages of any character *
290
+ * including, without limitation, damages for lost profits, loss of *
291
+ * goodwill, work stoppage, computer failure or malfunction, or any *
292
+ * and all other commercial damages or losses, even if such party *
293
+ * shall have been informed of the possibility of such damages. This *
294
+ * limitation of liability shall not apply to liability for death or *
295
+ * personal injury resulting from such party's negligence to the *
296
+ * extent applicable law prohibits such limitation. Some *
297
+ * jurisdictions do not allow the exclusion or limitation of *
298
+ * incidental or consequential damages, so this exclusion and *
299
+ * limitation may not apply to You. *
300
+ * *
301
+ ************************************************************************
302
+
303
+ 8. Litigation
304
+ -------------
305
+
306
+ Any litigation relating to this License may be brought only in the
307
+ courts of a jurisdiction where the defendant maintains its principal
308
+ place of business and such litigation shall be governed by laws of that
309
+ jurisdiction, without reference to its conflict-of-law provisions.
310
+ Nothing in this Section shall prevent a party's ability to bring
311
+ cross-claims or counter-claims.
312
+
313
+ 9. Miscellaneous
314
+ ----------------
315
+
316
+ This License represents the complete agreement concerning the subject
317
+ matter hereof. If any provision of this License is held to be
318
+ unenforceable, such provision shall be reformed only to the extent
319
+ necessary to make it enforceable. Any law or regulation which provides
320
+ that the language of a contract shall be construed against the drafter
321
+ shall not be used to construe this License against a Contributor.
322
+
323
+ 10. Versions of the License
324
+ ---------------------------
325
+
326
+ 10.1. New Versions
327
+
328
+ Mozilla Foundation is the license steward. Except as provided in Section
329
+ 10.3, no one other than the license steward has the right to modify or
330
+ publish new versions of this License. Each version will be given a
331
+ distinguishing version number.
332
+
333
+ 10.2. Effect of New Versions
334
+
335
+ You may distribute the Covered Software under the terms of the version
336
+ of the License under which You originally received the Covered Software,
337
+ or under the terms of any subsequent version published by the license
338
+ steward.
339
+
340
+ 10.3. Modified Versions
341
+
342
+ If you create software not governed by this License, and you want to
343
+ create a new license for such software, you may create and use a
344
+ modified version of this License if you rename the license and remove
345
+ any references to the name of the license steward (except to note that
346
+ such modified license differs from this License).
347
+
348
+ 10.4. Distributing Source Code Form that is Incompatible With Secondary
349
+ Licenses
350
+
351
+ If You choose to distribute Source Code Form that is Incompatible With
352
+ Secondary Licenses under the terms of this version of the License, the
353
+ notice described in Exhibit B of this License must be attached.
354
+
355
+ Exhibit A - Source Code Form License Notice
356
+ -------------------------------------------
357
+
358
+ This Source Code Form is subject to the terms of the Mozilla Public
359
+ License, v. 2.0. If a copy of the MPL was not distributed with this
360
+ file, You can obtain one at https://mozilla.org/MPL/2.0/.
361
+
362
+ If it is not possible or desirable to put the notice in a particular
363
+ file, then You may include the notice in a location (such as a LICENSE
364
+ file in a relevant directory) where a recipient would be likely to look
365
+ for such a notice.
366
+
367
+ You may add additional accurate notices of copyright ownership.
368
+
369
+ Exhibit B - "Incompatible With Secondary Licenses" Notice
370
+ ---------------------------------------------------------
371
+
372
+ This Source Code Form is "Incompatible With Secondary Licenses", as
373
+ defined by the Mozilla Public License, v. 2.0.
package/README.md CHANGED
@@ -136,6 +136,19 @@ No configuration required for this plugin.
136
136
 
137
137
  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.
138
138
 
139
+ > **⚠️ Important iOS Behavior**
140
+ >
141
+ > Enabling `showNotification: true` changes how your app's audio interacts with other apps on iOS:
142
+ >
143
+ > - **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.
144
+ > - **With notifications disabled** (showNotification: false): Your audio will **mix** with other apps' audio, allowing background music to continue playing.
145
+ >
146
+ > **When to use each:**
147
+ > - ✅ Use `showNotification: true` for: Music players, podcast apps, audiobook players (primary audio source)
148
+ > - ❌ Use `showNotification: false` for: Sound effects, notification sounds, secondary audio where mixing is preferred
149
+ >
150
+ > See [Issue #202](https://github.com/Cap-go/capacitor-native-audio/issues/202) for technical details.
151
+
139
152
  **Step 1: Configure the plugin with notification support**
140
153
 
141
154
  ```typescript
@@ -193,6 +206,7 @@ The media control buttons automatically handle:
193
206
  - All metadata fields are optional
194
207
  - Artwork can be a local file path or remote URL
195
208
  - The notification only appears when `showNotification: true` is set in configure()
209
+ - ⚠️ **iOS:** Enabling notifications will interrupt other apps' audio (see warning above)
196
210
  - iOS: Uses MPNowPlayingInfoCenter with MPRemoteCommandCenter
197
211
  - Android: Uses MediaSession with NotificationCompat.MediaStyle
198
212
 
@@ -674,29 +688,37 @@ Use this when you need to ensure compatibility with other audio plugins
674
688
 
675
689
  #### ConfigureOptions
676
690
 
677
- | Prop | Type | Description |
678
- | ---------------------- | -------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------- |
679
- | **`fade`** | <code>boolean</code> | Play the audio with Fade effect, only available for IOS |
680
- | **`focus`** | <code>boolean</code> | focus the audio with Audio Focus |
681
- | **`background`** | <code>boolean</code> | Play the audio in the background |
682
- | **`ignoreSilent`** | <code>boolean</code> | Ignore silent mode, works only on iOS setting this will nuke other audio apps |
683
- | **`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 |
691
+ | Prop | Type | Description |
692
+ | ---------------------- | -------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
693
+ | **`fade`** | <code>boolean</code> | Play the audio with Fade effect, only available for IOS |
694
+ | **`focus`** | <code>boolean</code> | focus the audio with Audio Focus |
695
+ | **`background`** | <code>boolean</code> | Play the audio in the background |
696
+ | **`ignoreSilent`** | <code>boolean</code> | Ignore silent mode, works only on iOS setting this will nuke other audio apps |
697
+ | **`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. |
684
698
 
685
699
 
686
700
  #### PreloadOptions
687
701
 
688
- | Prop | Type | Description |
689
- | -------------------------- | --------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
690
- | **`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) |
691
- | **`assetId`** | <code>string</code> | Asset Id, unique identifier of the file |
692
- | **`volume`** | <code>number</code> | Volume of the audio, between 0.1 and 1.0 |
693
- | **`audioChannelNum`** | <code>number</code> | Audio channel number, default is 1 |
694
- | **`isUrl`** | <code>boolean</code> | Is the audio file a URL, pass true if assetPath is a `file://` url or a streaming URL (m3u8) |
695
- | **`notificationMetadata`** | <code><a href="#notificationmetadata">NotificationMetadata</a></code> | Metadata to display in the notification center when audio is playing Only used when showNotification is enabled in configure() |
702
+ | Prop | Type | Description | Since |
703
+ | -------------------------- | --------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------ |
704
+ | **`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) | |
705
+ | **`assetId`** | <code>string</code> | Asset Id, unique identifier of the file | |
706
+ | **`volume`** | <code>number</code> | Volume of the audio, between 0.1 and 1.0 | |
707
+ | **`audioChannelNum`** | <code>number</code> | Audio channel number, default is 1 | |
708
+ | **`isUrl`** | <code>boolean</code> | Is the audio file a URL, pass true if assetPath is a `file://` url or a streaming URL (m3u8) | |
709
+ | **`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. | |
710
+ | **`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 |
696
711
 
697
712
 
698
713
  #### NotificationMetadata
699
714
 
715
+ Metadata to display in the notification center, Control Center (iOS), and lock screen
716
+ when `showNotification` is enabled in `configure()`.
717
+
718
+ Note: This metadata will only be displayed if `showNotification: true` is set in the
719
+ `configure()` method. See {@link <a href="#configureoptions">ConfigureOptions.showNotification</a>} for important
720
+ behavior details about audio mixing on iOS.
721
+
700
722
  | Prop | Type | Description |
701
723
  | ---------------- | ------------------- | ----------------------------------------------------- |
702
724
  | **`title`** | <code>string</code> | The title to display in the notification center |
@@ -737,6 +759,13 @@ Use this when you need to ensure compatibility with other audio plugins
737
759
  ### Type Aliases
738
760
 
739
761
 
762
+ #### Record
763
+
764
+ Construct a type with a set of properties K of type T
765
+
766
+ <code>{
740
767
  [P in K]: T;
741
768
  }</code>
769
+
770
+
742
771
  #### CompletedListener
743
772
 
744
773
  <code>(state: <a href="#completedevent">CompletedEvent</a>): void</code>
@@ -64,5 +64,5 @@ dependencies {
64
64
  implementation 'androidx.media3:media3-common:1.8.0'
65
65
  // Media notification support
66
66
  implementation 'androidx.media:media:1.7.1'
67
- implementation 'androidx.core:core:1.17.0'
67
+ implementation 'androidx.core:core:1.13.1'
68
68
  }
@@ -50,6 +50,7 @@ import java.net.URI;
50
50
  import java.net.URL;
51
51
  import java.util.ArrayList;
52
52
  import java.util.HashMap;
53
+ import java.util.Iterator;
53
54
  import java.util.Map;
54
55
 
55
56
  @UnstableApi
@@ -644,14 +645,40 @@ public class NativeAudio extends Plugin implements AudioManager.OnAudioFocusChan
644
645
  if (uri.getScheme() != null && (uri.getScheme().equals("http") || uri.getScheme().equals("https"))) {
645
646
  // Remote URL
646
647
  Log.d("AudioPlugin", "Debug: Remote URL detected: " + uri.toString());
648
+
649
+ // Extract headers if provided
650
+ Map<String, String> requestHeaders = null;
651
+ JSObject headersObj = call.getObject("headers");
652
+ if (headersObj != null) {
653
+ requestHeaders = new HashMap<>();
654
+ for (Iterator<String> it = headersObj.keys(); it.hasNext(); ) {
655
+ String key = it.next();
656
+ try {
657
+ String value = headersObj.getString(key);
658
+ if (value != null) {
659
+ requestHeaders.put(key, value);
660
+ }
661
+ } catch (Exception e) {
662
+ Log.w("AudioPlugin", "Skipping non-string header: " + key);
663
+ }
664
+ }
665
+ }
666
+
647
667
  if (assetPath.endsWith(".m3u8")) {
648
668
  // HLS Stream - resolve immediately since it's a stream
649
- StreamAudioAsset streamAudioAsset = new StreamAudioAsset(this, audioId, uri, volume);
669
+ StreamAudioAsset streamAudioAsset = new StreamAudioAsset(this, audioId, uri, volume, requestHeaders);
650
670
  audioAssetList.put(audioId, streamAudioAsset);
651
671
  call.resolve(status);
652
672
  } else {
653
673
  // Regular remote audio
654
- RemoteAudioAsset remoteAudioAsset = new RemoteAudioAsset(this, audioId, uri, audioChannelNum, volume);
674
+ RemoteAudioAsset remoteAudioAsset = new RemoteAudioAsset(
675
+ this,
676
+ audioId,
677
+ uri,
678
+ audioChannelNum,
679
+ volume,
680
+ requestHeaders
681
+ );
655
682
  remoteAudioAsset.setCompletionListener(this::dispatchComplete);
656
683
  audioAssetList.put(audioId, remoteAudioAsset);
657
684
  call.resolve(status);
@@ -18,6 +18,7 @@ import androidx.media3.exoplayer.source.MediaSource;
18
18
  import androidx.media3.exoplayer.source.ProgressiveMediaSource;
19
19
  import java.io.File;
20
20
  import java.util.ArrayList;
21
+ import java.util.Map;
21
22
 
22
23
  @UnstableApi
23
24
  public class RemoteAudioAsset extends AudioAsset {
@@ -36,13 +37,16 @@ public class RemoteAudioAsset extends AudioAsset {
36
37
  private float initialVolume;
37
38
  private Handler currentTimeHandler;
38
39
  private Runnable currentTimeRunnable;
40
+ private final Map<String, String> headers;
39
41
 
40
- public RemoteAudioAsset(NativeAudio owner, String assetId, Uri uri, int audioChannelNum, float volume) throws Exception {
42
+ public RemoteAudioAsset(NativeAudio owner, String assetId, Uri uri, int audioChannelNum, float volume, Map<String, String> headers)
43
+ throws Exception {
41
44
  super(owner, assetId, null, 0, volume);
42
45
  this.uri = uri;
43
46
  this.volume = volume;
44
47
  this.initialVolume = volume;
45
48
  this.players = new ArrayList<>();
49
+ this.headers = headers;
46
50
 
47
51
  if (audioChannelNum < 1) {
48
52
  audioChannelNum = 1;
@@ -87,12 +91,17 @@ public class RemoteAudioAsset extends AudioAsset {
87
91
  );
88
92
  }
89
93
 
90
- // Create cached data source factory
94
+ // Create cached data source factory with custom headers
91
95
  DefaultHttpDataSource.Factory httpDataSourceFactory = new DefaultHttpDataSource.Factory()
92
96
  .setAllowCrossProtocolRedirects(true)
93
97
  .setConnectTimeoutMs(15000)
94
98
  .setReadTimeoutMs(15000);
95
99
 
100
+ // Add custom headers if provided
101
+ if (headers != null && !headers.isEmpty()) {
102
+ httpDataSourceFactory.setDefaultRequestProperties(headers);
103
+ }
104
+
96
105
  CacheDataSource.Factory cacheDataSourceFactory = new CacheDataSource.Factory()
97
106
  .setCache(cache)
98
107
  .setUpstreamDataSourceFactory(httpDataSourceFactory)
@@ -301,10 +310,49 @@ public class RemoteAudioAsset extends AudioAsset {
301
310
 
302
311
  @Override
303
312
  public void unload() throws Exception {
304
- for (ExoPlayer player : players) {
305
- player.release();
313
+ @Override
314
+ public void unload() throws Exception {
315
+ if (Looper.myLooper() == Looper.getMainLooper()) {
316
+ // Synchronous cleanup when already on the main thread
317
+ stopCurrentTimeUpdates();
318
+ for (ExoPlayer player : new ArrayList<>(players)) {
319
+ try {
320
+ player.release();
321
+ } catch (Exception e) {
322
+ Log.w(TAG, "Error releasing player", e);
323
+ }
324
+ }
325
+ players.clear();
326
+ isPrepared = false;
327
+ playIndex = 0;
328
+ return;
306
329
  }
307
- players.clear();
330
+ // Ensure cleanup completes before returning when called off the main thread
331
+ final java.util.concurrent.CountDownLatch latch = new java.util.concurrent.CountDownLatch(1);
332
+ new Handler(Looper.getMainLooper()).post(() -> {
333
+ try {
334
+ stopCurrentTimeUpdates();
335
+ for (ExoPlayer player : new ArrayList<>(players)) {
336
+ try {
337
+ player.release();
338
+ } catch (Exception e) {
339
+ Log.w(TAG, "Error releasing player", e);
340
+ }
341
+ }
342
+ players.clear();
343
+ isPrepared = false;
344
+ playIndex = 0;
345
+ } finally {
346
+ latch.countDown();
347
+ }
348
+ });
349
+ try {
350
+ // Don't block forever; adjust timeout as needed
351
+ latch.await(2, java.util.concurrent.TimeUnit.SECONDS);
352
+ } catch (InterruptedException ie) {
353
+ Thread.currentThread().interrupt();
354
+ }
355
+ }
308
356
  }
309
357
 
310
358
  @Override
@@ -27,12 +27,15 @@ public class StreamAudioAsset extends AudioAsset {
27
27
  private static final float FADE_STEP = 0.05f;
28
28
  private static final int FADE_DELAY_MS = 80; // 80ms between steps
29
29
  private static final long LIVE_OFFSET_MS = 5000; // 5 seconds behind live
30
+ private final java.util.Map<String, String> headers;
30
31
 
31
- public StreamAudioAsset(NativeAudio owner, String assetId, Uri uri, float volume) throws Exception {
32
+ public StreamAudioAsset(NativeAudio owner, String assetId, Uri uri, float volume, java.util.Map<String, String> headers)
33
+ throws Exception {
32
34
  super(owner, assetId, null, 0, volume);
33
35
  this.uri = uri;
34
36
  this.volume = volume;
35
37
  this.initialVolume = volume;
38
+ this.headers = headers;
36
39
 
37
40
  createPlayer();
38
41
  }
@@ -74,6 +77,11 @@ public class StreamAudioAsset extends AudioAsset {
74
77
  .setReadTimeoutMs(15000)
75
78
  .setUserAgent("ExoPlayer");
76
79
 
80
+ // Add custom headers if provided
81
+ if (headers != null && !headers.isEmpty()) {
82
+ httpDataSourceFactory.setDefaultRequestProperties(headers);
83
+ }
84
+
77
85
  HlsMediaSource mediaSource = new HlsMediaSource.Factory(httpDataSourceFactory)
78
86
  .setAllowChunklessPreparation(true)
79
87
  .setTimestampAdjusterInitializationTimeoutMs(LIVE_OFFSET_MS) // 30 seconds timeout
@@ -216,6 +224,11 @@ public class StreamAudioAsset extends AudioAsset {
216
224
  .setReadTimeoutMs(15000)
217
225
  .setUserAgent("ExoPlayer");
218
226
 
227
+ // Add custom headers if provided
228
+ if (headers != null && !headers.isEmpty()) {
229
+ httpDataSourceFactory.setDefaultRequestProperties(headers);
230
+ }
231
+
219
232
  HlsMediaSource mediaSource = new HlsMediaSource.Factory(httpDataSourceFactory)
220
233
  .setAllowChunklessPreparation(true)
221
234
  .setTimestampAdjusterInitializationTimeoutMs(LIVE_OFFSET_MS)
@@ -461,6 +474,11 @@ public class StreamAudioAsset extends AudioAsset {
461
474
  .setReadTimeoutMs(15000)
462
475
  .setUserAgent("ExoPlayer");
463
476
 
477
+ // Add custom headers if provided
478
+ if (headers != null && !headers.isEmpty()) {
479
+ httpDataSourceFactory.setDefaultRequestProperties(headers);
480
+ }
481
+
464
482
  HlsMediaSource mediaSource = new HlsMediaSource.Factory(httpDataSourceFactory)
465
483
  .setAllowChunklessPreparation(true)
466
484
  .setTimestampAdjusterInitializationTimeoutMs(LIVE_OFFSET_MS)
package/dist/docs.json CHANGED
@@ -659,8 +659,13 @@
659
659
  },
660
660
  {
661
661
  "name": "showNotification",
662
- "tags": [],
663
- "docs": "Show audio playback in the notification center (iOS and Android)\nWhen enabled, displays audio metadata (title, artist, album, artwork) in the system notification",
662
+ "tags": [
663
+ {
664
+ "text": "https ://github.com/Cap-go/capacitor-native-audio/issues/202",
665
+ "name": "see"
666
+ }
667
+ ],
668
+ "docs": "Show audio playback in the notification center (iOS and Android)\nWhen enabled, displays audio metadata (title, artist, album, artwork) in the system notification\nand Control Center (iOS) or lock screen.\n\n**Important iOS Behavior:**\nEnabling this option changes the audio session category to `.playback` with `.default` mode,\nwhich means your app's audio will **interrupt** other apps' audio (like background music from\nSpotify, Apple Music, etc.) instead of mixing with it. This is required for the Now Playing\ninfo 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\nUse this when your app is the primary audio source (music players, podcast apps, etc.).\nDisable this for secondary audio like sound effects or notification sounds where mixing\nwith background music is preferred.",
664
669
  "complexTypes": [],
665
670
  "type": "boolean | undefined"
666
671
  }
@@ -710,19 +715,38 @@
710
715
  },
711
716
  {
712
717
  "name": "notificationMetadata",
713
- "tags": [],
714
- "docs": "Metadata to display in the notification center when audio is playing\nOnly used when showNotification is enabled in configure()",
718
+ "tags": [
719
+ {
720
+ "text": "NotificationMetadata",
721
+ "name": "see"
722
+ }
723
+ ],
724
+ "docs": "Metadata to display in the notification center when audio is playing.\nOnly used when `showNotification: true` is set in `configure()`.\n\nSee {@link ConfigureOptions.showNotification} for important details about\nhow this affects audio mixing behavior on iOS.",
715
725
  "complexTypes": [
716
726
  "NotificationMetadata"
717
727
  ],
718
728
  "type": "NotificationMetadata"
729
+ },
730
+ {
731
+ "name": "headers",
732
+ "tags": [
733
+ {
734
+ "text": "7.10.0",
735
+ "name": "since"
736
+ }
737
+ ],
738
+ "docs": "Custom HTTP headers to include when fetching remote audio files.\nOnly used when isUrl is true and assetPath is a remote URL (http/https).\nExample: { 'x-api-key': 'abc123', 'Authorization': 'Bearer token' }",
739
+ "complexTypes": [
740
+ "Record"
741
+ ],
742
+ "type": "Record<string, string>"
719
743
  }
720
744
  ]
721
745
  },
722
746
  {
723
747
  "name": "NotificationMetadata",
724
748
  "slug": "notificationmetadata",
725
- "docs": "",
749
+ "docs": "Metadata to display in the notification center, Control Center (iOS), and lock screen\nwhen `showNotification` is enabled in `configure()`.\n\nNote: This metadata will only be displayed if `showNotification: true` is set in the\n`configure()` method. See {@link ConfigureOptions.showNotification} for important\nbehavior details about audio mixing on iOS.",
726
750
  "tags": [],
727
751
  "methods": [],
728
752
  "properties": [
@@ -845,6 +869,20 @@
845
869
  ],
846
870
  "enums": [],
847
871
  "typeAliases": [
872
+ {
873
+ "name": "Record",
874
+ "slug": "record",
875
+ "docs": "Construct a type with a set of properties K of type T",
876
+ "types": [
877
+ {
878
+ "text": "{\r\n [P in K]: T;\r\n}",
879
+ "complexTypes": [
880
+ "K",
881
+ "T"
882
+ ]
883
+ }
884
+ ]
885
+ },
848
886
  {
849
887
  "name": "CompletedListener",
850
888
  "slug": "completedlistener",
@@ -68,9 +68,34 @@ export interface ConfigureOptions {
68
68
  /**
69
69
  * Show audio playback in the notification center (iOS and Android)
70
70
  * When enabled, displays audio metadata (title, artist, album, artwork) in the system notification
71
+ * and Control Center (iOS) or lock screen.
72
+ *
73
+ * **Important iOS Behavior:**
74
+ * Enabling this option changes the audio session category to `.playback` with `.default` mode,
75
+ * which means your app's audio will **interrupt** other apps' audio (like background music from
76
+ * Spotify, Apple Music, etc.) instead of mixing with it. This is required for the Now Playing
77
+ * info to appear in Control Center and on the lock screen.
78
+ *
79
+ * **Trade-offs:**
80
+ * - `showNotification: true` → Shows Now Playing controls, but interrupts other audio
81
+ * - `showNotification: false` → Audio mixes with other apps, but no Now Playing controls
82
+ *
83
+ * Use this when your app is the primary audio source (music players, podcast apps, etc.).
84
+ * Disable this for secondary audio like sound effects or notification sounds where mixing
85
+ * with background music is preferred.
86
+ *
87
+ * @see https://github.com/Cap-go/capacitor-native-audio/issues/202
71
88
  */
72
89
  showNotification?: boolean;
73
90
  }
91
+ /**
92
+ * Metadata to display in the notification center, Control Center (iOS), and lock screen
93
+ * when `showNotification` is enabled in `configure()`.
94
+ *
95
+ * Note: This metadata will only be displayed if `showNotification: true` is set in the
96
+ * `configure()` method. See {@link ConfigureOptions.showNotification} for important
97
+ * behavior details about audio mixing on iOS.
98
+ */
74
99
  export interface NotificationMetadata {
75
100
  /**
76
101
  * The title to display in the notification center
@@ -115,10 +140,23 @@ export interface PreloadOptions {
115
140
  */
116
141
  isUrl?: boolean;
117
142
  /**
118
- * Metadata to display in the notification center when audio is playing
119
- * Only used when showNotification is enabled in configure()
143
+ * Metadata to display in the notification center when audio is playing.
144
+ * Only used when `showNotification: true` is set in `configure()`.
145
+ *
146
+ * See {@link ConfigureOptions.showNotification} for important details about
147
+ * how this affects audio mixing behavior on iOS.
148
+ *
149
+ * @see NotificationMetadata
120
150
  */
121
151
  notificationMetadata?: NotificationMetadata;
152
+ /**
153
+ * Custom HTTP headers to include when fetching remote audio files.
154
+ * Only used when isUrl is true and assetPath is a remote URL (http/https).
155
+ * Example: { 'x-api-key': 'abc123', 'Authorization': 'Bearer token' }
156
+ *
157
+ * @since 7.10.0
158
+ */
159
+ headers?: Record<string, string>;
122
160
  }
123
161
  export interface CurrentTimeEvent {
124
162
  /**
@@ -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 */\n showNotification?: boolean;\n}\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 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 is enabled in configure()\n */\n notificationMetadata?: NotificationMetadata;\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 * 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}\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\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 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 * 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"]}
@@ -13,7 +13,7 @@ enum MyError: Error {
13
13
  // swiftlint:disable type_body_length file_length
14
14
  @objc(NativeAudio)
15
15
  public class NativeAudio: CAPPlugin, AVAudioPlayerDelegate, CAPBridgedPlugin {
16
- private let pluginVersion: String = "7.9.8"
16
+ private let pluginVersion: String = "7.9.9"
17
17
  public let identifier = "NativeAudio"
18
18
  public let jsName = "NativeAudio"
19
19
  public let pluginMethods: [CAPPluginMethod] = [
@@ -254,7 +254,21 @@ public class NativeAudio: CAPPlugin, AVAudioPlayerDelegate, CAPBridgedPlugin {
254
254
  // Use a single audio session configuration block for better atomicity
255
255
  do {
256
256
  // Set category first
257
- if focus {
257
+ // Fix for issue #202: When showNotification is enabled, use .playback without
258
+ // .mixWithOthers or .duckOthers to allow Now Playing info to display in
259
+ // Control Center and lock screen.
260
+ //
261
+ // IMPORTANT: This is a behavior trade-off:
262
+ // - With .playback + .default mode: Now Playing info shows, but interrupts other audio
263
+ // - With .mixWithOthers or .duckOthers: Audio mixes, but no Now Playing info
264
+ //
265
+ // This is required because iOS only shows Now Playing controls for audio sessions
266
+ // that use the .playback category without mixing options. This means the app becomes
267
+ // the primary audio source and will interrupt background music from other apps.
268
+ if self.showNotification {
269
+ // Use playback category with default mode for notification support
270
+ try self.session.setCategory(AVAudioSession.Category.playback, mode: .default)
271
+ } else if focus {
258
272
  try self.session.setCategory(AVAudioSession.Category.playback, options: .duckOthers)
259
273
  } else if !ignoreSilent {
260
274
  try self.session.setCategory(AVAudioSession.Category.ambient, options: focus ? .duckOthers : .mixWithOthers)
@@ -667,7 +681,17 @@ public class NativeAudio: CAPPlugin, AVAudioPlayerDelegate, CAPBridgedPlugin {
667
681
  }
668
682
  } else {
669
683
  // Handle remote URL
670
- let remoteAudioAsset = RemoteAudioAsset(owner: self, withAssetId: audioId, withPath: assetPath, withChannels: channels, withVolume: volume, withFadeDelay: delay)
684
+ // Extract headers if provided
685
+ var headers: [String: String]?
686
+ if let headersObj = call.getObject("headers") {
687
+ headers = [:]
688
+ for (key, value) in headersObj {
689
+ if let stringValue = value as? String {
690
+ headers?[key] = stringValue
691
+ }
692
+ }
693
+ }
694
+ let remoteAudioAsset = RemoteAudioAsset(owner: self, withAssetId: audioId, withPath: assetPath, withChannels: channels, withVolume: volume, withFadeDelay: delay, withHeaders: headers)
671
695
  self.audioList[audioId] = remoteAudioAsset
672
696
  call.resolve()
673
697
  return
@@ -12,7 +12,7 @@ public class RemoteAudioAsset: AudioAsset {
12
12
  var duration: TimeInterval = 0
13
13
  var asset: AVURLAsset?
14
14
 
15
- override init(owner: NativeAudio, withAssetId assetId: String, withPath path: String!, withChannels channels: Int!, withVolume volume: Float!, withFadeDelay delay: Float!) {
15
+ init(owner: NativeAudio, withAssetId assetId: String, withPath path: String!, withChannels channels: Int!, withVolume volume: Float!, withFadeDelay delay: Float!, withHeaders headers: [String: String]?) {
16
16
  super.init(owner: owner, withAssetId: assetId, withPath: path, withChannels: channels ?? 1, withVolume: volume ?? 1.0, withFadeDelay: delay ?? 0.0)
17
17
 
18
18
  owner.executeOnAudioQueue { [weak self] in
@@ -23,7 +23,13 @@ public class RemoteAudioAsset: AudioAsset {
23
23
  return
24
24
  }
25
25
 
26
- let asset = AVURLAsset(url: url, options: [AVURLAssetPreferPreciseDurationAndTimingKey: true])
26
+ // Build AVURLAsset options with custom headers if provided
27
+ var options: [String: Any] = [AVURLAssetPreferPreciseDurationAndTimingKey: true]
28
+ if let headers = headers, !headers.isEmpty {
29
+ options["AVURLAssetHTTPHeaderFieldsKey"] = headers
30
+ }
31
+
32
+ let asset = AVURLAsset(url: url, options: options)
27
33
  self.asset = asset
28
34
 
29
35
  // Limit channels to a reasonable maximum to prevent resource issues
package/package.json CHANGED
@@ -1,8 +1,8 @@
1
1
  {
2
2
  "name": "@capgo/native-audio",
3
- "version": "7.9.8",
3
+ "version": "7.9.10",
4
4
  "description": "A native plugin for native audio engine",
5
- "license": "MIT",
5
+ "license": "MPL-2.0",
6
6
  "main": "dist/plugin.cjs.js",
7
7
  "module": "dist/esm/index.js",
8
8
  "types": "dist/esm/index.d.ts",