@capgo/native-audio 6.4.4 → 6.4.5

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.
@@ -293,7 +293,7 @@ public class NativeAudio: CAPPlugin, AVAudioPlayerDelegate {
293
293
  let channels: Int?
294
294
  let volume: Float?
295
295
  let delay: Float?
296
- var isLocalUrl: Bool = call.getBool("isUrl") ?? false // Existing flag for local URLs
296
+ var isLocalUrl: Bool = call.getBool("isUrl") ?? false
297
297
 
298
298
  if audioId != "" {
299
299
  var assetPath: String = call.getString(Constant.AssetPathKey) ?? ""
@@ -324,25 +324,27 @@ public class NativeAudio: CAPPlugin, AVAudioPlayerDelegate {
324
324
  self.audioList[audioId] = remoteAudioAsset
325
325
  call.resolve()
326
326
  } else if isLocalUrl == false {
327
- // if assetPath dont start with public/ add it
327
+ // Handle public folder
328
+ // if assetPath doesnt start with public/ add it
328
329
  assetPath = assetPath.starts(with: "public/") ? assetPath : "public/" + assetPath
329
330
 
330
331
  let assetPathSplit = assetPath.components(separatedBy: ".")
331
332
  basePath = Bundle.main.path(forResource: assetPathSplit[0], ofType: assetPathSplit[1])
332
333
  } else {
333
- let url = URL(string: assetPath)
334
- basePath = url!.path
334
+ // Handle local file URL
335
+ let fileURL = URL(fileURLWithPath: assetPath)
336
+ basePath = fileURL.path
335
337
  }
336
338
 
337
- if FileManager.default.fileExists(atPath: basePath ?? "") {
339
+ if let basePath = basePath, FileManager.default.fileExists(atPath: basePath) {
338
340
  if !complex {
339
- let soundFileUrl = URL(fileURLWithPath: basePath ?? "")
341
+ let soundFileUrl = URL(fileURLWithPath: basePath)
340
342
  var soundId = SystemSoundID()
341
343
  AudioServicesCreateSystemSoundID(soundFileUrl as CFURL, &soundId)
342
344
  self.audioList[audioId] = NSNumber(value: Int32(soundId))
343
345
  call.resolve()
344
346
  } else {
345
- let audioAsset: AudioAsset = AudioAsset(
347
+ let audioAsset = AudioAsset(
346
348
  owner: self,
347
349
  withAssetId: audioId, withPath: basePath, withChannels: channels,
348
350
  withVolume: volume, withFadeDelay: delay)
@@ -350,7 +352,26 @@ public class NativeAudio: CAPPlugin, AVAudioPlayerDelegate {
350
352
  call.resolve()
351
353
  }
352
354
  } else {
353
- call.reject(Constant.ErrorAssetPath + " - " + assetPath)
355
+ if FileManager.default.fileExists(atPath: assetPath) {
356
+ // Use the original assetPath
357
+ if !complex {
358
+ let soundFileUrl = URL(fileURLWithPath: assetPath)
359
+ var soundId = SystemSoundID()
360
+ AudioServicesCreateSystemSoundID(soundFileUrl as CFURL, &soundId)
361
+ self.audioList[audioId] = NSNumber(value: Int32(soundId))
362
+ call.resolve()
363
+ } else {
364
+ let audioAsset = AudioAsset(
365
+ owner: self,
366
+ withAssetId: audioId, withPath: assetPath, withChannels: channels,
367
+ withVolume: volume, withFadeDelay: delay)
368
+ self.audioList[audioId] = audioAsset
369
+ call.resolve()
370
+ }
371
+ } else {
372
+ let attributes = try? FileManager.default.attributesOfItem(atPath: assetPath)
373
+ call.reject(Constant.ErrorAssetPath + " - " + assetPath)
374
+ }
354
375
  }
355
376
  } else {
356
377
  call.reject(Constant.ErrorAssetAlreadyLoaded + " - " + audioId)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@capgo/native-audio",
3
- "version": "6.4.4",
3
+ "version": "6.4.5",
4
4
  "description": "A native plugin for native audio engine",
5
5
  "main": "dist/plugin.js",
6
6
  "module": "dist/esm/index.js",
@@ -82,5 +82,6 @@
82
82
  },
83
83
  "publishConfig": {
84
84
  "access": "public"
85
- }
85
+ },
86
+ "packageManager": "pnpm@9.7.0+sha512.dc09430156b427f5ecfc79888899e1c39d2d690f004be70e05230b72cb173d96839587545d09429b55ac3c429c801b4dc3c0e002f653830a420fa2dd4e3cf9cf"
86
87
  }