Skip to content

Commit

Permalink
Merge pull request #50 from riderx/patch-1
Browse files Browse the repository at this point in the history
fix: deprecated warning
  • Loading branch information
bazuka5801 authored Feb 23, 2022
2 parents 59c7fe6 + 23362c5 commit f8f5fdb
Showing 1 changed file with 15 additions and 18 deletions.
33 changes: 15 additions & 18 deletions ios/Plugin/Plugin.swift
Original file line number Diff line number Diff line change
Expand Up @@ -61,15 +61,15 @@ public class NativeAudio: CAPPlugin {
audioAsset?.play(time: time)
}

call.success()
call.resolve()
} else if (asset is Int32) {
let audioAsset = asset as? NSNumber ?? 0

AudioServicesPlaySystemSound(SystemSoundID(audioAsset.intValue ))

call.success()
call.resolve()
} else {
call.error(Constant.ErrorAssetNotFound)
call.reject(Constant.ErrorAssetNotFound)
}
}
}
Expand All @@ -80,7 +80,7 @@ public class NativeAudio: CAPPlugin {
@objc private func getAudioAsset(_ call: CAPPluginCall) -> AudioAsset? {
let audioId = call.getString(Constant.AssetIdKey) ?? ""
if audioId == "" {
call.error(Constant.ErrorAssetId)
call.reject(Constant.ErrorAssetId)
return nil
}
if self.audioList.count > 0 {
Expand All @@ -89,7 +89,7 @@ public class NativeAudio: CAPPlugin {
return asset as? AudioAsset
}
}
call.error(Constant.ErrorAssetNotFound + " - " + audioId)
call.reject(Constant.ErrorAssetNotFound + " - " + audioId)
return nil
}

Expand Down Expand Up @@ -120,16 +120,16 @@ public class NativeAudio: CAPPlugin {
}

audioAsset.resume()
call.success()
call.resolve()
}

@objc func pause(_ call: CAPPluginCall) {
guard let audioAsset: AudioAsset = self.getAudioAsset(call) else {
return
return
}

audioAsset.pause()
call.success()
call.resolve()
}

@objc func stop(_ call: CAPPluginCall) {
Expand All @@ -138,7 +138,7 @@ public class NativeAudio: CAPPlugin {
do {
try stopAudio(audioId: audioId)
} catch {
call.error(Constant.ErrorAssetNotFound)
call.reject(Constant.ErrorAssetNotFound)
}
}

Expand All @@ -148,7 +148,7 @@ public class NativeAudio: CAPPlugin {
}

audioAsset.loop()
call.success()
call.resolve()
}

@objc func unload(_ call: CAPPluginCall) {
Expand All @@ -162,7 +162,7 @@ public class NativeAudio: CAPPlugin {
}
}

call.success()
call.resolve()
}

@objc func setVolume(_ call: CAPPluginCall) {
Expand All @@ -173,7 +173,7 @@ public class NativeAudio: CAPPlugin {
let volume = call.getFloat(Constant.Volume) ?? 1.0

audioAsset.setVolume(volume: volume as NSNumber)
call.success()
call.resolve()
}

private func preloadAsset(_ call: CAPPluginCall, isComplex complex: Bool) {
Expand Down Expand Up @@ -224,17 +224,14 @@ public class NativeAudio: CAPPlugin {

AudioServicesCreateSystemSoundID(soundFileUrl, &soundId)
self.audioList[audioId] = NSNumber(value: Int32(soundId))

call.success()
call.resolve()
} else {
let audioAsset: AudioAsset = AudioAsset(owner: self, withAssetId: audioId, withPath: basePath, withChannels: channels, withVolume: volume as NSNumber?, withFadeDelay: delay)

self.audioList[audioId] = audioAsset

call.success()
call.resolve()
}
} else {
call.error(Constant.ErrorAssetPath + " - " + assetPath)
call.reject(Constant.ErrorAssetPath + " - " + assetPath)
}
}
}
Expand Down

0 comments on commit f8f5fdb

Please sign in to comment.