@capgo/capacitor-native-audio 8.4.16 → 8.4.17

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.
@@ -3,11 +3,14 @@ import AVFoundation
3
3
  extension AudioAsset {
4
4
 
5
5
  func dispatchComplete() {
6
- if dispatchedCompleteMap[assetId] == true {
7
- return
6
+ owner?.executeOnAudioQueueAsync { [weak self] in
7
+ guard let self else { return }
8
+ if self.dispatchedCompleteMap[self.assetId] == true {
9
+ return
10
+ }
11
+ self.owner?.notifyListeners("complete", data: ["assetId": self.assetId])
12
+ self.dispatchedCompleteMap[self.assetId] = true
8
13
  }
9
- owner?.notifyListeners("complete", data: ["assetId": assetId])
10
- dispatchedCompleteMap[assetId] = true
11
14
  }
12
15
 
13
16
  func cancelFade() {
@@ -384,7 +384,10 @@ public class AudioAsset: NSObject, AVAudioPlayerDelegate {
384
384
 
385
385
  internal func startCurrentTimeUpdates() {
386
386
  stopCurrentTimeUpdates()
387
- dispatchedCompleteMap[assetId] = false
387
+ owner?.executeOnAudioQueueAsync { [weak self] in
388
+ guard let self else { return }
389
+ self.dispatchedCompleteMap[self.assetId] = false
390
+ }
388
391
  DispatchQueue.main.async { [weak self] in
389
392
  guard let self else { return }
390
393
  let timer = Timer(timeInterval: 0.1, repeats: true) { [weak self] _ in
@@ -18,7 +18,7 @@ private enum PlaybackStateValue: String {
18
18
  @objc(NativeAudio)
19
19
  // swiftlint:disable:next type_body_length
20
20
  public class NativeAudio: CAPPlugin, AVAudioPlayerDelegate, CAPBridgedPlugin {
21
- private let pluginVersion: String = "8.4.16"
21
+ private let pluginVersion: String = "8.4.17"
22
22
  public let identifier = "NativeAudio"
23
23
  public let jsName = "NativeAudio"
24
24
  public let pluginMethods: [CAPPluginMethod] = [
@@ -1565,6 +1565,17 @@ public class NativeAudio: CAPPlugin, AVAudioPlayerDelegate, CAPBridgedPlugin {
1565
1565
  }
1566
1566
  }
1567
1567
 
1568
+ /// Async barrier write — serializes shared-state mutations onto the audio queue
1569
+ /// WITHOUT blocking the calling thread. Runs inline when already on the queue
1570
+ /// to preserve ordering.
1571
+ internal func executeOnAudioQueueAsync(_ block: @escaping () -> Void) {
1572
+ if DispatchQueue.getSpecific(key: queueKey) != nil {
1573
+ block()
1574
+ } else {
1575
+ audioQueue.async(flags: .barrier, execute: block)
1576
+ }
1577
+ }
1578
+
1568
1579
  /// Use this for read-only access to shared state — avoids the .barrier write lock
1569
1580
  /// that `executeOnAudioQueue` applies, preventing deadlocks with third-party SDKs.
1570
1581
  internal func readOnAudioQueue<T>(_ block: () -> T) -> T {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@capgo/capacitor-native-audio",
3
- "version": "8.4.16",
3
+ "version": "8.4.17",
4
4
  "description": "A native plugin for native audio engine",
5
5
  "license": "MPL-2.0",
6
6
  "main": "dist/plugin.cjs.js",