@capgo/native-audio 5.1.3 → 5.1.13

Sign up to get free protection for your applications and to get access to all the features.
package/dist/plugin.js CHANGED
@@ -1,7 +1,7 @@
1
1
  var capacitorApp = (function (exports, core) {
2
2
  'use strict';
3
3
 
4
- const NativeAudio$1 = core.registerPlugin('NativeAudio', {
4
+ const NativeAudio$1 = core.registerPlugin("NativeAudio", {
5
5
  web: () => Promise.resolve().then(function () { return web; }).then((m) => new m.NativeAudioWeb()),
6
6
  });
7
7
 
@@ -14,8 +14,8 @@ var capacitorApp = (function (exports, core) {
14
14
  class NativeAudioWeb extends core.WebPlugin {
15
15
  constructor() {
16
16
  super({
17
- name: 'NativeAudio',
18
- platforms: ['web'],
17
+ name: "NativeAudio",
18
+ platforms: ["web"],
19
19
  });
20
20
  }
21
21
  async resume(options) {
@@ -35,10 +35,10 @@ var capacitorApp = (function (exports, core) {
35
35
  async getDuration(options) {
36
36
  const audio = this.getAudioAsset(options.assetId).audio;
37
37
  if (Number.isNaN(audio.duration)) {
38
- throw 'no duration available';
38
+ throw "no duration available";
39
39
  }
40
40
  if (!Number.isFinite(audio.duration)) {
41
- throw 'duration not available => media resource is streaming';
41
+ throw "duration not available => media resource is streaming";
42
42
  }
43
43
  return { duration: audio.duration };
44
44
  }
@@ -48,19 +48,20 @@ var capacitorApp = (function (exports, core) {
48
48
  async preload(options) {
49
49
  var _a;
50
50
  if (NativeAudioWeb.AUDIO_ASSET_BY_ASSET_ID.has(options.assetId)) {
51
- throw 'AssetId already exists. Unload first if like to change!';
51
+ throw "AssetId already exists. Unload first if like to change!";
52
52
  }
53
53
  if (!((_a = options.assetPath) === null || _a === void 0 ? void 0 : _a.length)) {
54
- throw 'no assetPath provided';
54
+ throw "no assetPath provided";
55
55
  }
56
- if (!options.isUrl && !new RegExp('^/?' + NativeAudioWeb.FILE_LOCATION).test(options.assetPath)) {
57
- const slashPrefix = options.assetPath.startsWith('/') ? '' : '/';
56
+ if (!options.isUrl &&
57
+ !new RegExp("^/?" + NativeAudioWeb.FILE_LOCATION).test(options.assetPath)) {
58
+ const slashPrefix = options.assetPath.startsWith("/") ? "" : "/";
58
59
  options.assetPath = `${NativeAudioWeb.FILE_LOCATION}${slashPrefix}${options.assetPath}`;
59
60
  }
60
61
  const audio = new Audio(options.assetPath);
61
62
  audio.autoplay = false;
62
63
  audio.loop = false;
63
- audio.preload = 'auto';
64
+ audio.preload = "auto";
64
65
  if (options.volume) {
65
66
  audio.volume = options.volume;
66
67
  }
@@ -91,15 +92,15 @@ var capacitorApp = (function (exports, core) {
91
92
  NativeAudioWeb.AUDIO_ASSET_BY_ASSET_ID.delete(options.assetId);
92
93
  }
93
94
  async setVolume(options) {
94
- if (typeof (options === null || options === void 0 ? void 0 : options.volume) !== 'number') {
95
- throw 'no volume provided';
95
+ if (typeof (options === null || options === void 0 ? void 0 : options.volume) !== "number") {
96
+ throw "no volume provided";
96
97
  }
97
98
  const audio = this.getAudioAsset(options.assetId).audio;
98
99
  audio.volume = options.volume;
99
100
  }
100
101
  async setRate(options) {
101
- if (typeof (options === null || options === void 0 ? void 0 : options.rate) !== 'number') {
102
- throw 'no rate provided';
102
+ if (typeof (options === null || options === void 0 ? void 0 : options.rate) !== "number") {
103
+ throw "no rate provided";
103
104
  }
104
105
  const audio = this.getAudioAsset(options.assetId).audio;
105
106
  audio.playbackRate = options.rate;
@@ -116,15 +117,15 @@ var capacitorApp = (function (exports, core) {
116
117
  return NativeAudioWeb.AUDIO_ASSET_BY_ASSET_ID.get(assetId);
117
118
  }
118
119
  checkAssetId(assetId) {
119
- if (typeof assetId !== 'string') {
120
- throw 'assetId must be a string';
120
+ if (typeof assetId !== "string") {
121
+ throw "assetId must be a string";
121
122
  }
122
123
  if (!(assetId === null || assetId === void 0 ? void 0 : assetId.length)) {
123
- throw 'no assetId provided';
124
+ throw "no assetId provided";
124
125
  }
125
126
  }
126
127
  }
127
- NativeAudioWeb.FILE_LOCATION = '';
128
+ NativeAudioWeb.FILE_LOCATION = "";
128
129
  NativeAudioWeb.AUDIO_ASSET_BY_ASSET_ID = new Map();
129
130
  const NativeAudio = new NativeAudioWeb();
130
131
 
@@ -1 +1 @@
1
- {"version":3,"file":"plugin.js","sources":["esm/index.js","esm/audio-asset.js","esm/web.js"],"sourcesContent":["import { registerPlugin } from '@capacitor/core';\nconst NativeAudio = registerPlugin('NativeAudio', {\n web: () => import('./web').then((m) => new m.NativeAudioWeb()),\n});\nexport * from './definitions';\nexport { NativeAudio };\n//# sourceMappingURL=index.js.map","export class AudioAsset {\n constructor(audio) {\n this.audio = audio;\n }\n}\n//# sourceMappingURL=audio-asset.js.map","import { WebPlugin } from '@capacitor/core';\nimport { AudioAsset } from './audio-asset';\nexport class NativeAudioWeb extends WebPlugin {\n constructor() {\n super({\n name: 'NativeAudio',\n platforms: ['web'],\n });\n }\n async resume(options) {\n const audio = this.getAudioAsset(options.assetId).audio;\n if (audio.paused) {\n return audio.play();\n }\n }\n async pause(options) {\n const audio = this.getAudioAsset(options.assetId).audio;\n return audio.pause();\n }\n async getCurrentTime(options) {\n const audio = this.getAudioAsset(options.assetId).audio;\n return { currentTime: audio.currentTime };\n }\n async getDuration(options) {\n const audio = this.getAudioAsset(options.assetId).audio;\n if (Number.isNaN(audio.duration)) {\n throw 'no duration available';\n }\n if (!Number.isFinite(audio.duration)) {\n throw 'duration not available => media resource is streaming';\n }\n return { duration: audio.duration };\n }\n async configure(options) {\n throw `configure is not supported for web: ${JSON.stringify(options)}`;\n }\n async preload(options) {\n var _a;\n if (NativeAudioWeb.AUDIO_ASSET_BY_ASSET_ID.has(options.assetId)) {\n throw 'AssetId already exists. Unload first if like to change!';\n }\n if (!((_a = options.assetPath) === null || _a === void 0 ? void 0 : _a.length)) {\n throw 'no assetPath provided';\n }\n if (!options.isUrl && !new RegExp('^/?' + NativeAudioWeb.FILE_LOCATION).test(options.assetPath)) {\n const slashPrefix = options.assetPath.startsWith('/') ? '' : '/';\n options.assetPath = `${NativeAudioWeb.FILE_LOCATION}${slashPrefix}${options.assetPath}`;\n }\n const audio = new Audio(options.assetPath);\n audio.autoplay = false;\n audio.loop = false;\n audio.preload = 'auto';\n if (options.volume) {\n audio.volume = options.volume;\n }\n NativeAudioWeb.AUDIO_ASSET_BY_ASSET_ID.set(options.assetId, new AudioAsset(audio));\n }\n async play(options) {\n var _a;\n const audio = this.getAudioAsset(options.assetId).audio;\n await this.stop(options);\n audio.loop = false;\n audio.currentTime = (_a = options.time) !== null && _a !== void 0 ? _a : 0;\n return audio.play();\n }\n async loop(options) {\n const audio = this.getAudioAsset(options.assetId).audio;\n await this.stop(options);\n audio.loop = true;\n return audio.play();\n }\n async stop(options) {\n const audio = this.getAudioAsset(options.assetId).audio;\n audio.pause();\n audio.loop = false;\n audio.currentTime = 0;\n }\n async unload(options) {\n await this.stop(options);\n NativeAudioWeb.AUDIO_ASSET_BY_ASSET_ID.delete(options.assetId);\n }\n async setVolume(options) {\n if (typeof (options === null || options === void 0 ? void 0 : options.volume) !== 'number') {\n throw 'no volume provided';\n }\n const audio = this.getAudioAsset(options.assetId).audio;\n audio.volume = options.volume;\n }\n async setRate(options) {\n if (typeof (options === null || options === void 0 ? void 0 : options.rate) !== 'number') {\n throw 'no rate provided';\n }\n const audio = this.getAudioAsset(options.assetId).audio;\n audio.playbackRate = options.rate;\n }\n async isPlaying(options) {\n const audio = this.getAudioAsset(options.assetId).audio;\n return { isPlaying: !audio.paused };\n }\n getAudioAsset(assetId) {\n this.checkAssetId(assetId);\n if (!NativeAudioWeb.AUDIO_ASSET_BY_ASSET_ID.has(assetId)) {\n throw `no asset for assetId \"${assetId}\" available. Call preload first!`;\n }\n return NativeAudioWeb.AUDIO_ASSET_BY_ASSET_ID.get(assetId);\n }\n checkAssetId(assetId) {\n if (typeof assetId !== 'string') {\n throw 'assetId must be a string';\n }\n if (!(assetId === null || assetId === void 0 ? void 0 : assetId.length)) {\n throw 'no assetId provided';\n }\n }\n}\nNativeAudioWeb.FILE_LOCATION = '';\nNativeAudioWeb.AUDIO_ASSET_BY_ASSET_ID = new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ACT,KAAK;IACL,CAAC;IACD,cAAc,CAAC,aAAa,GAAG,EAAE,CAAC;IAClC,cAAc,CAAC,uBAAuB,GAAG,IAAI,GAAG,EAAE,CAAC;IACnD,MAAM,WAAW,GAAG,IAAI,cAAc,EAAE;;;;;;;;;;;;;;;;"}
1
+ {"version":3,"file":"plugin.js","sources":["esm/index.js","esm/audio-asset.js","esm/web.js"],"sourcesContent":["import { registerPlugin } from \"@capacitor/core\";\nconst NativeAudio = registerPlugin(\"NativeAudio\", {\n web: () => import(\"./web\").then((m) => new m.NativeAudioWeb()),\n});\nexport * from \"./definitions\";\nexport { NativeAudio };\n//# sourceMappingURL=index.js.map","export class AudioAsset {\n constructor(audio) {\n this.audio = audio;\n }\n}\n//# sourceMappingURL=audio-asset.js.map","import { WebPlugin } from \"@capacitor/core\";\nimport { AudioAsset } from \"./audio-asset\";\nexport class NativeAudioWeb extends WebPlugin {\n constructor() {\n super({\n name: \"NativeAudio\",\n platforms: [\"web\"],\n });\n }\n async resume(options) {\n const audio = this.getAudioAsset(options.assetId).audio;\n if (audio.paused) {\n return audio.play();\n }\n }\n async pause(options) {\n const audio = this.getAudioAsset(options.assetId).audio;\n return audio.pause();\n }\n async getCurrentTime(options) {\n const audio = this.getAudioAsset(options.assetId).audio;\n return { currentTime: audio.currentTime };\n }\n async getDuration(options) {\n const audio = this.getAudioAsset(options.assetId).audio;\n if (Number.isNaN(audio.duration)) {\n throw \"no duration available\";\n }\n if (!Number.isFinite(audio.duration)) {\n throw \"duration not available => media resource is streaming\";\n }\n return { duration: audio.duration };\n }\n async configure(options) {\n throw `configure is not supported for web: ${JSON.stringify(options)}`;\n }\n async preload(options) {\n var _a;\n if (NativeAudioWeb.AUDIO_ASSET_BY_ASSET_ID.has(options.assetId)) {\n throw \"AssetId already exists. Unload first if like to change!\";\n }\n if (!((_a = options.assetPath) === null || _a === void 0 ? void 0 : _a.length)) {\n throw \"no assetPath provided\";\n }\n if (!options.isUrl &&\n !new RegExp(\"^/?\" + NativeAudioWeb.FILE_LOCATION).test(options.assetPath)) {\n const slashPrefix = options.assetPath.startsWith(\"/\") ? \"\" : \"/\";\n options.assetPath = `${NativeAudioWeb.FILE_LOCATION}${slashPrefix}${options.assetPath}`;\n }\n const audio = new Audio(options.assetPath);\n audio.autoplay = false;\n audio.loop = false;\n audio.preload = \"auto\";\n if (options.volume) {\n audio.volume = options.volume;\n }\n NativeAudioWeb.AUDIO_ASSET_BY_ASSET_ID.set(options.assetId, new AudioAsset(audio));\n }\n async play(options) {\n var _a;\n const audio = this.getAudioAsset(options.assetId).audio;\n await this.stop(options);\n audio.loop = false;\n audio.currentTime = (_a = options.time) !== null && _a !== void 0 ? _a : 0;\n return audio.play();\n }\n async loop(options) {\n const audio = this.getAudioAsset(options.assetId).audio;\n await this.stop(options);\n audio.loop = true;\n return audio.play();\n }\n async stop(options) {\n const audio = this.getAudioAsset(options.assetId).audio;\n audio.pause();\n audio.loop = false;\n audio.currentTime = 0;\n }\n async unload(options) {\n await this.stop(options);\n NativeAudioWeb.AUDIO_ASSET_BY_ASSET_ID.delete(options.assetId);\n }\n async setVolume(options) {\n if (typeof (options === null || options === void 0 ? void 0 : options.volume) !== \"number\") {\n throw \"no volume provided\";\n }\n const audio = this.getAudioAsset(options.assetId).audio;\n audio.volume = options.volume;\n }\n async setRate(options) {\n if (typeof (options === null || options === void 0 ? void 0 : options.rate) !== \"number\") {\n throw \"no rate provided\";\n }\n const audio = this.getAudioAsset(options.assetId).audio;\n audio.playbackRate = options.rate;\n }\n async isPlaying(options) {\n const audio = this.getAudioAsset(options.assetId).audio;\n return { isPlaying: !audio.paused };\n }\n getAudioAsset(assetId) {\n this.checkAssetId(assetId);\n if (!NativeAudioWeb.AUDIO_ASSET_BY_ASSET_ID.has(assetId)) {\n throw `no asset for assetId \"${assetId}\" available. Call preload first!`;\n }\n return NativeAudioWeb.AUDIO_ASSET_BY_ASSET_ID.get(assetId);\n }\n checkAssetId(assetId) {\n if (typeof assetId !== \"string\") {\n throw \"assetId must be a string\";\n }\n if (!(assetId === null || assetId === void 0 ? void 0 : assetId.length)) {\n throw \"no assetId provided\";\n }\n }\n}\nNativeAudioWeb.FILE_LOCATION = \"\";\nNativeAudioWeb.AUDIO_ASSET_BY_ASSET_ID = new Map();\nconst NativeAudio = new NativeAudioWeb();\nexport { NativeAudio };\n//# sourceMappingURL=web.js.map"],"names":["NativeAudio","registerPlugin","WebPlugin"],"mappings":";;;AACK,UAACA,aAAW,GAAGC,mBAAc,CAAC,aAAa,EAAE;IAClD,IAAI,GAAG,EAAE,MAAM,mDAAe,CAAC,IAAI,CAAC,CAAC,CAAC,KAAK,IAAI,CAAC,CAAC,cAAc,EAAE,CAAC;IAClE,CAAC;;ICHM,MAAM,UAAU,CAAC;IACxB,IAAI,WAAW,CAAC,KAAK,EAAE;IACvB,QAAQ,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;IAC3B,KAAK;IACL;;ICFO,MAAM,cAAc,SAASC,cAAS,CAAC;IAC9C,IAAI,WAAW,GAAG;IAClB,QAAQ,KAAK,CAAC;IACd,YAAY,IAAI,EAAE,aAAa;IAC/B,YAAY,SAAS,EAAE,CAAC,KAAK,CAAC;IAC9B,SAAS,CAAC,CAAC;IACX,KAAK;IACL,IAAI,MAAM,MAAM,CAAC,OAAO,EAAE;IAC1B,QAAQ,MAAM,KAAK,GAAG,IAAI,CAAC,aAAa,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,KAAK,CAAC;IAChE,QAAQ,IAAI,KAAK,CAAC,MAAM,EAAE;IAC1B,YAAY,OAAO,KAAK,CAAC,IAAI,EAAE,CAAC;IAChC,SAAS;IACT,KAAK;IACL,IAAI,MAAM,KAAK,CAAC,OAAO,EAAE;IACzB,QAAQ,MAAM,KAAK,GAAG,IAAI,CAAC,aAAa,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,KAAK,CAAC;IAChE,QAAQ,OAAO,KAAK,CAAC,KAAK,EAAE,CAAC;IAC7B,KAAK;IACL,IAAI,M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AAQ,IAAI,EAAE,OAAO,KAAK,IAAI,IAAI,OAAO,KAAK,KAAK,CAAC,GAAG,KAAK,CAAC,GAAG,OAAO,CAAC,MAAM,CAAC,EAAE;IACjF,YAAY,MAAM,qBAAqB,CAAC;IACxC,SAAS;IACT,KAAK;IACL,CAAC;IACD,cAAc,CAAC,aAAa,GAAG,EAAE,CAAC;IAClC,cAAc,CAAC,uBAAuB,GAAG,IAAI,GAAG,EAAE,CAAC;IACnD,MAAM,WAAW,GAAG,IAAI,cAAc,EAAE;;;;;;;;;;;;;;;;"}
@@ -10,40 +10,39 @@ import AVFoundation
10
10
 
11
11
  public class AudioAsset: NSObject, AVAudioPlayerDelegate {
12
12
 
13
- var channels: NSMutableArray = NSMutableArray()
13
+ var channels: [AVAudioPlayer] = []
14
14
  var playIndex: Int = 0
15
15
  var assetId: String = ""
16
- var initialVolume: NSNumber = 1.0
17
- var fadeDelay: NSNumber = 1.0
16
+ var initialVolume: Float = 1.0
17
+ var fadeDelay: Float = 1.0
18
18
  var owner: NativeAudio
19
19
 
20
- let FADE_STEP: Float = 0.05
21
- let FADE_DELAY: Float = 0.08
20
+ let FADESTEP: Float = 0.05
21
+ let FADEDELAY: Float = 0.08
22
22
 
23
- init(owner: NativeAudio, withAssetId assetId: String, withPath path: String!, withChannels channels: NSNumber!, withVolume volume: NSNumber!, withFadeDelay delay: NSNumber!) {
23
+ init(owner: NativeAudio, withAssetId assetId: String, withPath path: String!, withChannels channels: Int!, withVolume volume: Float!, withFadeDelay delay: Float!) {
24
24
 
25
25
  self.owner = owner
26
26
  self.assetId = assetId
27
- self.channels = NSMutableArray.init(capacity: channels as! Int)
27
+ self.channels = []
28
28
 
29
29
  super.init()
30
30
 
31
- let pathUrl: NSURL! = NSURL.fileURL(withPath: path) as NSURL
32
-
33
- for _ in 0..<channels.intValue {
31
+ let pathUrl: URL = URL(string: path)!
32
+ for _ in 0..<channels {
34
33
  do {
35
- let player: AVAudioPlayer! = try AVAudioPlayer(contentsOf: pathUrl as URL)
34
+ let player: AVAudioPlayer! = try AVAudioPlayer(contentsOf: pathUrl)
36
35
 
37
36
  if player != nil {
38
- player.volume = volume.floatValue
37
+ player.volume = volume
39
38
  player.prepareToPlay()
40
- self.channels.addObjects(from: [player as Any])
39
+ self.channels.append(player)
41
40
  if channels == 1 {
42
41
  player.delegate = self
43
42
  }
44
43
  }
45
44
  } catch {
46
-
45
+ print("Error loading \(String(describing: path))")
47
46
  }
48
47
  }
49
48
  }
@@ -52,8 +51,7 @@ public class AudioAsset: NSObject, AVAudioPlayerDelegate {
52
51
  if channels.count != 1 {
53
52
  return 0
54
53
  }
55
-
56
- let player: AVAudioPlayer = channels.object(at: playIndex) as! AVAudioPlayer
54
+ let player: AVAudioPlayer = channels[playIndex]
57
55
 
58
56
  return player.currentTime
59
57
  }
@@ -63,70 +61,69 @@ public class AudioAsset: NSObject, AVAudioPlayerDelegate {
63
61
  return 0
64
62
  }
65
63
 
66
- let player: AVAudioPlayer = channels.object(at: playIndex) as! AVAudioPlayer
64
+ let player: AVAudioPlayer = channels[playIndex]
67
65
 
68
66
  return player.duration
69
67
  }
70
68
 
71
69
  func play(time: TimeInterval) {
72
- let player: AVAudioPlayer = channels.object(at: playIndex) as! AVAudioPlayer
70
+ let player: AVAudioPlayer = channels[playIndex]
73
71
  player.currentTime = time
74
72
  player.numberOfLoops = 0
75
73
  player.play()
76
- playIndex = Int(truncating: NSNumber(value: playIndex + 1))
77
- playIndex = Int(truncating: NSNumber(value: playIndex % channels.count))
74
+ playIndex += 1
75
+ playIndex = playIndex % channels.count
78
76
  }
79
77
 
80
78
  func playWithFade(time: TimeInterval) {
81
- let player: AVAudioPlayer! = channels.object(at: playIndex) as? AVAudioPlayer
79
+ let player: AVAudioPlayer = channels[playIndex]
82
80
  player.currentTime = time
83
81
 
84
82
  if !player.isPlaying {
85
83
  player.numberOfLoops = 0
86
84
  player.volume = 0
87
85
  player.play()
88
- playIndex = Int(truncating: NSNumber(value: playIndex + 1))
89
- playIndex = Int(truncating: NSNumber(value: playIndex % channels.count))
86
+ playIndex += 1
87
+ playIndex = playIndex % channels.count
90
88
  } else {
91
- if player.volume < initialVolume.floatValue {
92
- player.volume = player.volume + self.FADE_STEP
89
+ if player.volume < initialVolume {
90
+ player.volume += self.FADESTEP
93
91
  }
94
92
  }
95
93
 
96
94
  }
97
95
 
98
96
  func pause() {
99
- let player: AVAudioPlayer = channels.object(at: playIndex) as! AVAudioPlayer
97
+ let player: AVAudioPlayer = channels[playIndex]
100
98
  player.pause()
101
99
  }
102
100
 
103
101
  func resume() {
104
- let player: AVAudioPlayer = channels.object(at: playIndex) as! AVAudioPlayer
102
+ let player: AVAudioPlayer = channels[playIndex]
105
103
 
106
104
  let timeOffset = player.deviceCurrentTime + 0.01
107
105
  player.play(atTime: timeOffset)
108
106
  }
109
107
 
110
108
  func stop() {
111
- for i in 0..<channels.count {
112
- let player: AVAudioPlayer! = channels.object(at: i) as? AVAudioPlayer
109
+ for player in channels {
113
110
  player.stop()
114
111
  }
115
112
  }
116
113
 
117
114
  func stopWithFade() {
118
- let player: AVAudioPlayer! = channels.object(at: playIndex) as? AVAudioPlayer
115
+ let player: AVAudioPlayer = channels[playIndex]
119
116
 
120
117
  if !player.isPlaying {
121
118
  player.currentTime = 0.0
122
119
  player.numberOfLoops = 0
123
120
  player.volume = 0
124
121
  player.play()
125
- playIndex = Int(truncating: NSNumber(value: playIndex + 1))
126
- playIndex = Int(truncating: NSNumber(value: playIndex % channels.count))
122
+ playIndex += 1
123
+ playIndex = playIndex % channels.count
127
124
  } else {
128
- if player.volume < initialVolume.floatValue {
129
- player.volume = player.volume + self.FADE_STEP
125
+ if player.volume < initialVolume {
126
+ player.volume += self.FADESTEP
130
127
  }
131
128
  }
132
129
  }
@@ -134,11 +131,11 @@ public class AudioAsset: NSObject, AVAudioPlayerDelegate {
134
131
  func loop() {
135
132
  self.stop()
136
133
 
137
- let player: AVAudioPlayer! = channels.object(at: Int(playIndex)) as? AVAudioPlayer
134
+ let player: AVAudioPlayer = channels[playIndex]
138
135
  player.numberOfLoops = -1
139
136
  player.play()
140
- playIndex = Int(truncating: NSNumber(value: playIndex + 1))
141
- playIndex = Int(truncating: NSNumber(value: playIndex % channels.count))
137
+ playIndex += 1
138
+ playIndex = playIndex % channels.count
142
139
  }
143
140
 
144
141
  func unload() {
@@ -149,20 +146,17 @@ public class AudioAsset: NSObject, AVAudioPlayerDelegate {
149
146
  //
150
147
  // player = nil
151
148
  // }
152
-
153
- channels = NSMutableArray()
149
+ channels = []
154
150
  }
155
151
 
156
152
  func setVolume(volume: NSNumber!) {
157
- for i in 0..<channels.count {
158
- let player: AVAudioPlayer! = channels.object(at: i) as? AVAudioPlayer
153
+ for player in channels {
159
154
  player.volume = volume.floatValue
160
155
  }
161
156
  }
162
157
 
163
158
  func setRate(rate: NSNumber!) {
164
- for i in 0..<channels.count {
165
- let player: AVAudioPlayer! = channels.object(at: i) as? AVAudioPlayer
159
+ for player in channels {
166
160
  player.rate = rate.floatValue
167
161
  }
168
162
  }
@@ -183,8 +177,7 @@ public class AudioAsset: NSObject, AVAudioPlayerDelegate {
183
177
  return false
184
178
  }
185
179
 
186
- let player: AVAudioPlayer = channels.object(at: playIndex) as! AVAudioPlayer
187
-
180
+ let player: AVAudioPlayer = channels[playIndex]
188
181
  return player.isPlaying
189
182
  }
190
183
  }
@@ -18,4 +18,5 @@ public class Constant {
18
18
  public static let ErrorAssetId = "Asset Id is missing"
19
19
  public static let ErrorAssetPath = "Asset Path is missing"
20
20
  public static let ErrorAssetNotFound = "Asset is not loaded"
21
+ public static let ErrorAssetAlreadyLoaded = "Asset is already loaded"
21
22
  }
@@ -163,7 +163,10 @@ public class NativeAudio: CAPPlugin {
163
163
  if self.audioList.count > 0 {
164
164
  let asset = self.audioList[audioId]
165
165
  if asset != nil && asset is AudioAsset {
166
- let audioAsset = asset as! AudioAsset
166
+ guard let audioAsset=asset as? AudioAsset else {
167
+ call.reject("Cannot cast to AudioAsset")
168
+ return
169
+ }
167
170
  audioAsset.unload()
168
171
  self.audioList[audioId] = nil
169
172
  }
@@ -204,9 +207,9 @@ public class NativeAudio: CAPPlugin {
204
207
 
205
208
  private func preloadAsset(_ call: CAPPluginCall, isComplex complex: Bool) {
206
209
  let audioId = call.getString(Constant.AssetIdKey) ?? ""
207
- let channels: NSNumber?
210
+ let channels: Int?
208
211
  let volume: Float?
209
- let delay: NSNumber?
212
+ let delay: Float?
210
213
  let isUrl: Bool?
211
214
 
212
215
  if audioId != "" {
@@ -214,8 +217,8 @@ public class NativeAudio: CAPPlugin {
214
217
 
215
218
  if complex {
216
219
  volume = call.getFloat("volume") ?? 1.0
217
- channels = NSNumber(value: call.getInt("channels") ?? 1)
218
- delay = NSNumber(value: call.getInt("delay") ?? 1)
220
+ channels = call.getInt("channels") ?? 1
221
+ delay = call.getFloat("delay") ?? 1.0
219
222
  isUrl = call.getBool("isUrl") ?? false
220
223
  } else {
221
224
  channels = 0
@@ -230,13 +233,12 @@ public class NativeAudio: CAPPlugin {
230
233
 
231
234
  let asset = audioList[audioId]
232
235
  let queue = DispatchQueue(label: "ee.forgr.audio.simple.queue", qos: .userInitiated)
233
-
234
236
  queue.async {
235
237
  if asset == nil {
236
238
  var basePath: String?
237
239
  if isUrl == false {
238
240
  // if assetPath dont start with public/ add it
239
- assetPath = assetPath.starts(with: "public/") ? assetPath : "public/" + assetPath
241
+ assetPath = assetPath.starts(with: "public/") ? assetPath : "public/" + assetPath
240
242
 
241
243
  let assetPathSplit = assetPath.components(separatedBy: ".")
242
244
  basePath = Bundle.main.path(forResource: assetPathSplit[0], ofType: assetPathSplit[1])
@@ -247,20 +249,22 @@ public class NativeAudio: CAPPlugin {
247
249
 
248
250
  if FileManager.default.fileExists(atPath: basePath ?? "") {
249
251
  if !complex {
250
- let pathUrl = URL(fileURLWithPath: basePath ?? "")
251
- let soundFileUrl: CFURL = CFBridgingRetain(pathUrl) as! CFURL
252
+ let soundFileUrl = URL(fileURLWithPath: basePath ?? "")
252
253
  var soundId = SystemSoundID()
253
- AudioServicesCreateSystemSoundID(soundFileUrl, &soundId)
254
+ AudioServicesCreateSystemSoundID(soundFileUrl as CFURL, &soundId)
254
255
  self.audioList[audioId] = NSNumber(value: Int32(soundId))
255
256
  call.resolve()
256
257
  } else {
257
- let audioAsset: AudioAsset = AudioAsset(owner: self, withAssetId: audioId, withPath: basePath, withChannels: channels, withVolume: volume as NSNumber?, withFadeDelay: delay)
258
+ let audioAsset: AudioAsset = AudioAsset(owner: self,
259
+ withAssetId: audioId, withPath: basePath, withChannels: channels, withVolume: volume, withFadeDelay: delay)
258
260
  self.audioList[audioId] = audioAsset
259
261
  call.resolve()
260
262
  }
261
263
  } else {
262
264
  call.reject(Constant.ErrorAssetPath + " - " + assetPath)
263
265
  }
266
+ } else {
267
+ call.reject(Constant.ErrorAssetAlreadyLoaded + " - " + audioId)
264
268
  }
265
269
  }
266
270
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@capgo/native-audio",
3
- "version": "5.1.3",
3
+ "version": "5.1.13",
4
4
  "description": "A native plugin for native audio engine",
5
5
  "main": "dist/plugin.js",
6
6
  "module": "dist/esm/index.js",
@@ -28,7 +28,7 @@
28
28
  "lint": "npm run eslint && npm run prettier -- --check && npm run swiftlint -- lint",
29
29
  "fmt": "npm run eslint -- --fix && npm run prettier -- --write && npm run swiftlint -- --autocorrect --format",
30
30
  "eslint": "eslint . --ext ts",
31
- "prettier": "prettier \"**/*.{css,html,ts,js,java}\"",
31
+ "prettier": "prettier --config .prettierrc.js \"**/*.{css,html,ts,js,java}\"",
32
32
  "swiftlint": "node-swiftlint",
33
33
  "docgen": "docgen --api NativeAudio --output-readme README.md --output-json dist/docs.json",
34
34
  "build": "npm run clean && npm run docgen && tsc && rollup -c rollup.config.mjs",
@@ -40,23 +40,24 @@
40
40
  "author": "Martin Donadieu <martindonadieu@gmail.com>",
41
41
  "license": "MIT",
42
42
  "devDependencies": {
43
- "@capacitor/android": "^4.7.0",
44
- "@capacitor/cli": "^4.7.0",
45
- "@capacitor/core": "^4.7.0",
43
+ "@capacitor/android": "^4.7.3",
44
+ "@capacitor/cli": "^4.7.3",
45
+ "@capacitor/core": "^4.7.3",
46
46
  "@capacitor/docgen": "^0.2.1",
47
- "@capacitor/ios": "^4.7.0",
47
+ "@capacitor/ios": "^4.7.3",
48
48
  "@ionic/eslint-config": "^0.3.0",
49
49
  "@ionic/prettier-config": "^2.0.0",
50
50
  "@ionic/swiftlint-config": "^1.1.2",
51
- "@typescript-eslint/eslint-plugin": "^5.54.1",
52
- "@typescript-eslint/parser": "^5.54.1",
53
- "eslint": "^8.35.0",
51
+ "@types/node": "^18.15.11",
52
+ "@typescript-eslint/eslint-plugin": "^5.58.0",
53
+ "@typescript-eslint/parser": "^5.58.0",
54
+ "eslint": "^8.38.0",
54
55
  "eslint-plugin-import": "^2.27.5",
55
56
  "husky": "^8.0.3",
56
- "prettier": "^2.7.1",
57
- "prettier-plugin-java": "^2.0.0",
58
- "rimraf": "^4.3.1",
59
- "rollup": "^3.18.0",
57
+ "prettier": "^2.8.7",
58
+ "prettier-plugin-java": "^2.1.0",
59
+ "rimraf": "^4.4.1",
60
+ "rollup": "^3.20.2",
60
61
  "swiftlint": "^1.0.1",
61
62
  "typescript": "^4.9.5"
62
63
  },