@capgo/native-audio 7.11.2 → 8.1.0

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.
@@ -11,6 +11,6 @@ Pod::Spec.new do |s|
11
11
  s.author = package['author']
12
12
  s.source = { :git => package['repository']['url'], :tag => s.version.to_s }
13
13
  s.source_files = 'ios/Sources/**/*.{swift,h,m,c,cc,mm,cpp}'
14
- s.ios.deployment_target = '14.0'
14
+ s.ios.deployment_target = '15.0'
15
15
  s.dependency 'Capacitor'
16
16
  end
package/Package.swift CHANGED
@@ -13,7 +13,7 @@ let package = Package(
13
13
  )
14
14
  ],
15
15
  dependencies: [
16
- .package(url: "https://github.com/ionic-team/capacitor-swift-pm.git", from: "7.0.0")
16
+ .package(url: "https://github.com/ionic-team/capacitor-swift-pm.git", from: "8.0.0")
17
17
  ],
18
18
  targets: [
19
19
  .target(
package/README.md CHANGED
@@ -243,6 +243,71 @@ The media control buttons automatically handle:
243
243
  - iOS: Uses MPNowPlayingInfoCenter with MPRemoteCommandCenter
244
244
  - Android: Uses MediaSession with NotificationCompat.MediaStyle
245
245
 
246
+ ## Play Once (Fire-and-Forget) @since 7.11.0
247
+
248
+ For simple one-shot audio playback (sound effects, notifications, etc.), use `playOnce()` which handles the entire asset lifecycle automatically:
249
+
250
+ ```typescript
251
+ // Basic usage - automatic cleanup after playback
252
+ await NativeAudio.playOnce({
253
+ assetPath: 'audio/notification.mp3',
254
+ });
255
+
256
+ // With volume control
257
+ await NativeAudio.playOnce({
258
+ assetPath: 'audio/beep.wav',
259
+ volume: 0.8,
260
+ });
261
+
262
+ // Remote audio with notification metadata
263
+ await NativeAudio.playOnce({
264
+ assetPath: 'https://example.com/audio.mp3',
265
+ isUrl: true,
266
+ autoPlay: true,
267
+ notificationMetadata: {
268
+ title: 'Song Name',
269
+ artist: 'Artist Name',
270
+ }
271
+ });
272
+
273
+ // Temporary file with automatic deletion
274
+ await NativeAudio.playOnce({
275
+ assetPath: 'file:///path/to/temp-audio.wav',
276
+ deleteAfterPlay: true, // File deleted after playback completes
277
+ volume: 0.5,
278
+ });
279
+ ```
280
+
281
+ #### Advanced: Manual Control
282
+
283
+ If you need to control playback timing, set `autoPlay: false` and use the returned `assetId`:
284
+
285
+ ```typescript
286
+ const { assetId } = await NativeAudio.playOnce({
287
+ assetPath: 'audio/sound.wav',
288
+ autoPlay: false,
289
+ });
290
+
291
+ // Play later when needed
292
+ await NativeAudio.play({ assetId });
293
+
294
+ // Stop if needed (will auto-cleanup)
295
+ await NativeAudio.stop({ assetId });
296
+ ```
297
+
298
+ **Key Features:**
299
+ - ✅ Automatic asset loading and unloading
300
+ - ✅ Cleanup on completion or error
301
+ - ✅ Optional file deletion after playback
302
+ - ✅ Notification metadata support
303
+ - ✅ Works with local files and remote URLs
304
+
305
+ **Notes:**
306
+ - Assets are automatically cleaned up after playback completes or on error
307
+ - `deleteAfterPlay` only works for local `file://` URLs, not remote URLs
308
+ - The returned `assetId` can be used with `play()`, `stop()`, `unload()` methods
309
+ - Manual cleanup via `stop()` or `unload()` is optional but supported
310
+
246
311
  ## Example app
247
312
 
248
313
  This repository now ships with an interactive Capacitor project under `example/` that exercises the main APIs on web, iOS, and Android shells.
@@ -403,6 +468,45 @@ Load an audio file
403
468
  --------------------
404
469
 
405
470
 
471
+ ### playOnce(...)
472
+
473
+ ```typescript
474
+ playOnce(options: PlayOnceOptions) => Promise<PlayOnceResult>
475
+ ```
476
+
477
+ Play an audio file once with automatic cleanup
478
+
479
+ Method designed for simple, single-shot audio playback,
480
+ such as notification sounds, UI feedback, or other short audio clips
481
+ that don't require manual state management.
482
+
483
+ **Key Features:**
484
+ - **Fire-and-forget**: No need to manually preload, play, stop, or unload
485
+ - **Auto-cleanup**: Asset is automatically unloaded after playback completes
486
+ - **Optional file deletion**: Can delete local files after playback (useful for temp files)
487
+ - **Returns assetId**: Can still control playback if needed (pause, stop, etc.)
488
+
489
+ **Use Cases:**
490
+ - Notification sounds
491
+ - UI sound effects (button clicks, alerts)
492
+ - Short audio clips that play once
493
+ - Temporary audio files that should be cleaned up
494
+
495
+ **Comparison with regular play():**
496
+ - `play()`: Requires manual preload, play, and unload steps
497
+ - `playOnce()`: Handles everything automatically with a single call
498
+
499
+ | Param | Type |
500
+ | ------------- | ----------------------------------------------------------- |
501
+ | **`options`** | <code><a href="#playonceoptions">PlayOnceOptions</a></code> |
502
+
503
+ **Returns:** <code>Promise&lt;<a href="#playonceresult">PlayOnceResult</a>&gt;</code>
504
+
505
+ **Since:** 7.11.0
506
+
507
+ --------------------
508
+
509
+
406
510
  ### isPreloaded(...)
407
511
 
408
512
  ```typescript
@@ -760,6 +864,26 @@ behavior details about audio mixing on iOS.
760
864
  | **`artworkUrl`** | <code>string</code> | URL or local path to the artwork/album art image |
761
865
 
762
866
 
867
+ #### PlayOnceResult
868
+
869
+ | Prop | Type | Description |
870
+ | ------------- | ------------------- | ------------------------------------------------------------------------------------------------------------------------- |
871
+ | **`assetId`** | <code>string</code> | The internally generated asset ID for this playback Can be used to control playback (pause, stop, etc.) before completion |
872
+
873
+
874
+ #### PlayOnceOptions
875
+
876
+ | Prop | Type | Description | Default | Since |
877
+ | -------------------------- | --------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------ | ------ |
878
+ | **`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) | | |
879
+ | **`volume`** | <code>number</code> | Volume of the audio, between 0.1 and 1.0 | <code>1.0</code> | |
880
+ | **`isUrl`** | <code>boolean</code> | Is the audio file a URL, pass true if assetPath is a `file://` url or a streaming URL (m3u8) | <code>false</code> | |
881
+ | **`autoPlay`** | <code>boolean</code> | Automatically start playback after loading | <code>true</code> | |
882
+ | **`deleteAfterPlay`** | <code>boolean</code> | Delete the audio file from disk after playback completes Only works for local files (file:// URLs), ignored for remote URLs | <code>false</code> | 7.11.0 |
883
+ | **`notificationMetadata`** | <code><a href="#notificationmetadata">NotificationMetadata</a></code> | Metadata to display in the notification center when audio is playing. Only used when `showNotification: true` is set in `configure()`. See {@link <a href="#configureoptions">ConfigureOptions.showNotification</a>} for important details about how this affects audio mixing behavior on iOS. | | 7.10.0 |
884
+ | **`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 |
885
+
886
+
763
887
  #### Assets
764
888
 
765
889
  | Prop | Type | Description |
@@ -1,8 +1,8 @@
1
1
  ext {
2
2
  junitVersion = project.hasProperty('junitVersion') ? rootProject.ext.junitVersion : '4.13.2'
3
- androidxAppCompatVersion = project.hasProperty('androidxAppCompatVersion') ? rootProject.ext.androidxAppCompatVersion : '1.7.0'
4
- androidxJunitVersion = project.hasProperty('androidxJunitVersion') ? rootProject.ext.androidxJunitVersion : '1.2.1'
5
- androidxEspressoCoreVersion = project.hasProperty('androidxEspressoCoreVersion') ? rootProject.ext.androidxEspressoCoreVersion : '3.6.1'
3
+ androidxAppCompatVersion = project.hasProperty('androidxAppCompatVersion') ? rootProject.ext.androidxAppCompatVersion : '1.7.1'
4
+ androidxJunitVersion = project.hasProperty('androidxJunitVersion') ? rootProject.ext.androidxJunitVersion : '1.3.0'
5
+ androidxEspressoCoreVersion = project.hasProperty('androidxEspressoCoreVersion') ? rootProject.ext.androidxEspressoCoreVersion : '3.7.0'
6
6
 
7
7
  // Read HLS configuration from gradle.properties (set by hook script)
8
8
  // Default to 'true' for backward compatibility
@@ -15,18 +15,18 @@ buildscript {
15
15
  mavenCentral()
16
16
  }
17
17
  dependencies {
18
- classpath 'com.android.tools.build:gradle:8.7.3'
18
+ classpath 'com.android.tools.build:gradle:8.13.0'
19
19
  }
20
20
  }
21
21
 
22
22
  apply plugin: 'com.android.library'
23
23
 
24
24
  android {
25
- namespace "ee.forgr.audio.nativeaudio"
26
- compileSdk project.hasProperty('compileSdkVersion') ? rootProject.ext.compileSdkVersion : 35
25
+ namespace = "ee.forgr.audio.nativeaudio"
26
+ compileSdk = project.hasProperty('compileSdkVersion') ? rootProject.ext.compileSdkVersion : 36
27
27
  defaultConfig {
28
- minSdkVersion project.hasProperty('minSdkVersion') ? rootProject.ext.minSdkVersion : 23
29
- targetSdkVersion project.hasProperty('targetSdkVersion') ? rootProject.ext.targetSdkVersion : 35
28
+ minSdkVersion project.hasProperty('minSdkVersion') ? rootProject.ext.minSdkVersion : 24
29
+ targetSdkVersion project.hasProperty('targetSdkVersion') ? rootProject.ext.targetSdkVersion : 36
30
30
  versionCode 1
31
31
  versionName "1.0"
32
32
  testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
@@ -38,7 +38,7 @@ android {
38
38
  }
39
39
  }
40
40
  lintOptions {
41
- abortOnError false
41
+ abortOnError = false
42
42
  }
43
43
  compileOptions {
44
44
  sourceCompatibility JavaVersion.VERSION_21