@capgo/native-audio 6.4.18 → 6.4.20

Sign up to get free protection for your applications and to get access to all the features.
package/dist/esm/web.js CHANGED
@@ -61,17 +61,18 @@ export class NativeAudioWeb extends WebPlugin {
61
61
  }
62
62
  NativeAudioWeb.AUDIO_ASSET_BY_ASSET_ID.set(options.assetId, new AudioAsset(audio));
63
63
  }
64
- onEnded(event) {
65
- const audio = event.target;
66
- this.notifyListeners("complete", { assetId: audio.id });
64
+ onEnded(assetId) {
65
+ this.notifyListeners("complete", { assetId });
67
66
  }
68
67
  async play(options) {
69
- var _a;
70
- const audio = this.getAudioAsset(options.assetId).audio;
68
+ const { assetId, time = 0 } = options;
69
+ const audio = this.getAudioAsset(assetId).audio;
71
70
  await this.stop(options);
72
71
  audio.loop = false;
73
- audio.currentTime = (_a = options.time) !== null && _a !== void 0 ? _a : 0;
74
- audio.addEventListener("ended", (e) => this.onEnded(e), { once: true });
72
+ audio.currentTime = time;
73
+ audio.addEventListener("ended", () => this.onEnded(assetId), {
74
+ once: true,
75
+ });
75
76
  return audio.play();
76
77
  }
77
78
  async loop(options) {
@@ -1 +1 @@
1
- {"version":3,"file":"web.js","sourceRoot":"","sources":["../../src/web.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAE5C,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAI3C,MAAM,OAAO,cAAe,SAAQ,SAAS;IAK3C;QACE,KAAK,EAAE,CAAC;IACV,CAAC;IAED,KAAK,CAAC,MAAM,CAAC,OAA4B;QACvC,MAAM,KAAK,GAAqB,IAAI,CAAC,aAAa,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,KAAK,CAAC;QAC1E,IAAI,KAAK,CAAC,MAAM,EAAE,CAAC;YACjB,OAAO,KAAK,CAAC,IAAI,EAAE,CAAC;QACtB,CAAC;IACH,CAAC;IAED,KAAK,CAAC,KAAK,CAAC,OAA4B;QACtC,MAAM,KAAK,GAAqB,IAAI,CAAC,a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,CAAA,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,MAAM,CAAA,EAAE,CAAC;YACrB,MAAM,qBAAqB,CAAC;QAC9B,CAAC;IACH,CAAC;;AA1JuB,4BAAa,GAAW,EAAE,CAAC;AAC3B,sCAAuB,GAC7C,IAAI,GAAG,EAAsB,CAAC;AA2JlC,MAAM,WAAW,GAAG,IAAI,cAAc,EAAE,CAAC;AAEzC,OAAO,EAAE,WAAW,EAAE,CAAC","sourcesContent":["import { WebPlugin } from \"@capacitor/core\";\n\nimport { AudioAsset } from \"./audio-asset\";\nimport type { ConfigureOptions, PreloadOptions } from \"./definitions\";\nimport { NativeAudio } from \"./definitions\";\n\nexport class NativeAudioWeb extends WebPlugin implements NativeAudio {\n private static readonly FILE_LOCATION: string = \"\";\n private static readonly AUDIO_ASSET_BY_ASSET_ID: Map<string, AudioAsset> =\n new Map<string, AudioAsset>();\n\n constructor() {\n super();\n }\n\n async resume(options: { assetId: string }): Promise<void> {\n const audio: HTMLAudioElement = this.getAudioAsset(options.assetId).audio;\n if (audio.paused) {\n return audio.play();\n }\n }\n\n async pause(options: { assetId: string }): Promise<void> {\n const audio: HTMLAudioElement = this.getAudioAsset(options.assetId).audio;\n return audio.pause();\n }\n\n async getCurrentTime(options: {\n assetId: string;\n }): Promise<{ currentTime: number }> {\n const audio: HTMLAudioElement = this.getAudioAsset(options.assetId).audio;\n return { currentTime: audio.currentTime };\n }\n\n async getDuration(options: {\n assetId: string;\n }): Promise<{ duration: number }> {\n const audio: HTMLAudioElement = 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\n async configure(options: ConfigureOptions): Promise<void> {\n throw `configure is not supported for web: ${JSON.stringify(options)}`;\n }\n\n async isPreloaded(options: PreloadOptions): Promise<{ found: boolean }> {\n try {\n return { found: !!this.getAudioAsset(options.assetId) };\n } catch (e) {\n return { found: false };\n }\n }\n\n async preload(options: PreloadOptions): Promise<void> {\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 (!options.assetPath?.length) {\n throw \"no assetPath provided\";\n }\n if (\n !options.isUrl &&\n !new RegExp(\"^/?\" + NativeAudioWeb.FILE_LOCATION).test(options.assetPath)\n ) {\n const slashPrefix: string = options.assetPath.startsWith(\"/\") ? \"\" : \"/\";\n options.assetPath = `${NativeAudioWeb.FILE_LOCATION}${slashPrefix}${options.assetPath}`;\n }\n const audio: HTMLAudioElement = 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(\n options.assetId,\n new AudioAsset(audio),\n );\n }\n private onEnded(event: Event): void {\n const audio: HTMLAudioElement = event.target as HTMLAudioElement;\n this.notifyListeners(\"complete\", { assetId: audio.id });\n }\n\n async play(options: { assetId: string; time?: number }): Promise<void> {\n const audio: HTMLAudioElement = this.getAudioAsset(options.assetId).audio;\n await this.stop(options);\n audio.loop = false;\n audio.currentTime = options.time ?? 0;\n audio.addEventListener(\"ended\", (e) => this.onEnded(e), { once: true });\n return audio.play();\n }\n\n async loop(options: { assetId: string }): Promise<void> {\n const audio: HTMLAudioElement = this.getAudioAsset(options.assetId).audio;\n await this.stop(options);\n audio.loop = true;\n return audio.play();\n }\n\n async stop(options: { assetId: string }): Promise<void> {\n const audio: HTMLAudioElement = this.getAudioAsset(options.assetId).audio;\n audio.pause();\n audio.loop = false;\n audio.currentTime = 0;\n }\n\n async unload(options: { assetId: string }): Promise<void> {\n await this.stop(options);\n NativeAudioWeb.AUDIO_ASSET_BY_ASSET_ID.delete(options.assetId);\n }\n\n async setVolume(options: { assetId: string; volume: number }): Promise<void> {\n if (typeof options?.volume !== \"number\") {\n throw \"no volume provided\";\n }\n\n const audio: HTMLAudioElement = this.getAudioAsset(options.assetId).audio;\n audio.volume = options.volume;\n }\n\n async setRate(options: { assetId: string; rate: number }): Promise<void> {\n if (typeof options?.rate !== \"number\") {\n throw \"no rate provided\";\n }\n\n const audio: HTMLAudioElement = this.getAudioAsset(options.assetId).audio;\n audio.playbackRate = options.rate;\n }\n\n async isPlaying(options: {\n assetId: string;\n }): Promise<{ isPlaying: boolean }> {\n const audio: HTMLAudioElement = this.getAudioAsset(options.assetId).audio;\n return { isPlaying: !audio.paused };\n }\n\n private getAudioAsset(assetId: string): AudioAsset {\n this.checkAssetId(assetId);\n\n if (!NativeAudioWeb.AUDIO_ASSET_BY_ASSET_ID.has(assetId)) {\n throw `no asset for assetId \"${assetId}\" available. Call preload first!`;\n }\n\n return NativeAudioWeb.AUDIO_ASSET_BY_ASSET_ID.get(assetId) as AudioAsset;\n }\n\n private checkAssetId(assetId: string): void {\n if (typeof assetId !== \"string\") {\n throw \"assetId must be a string\";\n }\n\n if (!assetId?.length) {\n throw \"no assetId provided\";\n }\n }\n}\n\nconst NativeAudio = new NativeAudioWeb();\n\nexport { NativeAudio };\n"]}
1
+ {"version":3,"file":"web.js","sourceRoot":"","sources":["../../src/web.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAE5C,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAI3C,MAAM,OAAO,cAAe,SAAQ,SAAS;IAK3C;QACE,KAAK,EAAE,CAAC;IACV,CAAC;IAED,KAAK,CAAC,MAAM,CAAC,OAA4B;QACvC,MAAM,KAAK,GAAqB,IAAI,CAAC,aAAa,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,KAAK,CAAC;QAC1E,IAAI,KAAK,CAAC,MAAM,EAAE,CAAC;YACjB,OAAO,KAAK,CAAC,IAAI,EAAE,CAAC;QACtB,CAAC;IACH,CAAC;IAED,KAAK,CAAC,KAAK,CAAC,OAA4B;QACtC,M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OAAO,CAAE,MAAM,CAAA,EAAE,CAAC;YACrB,MAAM,qBAAqB,CAAC;QAC9B,CAAC;IACH,CAAC;;AA5JuB,4BAAa,GAAW,EAAE,CAAC;AAC3B,sCAAuB,GAC7C,IAAI,GAAG,EAAsB,CAAC;AA6JlC,MAAM,WAAW,GAAG,IAAI,cAAc,EAAE,CAAC;AAEzC,OAAO,EAAE,WAAW,EAAE,CAAC","sourcesContent":["import { WebPlugin } from \"@capacitor/core\";\n\nimport { AudioAsset } from \"./audio-asset\";\nimport type { ConfigureOptions, PreloadOptions } from \"./definitions\";\nimport { NativeAudio } from \"./definitions\";\n\nexport class NativeAudioWeb extends WebPlugin implements NativeAudio {\n private static readonly FILE_LOCATION: string = \"\";\n private static readonly AUDIO_ASSET_BY_ASSET_ID: Map<string, AudioAsset> =\n new Map<string, AudioAsset>();\n\n constructor() {\n super();\n }\n\n async resume(options: { assetId: string }): Promise<void> {\n const audio: HTMLAudioElement = this.getAudioAsset(options.assetId).audio;\n if (audio.paused) {\n return audio.play();\n }\n }\n\n async pause(options: { assetId: string }): Promise<void> {\n const audio: HTMLAudioElement = this.getAudioAsset(options.assetId).audio;\n return audio.pause();\n }\n\n async getCurrentTime(options: {\n assetId: string;\n }): Promise<{ currentTime: number }> {\n const audio: HTMLAudioElement = this.getAudioAsset(options.assetId).audio;\n return { currentTime: audio.currentTime };\n }\n\n async getDuration(options: {\n assetId: string;\n }): Promise<{ duration: number }> {\n const audio: HTMLAudioElement = 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\n async configure(options: ConfigureOptions): Promise<void> {\n throw `configure is not supported for web: ${JSON.stringify(options)}`;\n }\n\n async isPreloaded(options: PreloadOptions): Promise<{ found: boolean }> {\n try {\n return { found: !!this.getAudioAsset(options.assetId) };\n } catch (e) {\n return { found: false };\n }\n }\n\n async preload(options: PreloadOptions): Promise<void> {\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 (!options.assetPath?.length) {\n throw \"no assetPath provided\";\n }\n if (\n !options.isUrl &&\n !new RegExp(\"^/?\" + NativeAudioWeb.FILE_LOCATION).test(options.assetPath)\n ) {\n const slashPrefix: string = options.assetPath.startsWith(\"/\") ? \"\" : \"/\";\n options.assetPath = `${NativeAudioWeb.FILE_LOCATION}${slashPrefix}${options.assetPath}`;\n }\n const audio: HTMLAudioElement = 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(\n options.assetId,\n new AudioAsset(audio),\n );\n }\n private onEnded(assetId: string): void {\n this.notifyListeners(\"complete\", { assetId });\n }\n\n async play(options: { assetId: string; time?: number }): Promise<void> {\n const { assetId, time = 0 } = options;\n const audio = this.getAudioAsset(assetId).audio;\n await this.stop(options);\n audio.loop = false;\n audio.currentTime = time;\n audio.addEventListener(\"ended\", () => this.onEnded(assetId), {\n once: true,\n });\n return audio.play();\n }\n\n async loop(options: { assetId: string }): Promise<void> {\n const audio: HTMLAudioElement = this.getAudioAsset(options.assetId).audio;\n await this.stop(options);\n audio.loop = true;\n return audio.play();\n }\n\n async stop(options: { assetId: string }): Promise<void> {\n const audio: HTMLAudioElement = this.getAudioAsset(options.assetId).audio;\n audio.pause();\n audio.loop = false;\n audio.currentTime = 0;\n }\n\n async unload(options: { assetId: string }): Promise<void> {\n await this.stop(options);\n NativeAudioWeb.AUDIO_ASSET_BY_ASSET_ID.delete(options.assetId);\n }\n\n async setVolume(options: { assetId: string; volume: number }): Promise<void> {\n if (typeof options?.volume !== \"number\") {\n throw \"no volume provided\";\n }\n\n const audio: HTMLAudioElement = this.getAudioAsset(options.assetId).audio;\n audio.volume = options.volume;\n }\n\n async setRate(options: { assetId: string; rate: number }): Promise<void> {\n if (typeof options?.rate !== \"number\") {\n throw \"no rate provided\";\n }\n\n const audio: HTMLAudioElement = this.getAudioAsset(options.assetId).audio;\n audio.playbackRate = options.rate;\n }\n\n async isPlaying(options: {\n assetId: string;\n }): Promise<{ isPlaying: boolean }> {\n const audio: HTMLAudioElement = this.getAudioAsset(options.assetId).audio;\n return { isPlaying: !audio.paused };\n }\n\n private getAudioAsset(assetId: string): AudioAsset {\n this.checkAssetId(assetId);\n\n if (!NativeAudioWeb.AUDIO_ASSET_BY_ASSET_ID.has(assetId)) {\n throw `no asset for assetId \"${assetId}\" available. Call preload first!`;\n }\n\n return NativeAudioWeb.AUDIO_ASSET_BY_ASSET_ID.get(assetId) as AudioAsset;\n }\n\n private checkAssetId(assetId: string): void {\n if (typeof assetId !== \"string\") {\n throw \"assetId must be a string\";\n }\n\n if (!assetId?.length) {\n throw \"no assetId provided\";\n }\n }\n}\n\nconst NativeAudio = new NativeAudioWeb();\n\nexport { NativeAudio };\n"]}
@@ -73,17 +73,18 @@ class NativeAudioWeb extends core.WebPlugin {
73
73
  }
74
74
  NativeAudioWeb.AUDIO_ASSET_BY_ASSET_ID.set(options.assetId, new AudioAsset(audio));
75
75
  }
76
- onEnded(event) {
77
- const audio = event.target;
78
- this.notifyListeners("complete", { assetId: audio.id });
76
+ onEnded(assetId) {
77
+ this.notifyListeners("complete", { assetId });
79
78
  }
80
79
  async play(options) {
81
- var _a;
82
- const audio = this.getAudioAsset(options.assetId).audio;
80
+ const { assetId, time = 0 } = options;
81
+ const audio = this.getAudioAsset(assetId).audio;
83
82
  await this.stop(options);
84
83
  audio.loop = false;
85
- audio.currentTime = (_a = options.time) !== null && _a !== void 0 ? _a : 0;
86
- audio.addEventListener("ended", (e) => this.onEnded(e), { once: true });
84
+ audio.currentTime = time;
85
+ audio.addEventListener("ended", () => this.onEnded(assetId), {
86
+ once: true,
87
+ });
87
88
  return audio.play();
88
89
  }
89
90
  async loop(options) {
@@ -1 +1 @@
1
- {"version":3,"file":"plugin.cjs.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 }\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 isPreloaded(options) {\n try {\n return { found: !!this.getAudioAsset(options.assetId) };\n }\n catch (e) {\n return { found: false };\n }\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 onEnded(event) {\n const audio = event.target;\n this.notifyListeners(\"complete\", { assetId: audio.id });\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 audio.addEventListener(\"ended\", (e) => this.onEnded(e), { once: true });\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,MAACA,aAAW,GAAGC,mBAAc,CAAC,aAAa,EAAE;AAClD,IAAI,GAAG,EAAE,MAAM,mDAAe,CAAC,IAAI,CAAC,CAAC,CAAC,KAAK,IAAI,CAAC,CAAC,cAAc,EAAE,CAAC;AAClE,CAAC;;ACHM,MAAM,UAAU,CAAC;AACxB,IAAI,WAAW,CAAC,KAAK,EAAE;AACvB,QAAQ,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;AAC3B,KAAK;AACL;;ACFO,MAAM,cAAc,SAASC,cAAS,CAAC;AAC9C,IAAI,WAAW,GAAG;AAClB,QAAQ,KAAK,EAAE,CAAC;AAChB,KAAK;AACL,IAAI,MAAM,MAAM,CAAC,OAAO,EAAE;AAC1B,QAAQ,MAAM,KAAK,GAAG,IAAI,CAAC,aAAa,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,KAAK,CAAC;AAChE,QAAQ,IAAI,KAAK,CAAC,MAAM,EAAE;AAC1B,YAAY,OAAO,KAAK,CAAC,IAAI,EAAE,CAAC;AAChC,SAAS;AACT,KAAK;AACL,IAAI,MAAM,KAAK,CAAC,OAAO,EAAE;AACzB,QAAQ,MAAM,KAAK,GAAG,IAAI,CAAC,aAAa,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,KAAK,CAAC;AAChE,QAAQ,OAAO,KAAK,CAAC,KAAK,EAAE,CAAC;AAC7B,KAAK;AACL,IAAI,MAAM,cAAc,CAAC,OAAO,EAAE;AAClC,QAAQ,MAAM,KAAK,GAAG,IAAI,CAAC,aAAa,CAAC,OAAO,CAAC,OAAO,CAA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SAAS,EAAE,CAAC,KAAK,CAAC,MAAM,EAAE,CAAC;AAC5C,KAAK;AACL,IAAI,aAAa,CAAC,OAAO,EAAE;AAC3B,QAAQ,IAAI,CAAC,YAAY,CAAC,OAAO,CAAC,CAAC;AACnC,QAAQ,IAAI,CAAC,cAAc,CAAC,uBAAuB,CAAC,GAAG,CAAC,OAAO,CAAC,EAAE;AAClE,YAAY,MAAM,CAAC,sBAAsB,EAAE,OAAO,CAAC,gCAAgC,CAAC,CAAC;AACrF,SAAS;AACT,QAAQ,OAAO,cAAc,CAAC,uBAAuB,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;AACnE,KAAK;AACL,IAAI,YAAY,CAAC,OAAO,EAAE;AAC1B,QAAQ,IAAI,OAAO,OAAO,KAAK,QAAQ,EAAE;AACzC,YAAY,MAAM,0BAA0B,CAAC;AAC7C,SAAS;AACT,QAAQ,IAAI,EAAE,OAAO,KAAK,IAAI,IAAI,OAAO,KAAK,KAAK,CAAC,GAAG,KAAK,CAAC,GAAG,OAAO,CAAC,MAAM,CAAC,EAAE;AACjF,YAAY,MAAM,qBAAqB,CAAC;AACxC,SAAS;AACT,KAAK;AACL,CAAC;AACD,cAAc,CAAC,aAAa,GAAG,EAAE,CAAC;AAClC,cAAc,CAAC,uBAAuB,GAAG,IAAI,GAAG,EAAE,CAAC;AACnD,MAAM,WAAW,GAAG,IAAI,cAAc,EAAE;;;;;;;;;;"}
1
+ {"version":3,"file":"plugin.cjs.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 }\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 isPreloaded(options) {\n try {\n return { found: !!this.getAudioAsset(options.assetId) };\n }\n catch (e) {\n return { found: false };\n }\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 onEnded(assetId) {\n this.notifyListeners(\"complete\", { assetId });\n }\n async play(options) {\n const { assetId, time = 0 } = options;\n const audio = this.getAudioAsset(assetId).audio;\n await this.stop(options);\n audio.loop = false;\n audio.currentTime = time;\n audio.addEventListener(\"ended\", () => this.onEnded(assetId), {\n once: true,\n });\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,MAACA,aAAW,GAAGC,mBAAc,CAAC,aAAa,EAAE;AAClD,IAAI,GAAG,EAAE,MAAM,mDAAe,CAAC,IAAI,CAAC,CAAC,CAAC,KAAK,IAAI,CAAC,CAAC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SAAS;AACT,QAAQ,IAAI,EAAE,OAAO,KAAK,IAAI,IAAI,OAAO,KAAK,KAAK,CAAC,GAAG,KAAK,CAAC,GAAG,OAAO,CAAC,MAAM,CAAC,EAAE;AACjF,YAAY,MAAM,qBAAqB,CAAC;AACxC,SAAS;AACT,KAAK;AACL,CAAC;AACD,cAAc,CAAC,aAAa,GAAG,EAAE,CAAC;AAClC,cAAc,CAAC,uBAAuB,GAAG,IAAI,GAAG,EAAE,CAAC;AACnD,MAAM,WAAW,GAAG,IAAI,cAAc,EAAE;;;;;;;;;;"}
package/dist/plugin.js CHANGED
@@ -72,17 +72,18 @@ var capacitorCapacitorNativeAudio = (function (exports, core) {
72
72
  }
73
73
  NativeAudioWeb.AUDIO_ASSET_BY_ASSET_ID.set(options.assetId, new AudioAsset(audio));
74
74
  }
75
- onEnded(event) {
76
- const audio = event.target;
77
- this.notifyListeners("complete", { assetId: audio.id });
75
+ onEnded(assetId) {
76
+ this.notifyListeners("complete", { assetId });
78
77
  }
79
78
  async play(options) {
80
- var _a;
81
- const audio = this.getAudioAsset(options.assetId).audio;
79
+ const { assetId, time = 0 } = options;
80
+ const audio = this.getAudioAsset(assetId).audio;
82
81
  await this.stop(options);
83
82
  audio.loop = false;
84
- audio.currentTime = (_a = options.time) !== null && _a !== void 0 ? _a : 0;
85
- audio.addEventListener("ended", (e) => this.onEnded(e), { once: true });
83
+ audio.currentTime = time;
84
+ audio.addEventListener("ended", () => this.onEnded(assetId), {
85
+ once: true,
86
+ });
86
87
  return audio.play();
87
88
  }
88
89
  async loop(options) {
@@ -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 }\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 isPreloaded(options) {\n try {\n return { found: !!this.getAudioAsset(options.assetId) };\n }\n catch (e) {\n return { found: false };\n }\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 onEnded(event) {\n const audio = event.target;\n this.notifyListeners(\"complete\", { assetId: audio.id });\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 audio.addEventListener(\"ended\", (e) => this.onEnded(e), { once: true });\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,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AE,OAAO,CAAC,gCAAgC,CAAC,CAAC;IACrF,SAAS;IACT,QAAQ,OAAO,cAAc,CAAC,uBAAuB,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;IACnE,KAAK;IACL,IAAI,YAAY,CAAC,OAAO,EAAE;IAC1B,QAAQ,IAAI,OAAO,OAAO,KAAK,QAAQ,EAAE;IACzC,YAAY,MAAM,0BAA0B,CAAC;IAC7C,SAAS;IACT,QAAQ,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;;;;;;;;;;;;;;;;"}
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 }\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 isPreloaded(options) {\n try {\n return { found: !!this.getAudioAsset(options.assetId) };\n }\n catch (e) {\n return { found: false };\n }\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 onEnded(assetId) {\n this.notifyListeners(\"complete\", { assetId });\n }\n async play(options) {\n const { assetId, time = 0 } = options;\n const audio = this.getAudioAsset(assetId).audio;\n await this.stop(options);\n audio.loop = false;\n audio.currentTime = time;\n audio.addEventListener(\"ended\", () => this.onEnded(assetId), {\n once: true,\n });\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,EAAE,CAAC;IAChB,KAAK;IAC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AG,IAAI,GAAG,EAAE,CAAC;IACnD,MAAM,WAAW,GAAG,IAAI,cAAc,EAAE;;;;;;;;;;;;;;;;"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@capgo/native-audio",
3
- "version": "6.4.18",
3
+ "version": "6.4.20",
4
4
  "description": "A native plugin for native audio engine",
5
5
  "main": "dist/plugin.js",
6
6
  "module": "dist/esm/index.js",