diff --git a/.gitignore b/.gitignore index 29bee57..a7ce994 100644 --- a/.gitignore +++ b/.gitignore @@ -3,6 +3,7 @@ # And the CLI then renames it # node files +dist/ node_modules/ package-lock.json diff --git a/dist/docs.json b/dist/docs.json deleted file mode 100644 index 3e1dd46..0000000 --- a/dist/docs.json +++ /dev/null @@ -1,333 +0,0 @@ -{ - "api": { - "name": "NativeAudio", - "slug": "nativeaudio", - "docs": "", - "tags": [], - "methods": [ - { - "name": "configure", - "signature": "(options: ConfigureOptions) => Promise", - "parameters": [ - { - "name": "options", - "docs": "", - "type": "ConfigureOptions" - } - ], - "returns": "Promise", - "tags": [], - "docs": "", - "complexTypes": [ - "ConfigureOptions" - ], - "slug": "configure" - }, - { - "name": "preload", - "signature": "(options: PreloadOptions) => Promise", - "parameters": [ - { - "name": "options", - "docs": "", - "type": "PreloadOptions" - } - ], - "returns": "Promise", - "tags": [], - "docs": "", - "complexTypes": [ - "PreloadOptions" - ], - "slug": "preload" - }, - { - "name": "play", - "signature": "(options: { assetId: string; time?: number; }) => Promise", - "parameters": [ - { - "name": "options", - "docs": "", - "type": "{ assetId: string; time?: number | undefined; }" - } - ], - "returns": "Promise", - "tags": [], - "docs": "", - "complexTypes": [], - "slug": "play" - }, - { - "name": "pause", - "signature": "(options: { assetId: string; }) => Promise", - "parameters": [ - { - "name": "options", - "docs": "", - "type": "{ assetId: string; }" - } - ], - "returns": "Promise", - "tags": [], - "docs": "", - "complexTypes": [], - "slug": "pause" - }, - { - "name": "resume", - "signature": "(options: { assetId: string; }) => Promise", - "parameters": [ - { - "name": "options", - "docs": "", - "type": "{ assetId: string; }" - } - ], - "returns": "Promise", - "tags": [], - "docs": "", - "complexTypes": [], - "slug": "resume" - }, - { - "name": "loop", - "signature": "(options: { assetId: string; }) => Promise", - "parameters": [ - { - "name": "options", - "docs": "", - "type": "{ assetId: string; }" - } - ], - "returns": "Promise", - "tags": [], - "docs": "", - "complexTypes": [], - "slug": "loop" - }, - { - "name": "stop", - "signature": "(options: { assetId: string; }) => Promise", - "parameters": [ - { - "name": "options", - "docs": "", - "type": "{ assetId: string; }" - } - ], - "returns": "Promise", - "tags": [], - "docs": "", - "complexTypes": [], - "slug": "stop" - }, - { - "name": "unload", - "signature": "(options: { assetId: string; }) => Promise", - "parameters": [ - { - "name": "options", - "docs": "", - "type": "{ assetId: string; }" - } - ], - "returns": "Promise", - "tags": [], - "docs": "", - "complexTypes": [], - "slug": "unload" - }, - { - "name": "setVolume", - "signature": "(options: { assetId: string; volume: number; }) => Promise", - "parameters": [ - { - "name": "options", - "docs": "", - "type": "{ assetId: string; volume: number; }" - } - ], - "returns": "Promise", - "tags": [], - "docs": "", - "complexTypes": [], - "slug": "setvolume" - }, - { - "name": "getCurrentTime", - "signature": "(options: { assetId: string; }) => Promise<{ currentTime: number; }>", - "parameters": [ - { - "name": "options", - "docs": "", - "type": "{ assetId: string; }" - } - ], - "returns": "Promise<{ currentTime: number; }>", - "tags": [], - "docs": "", - "complexTypes": [], - "slug": "getcurrenttime" - }, - { - "name": "getDuration", - "signature": "(options: { assetId: string; }) => Promise<{ duration: number; }>", - "parameters": [ - { - "name": "options", - "docs": "", - "type": "{ assetId: string; }" - } - ], - "returns": "Promise<{ duration: number; }>", - "tags": [], - "docs": "", - "complexTypes": [], - "slug": "getduration" - }, - { - "name": "isPlaying", - "signature": "(options: { assetId: string; }) => Promise<{ isPlaying: boolean; }>", - "parameters": [ - { - "name": "options", - "docs": "", - "type": "{ assetId: string; }" - } - ], - "returns": "Promise<{ isPlaying: boolean; }>", - "tags": [], - "docs": "", - "complexTypes": [], - "slug": "isplaying" - }, - { - "name": "addListener", - "signature": "(eventName: 'complete', listenerFunc: (event: { assetId: string; }) => void) => Promise", - "parameters": [ - { - "name": "eventName", - "docs": "", - "type": "'complete'" - }, - { - "name": "listenerFunc", - "docs": "", - "type": "(event: { assetId: string; }) => void" - } - ], - "returns": "Promise", - "tags": [ - { - "name": "since", - "text": "5.0.1" - } - ], - "docs": "Listen for asset completed playing event", - "complexTypes": [ - "PluginListenerHandle" - ], - "slug": "addlistenercomplete" - } - ], - "properties": [] - }, - "interfaces": [ - { - "name": "ConfigureOptions", - "slug": "configureoptions", - "docs": "", - "tags": [], - "methods": [], - "properties": [ - { - "name": "fade", - "tags": [ - { - "text": "true", - "name": "default" - } - ], - "docs": "indicating whether or not to fade audio.", - "complexTypes": [], - "type": "boolean | undefined" - }, - { - "name": "focus", - "tags": [ - { - "text": "true", - "name": "default" - } - ], - "docs": "indicating whether or not to disable mixed audio.", - "complexTypes": [], - "type": "boolean | undefined" - } - ] - }, - { - "name": "PreloadOptions", - "slug": "preloadoptions", - "docs": "", - "tags": [], - "methods": [], - "properties": [ - { - "name": "assetPath", - "tags": [], - "docs": "", - "complexTypes": [], - "type": "string" - }, - { - "name": "assetId", - "tags": [], - "docs": "", - "complexTypes": [], - "type": "string" - }, - { - "name": "volume", - "tags": [], - "docs": "", - "complexTypes": [], - "type": "number | undefined" - }, - { - "name": "audioChannelNum", - "tags": [], - "docs": "", - "complexTypes": [], - "type": "number | undefined" - }, - { - "name": "isUrl", - "tags": [], - "docs": "", - "complexTypes": [], - "type": "boolean | undefined" - } - ] - }, - { - "name": "PluginListenerHandle", - "slug": "pluginlistenerhandle", - "docs": "", - "tags": [], - "methods": [], - "properties": [ - { - "name": "remove", - "tags": [], - "docs": "", - "complexTypes": [], - "type": "() => Promise" - } - ] - } - ], - "enums": [], - "typeAliases": [], - "pluginConfigs": [] -} \ No newline at end of file diff --git a/dist/esm/audio-asset.d.ts b/dist/esm/audio-asset.d.ts deleted file mode 100644 index d36f1e2..0000000 --- a/dist/esm/audio-asset.d.ts +++ /dev/null @@ -1,4 +0,0 @@ -export declare class AudioAsset { - readonly audio: HTMLAudioElement; - constructor(audio: HTMLAudioElement); -} diff --git a/dist/esm/audio-asset.js b/dist/esm/audio-asset.js deleted file mode 100644 index 67003ff..0000000 --- a/dist/esm/audio-asset.js +++ /dev/null @@ -1,6 +0,0 @@ -export class AudioAsset { - constructor(audio) { - this.audio = audio; - } -} -//# sourceMappingURL=audio-asset.js.map \ No newline at end of file diff --git a/dist/esm/audio-asset.js.map b/dist/esm/audio-asset.js.map deleted file mode 100644 index 5de9bc2..0000000 --- a/dist/esm/audio-asset.js.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"audio-asset.js","sourceRoot":"","sources":["../../src/audio-asset.ts"],"names":[],"mappings":"AAAA,MAAM,OAAO,UAAU;IAGrB,YAAY,KAAuB;QACjC,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;IACrB,CAAC;CACF"} \ No newline at end of file diff --git a/dist/esm/definitions.d.ts b/dist/esm/definitions.d.ts deleted file mode 100644 index 87779a2..0000000 --- a/dist/esm/definitions.d.ts +++ /dev/null @@ -1,69 +0,0 @@ -import type { PluginListenerHandle } from '@capacitor/core'; -export interface NativeAudio { - configure(options: ConfigureOptions): Promise; - preload(options: PreloadOptions): Promise; - play(options: { - assetId: string; - time?: number; - }): Promise; - pause(options: { - assetId: string; - }): Promise; - resume(options: { - assetId: string; - }): Promise; - loop(options: { - assetId: string; - }): Promise; - stop(options: { - assetId: string; - }): Promise; - unload(options: { - assetId: string; - }): Promise; - setVolume(options: { - assetId: string; - volume: number; - }): Promise; - getCurrentTime(options: { - assetId: string; - }): Promise<{ - currentTime: number; - }>; - getDuration(options: { - assetId: string; - }): Promise<{ - duration: number; - }>; - isPlaying(options: { - assetId: string; - }): Promise<{ - isPlaying: boolean; - }>; - /** - * Listen for asset completed playing event - * - * @since 5.0.1 - */ - addListener(eventName: 'complete', listenerFunc: (event: { - assetId: string; - }) => void): Promise; -} -export interface ConfigureOptions { - /** - * indicating whether or not to fade audio. - * @default true - */ - fade?: boolean; - /** - * indicating whether or not to disable mixed audio. - * @default true */ - focus?: boolean; -} -export interface PreloadOptions { - assetPath: string; - assetId: string; - volume?: number; - audioChannelNum?: number; - isUrl?: boolean; -} diff --git a/dist/esm/definitions.js b/dist/esm/definitions.js deleted file mode 100644 index 497acb5..0000000 --- a/dist/esm/definitions.js +++ /dev/null @@ -1,2 +0,0 @@ -export {}; -//# sourceMappingURL=definitions.js.map \ No newline at end of file diff --git a/dist/esm/definitions.js.map b/dist/esm/definitions.js.map deleted file mode 100644 index a8a0176..0000000 --- a/dist/esm/definitions.js.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"definitions.js","sourceRoot":"","sources":["../../src/definitions.ts"],"names":[],"mappings":""} \ No newline at end of file diff --git a/dist/esm/index.d.ts b/dist/esm/index.d.ts deleted file mode 100644 index 09d7867..0000000 --- a/dist/esm/index.d.ts +++ /dev/null @@ -1,4 +0,0 @@ -import { NativeAudio } from './definitions'; -declare const NativeAudio: NativeAudio; -export * from './definitions'; -export { NativeAudio }; diff --git a/dist/esm/index.js b/dist/esm/index.js deleted file mode 100644 index 0677242..0000000 --- a/dist/esm/index.js +++ /dev/null @@ -1,7 +0,0 @@ -import { registerPlugin } from '@capacitor/core'; -const NativeAudio = registerPlugin('NativeAudio', { - web: () => import('./web').then((m) => new m.NativeAudioWeb()), -}); -export * from './definitions'; -export { NativeAudio }; -//# sourceMappingURL=index.js.map \ No newline at end of file diff --git a/dist/esm/index.js.map b/dist/esm/index.js.map deleted file mode 100644 index f57e211..0000000 --- a/dist/esm/index.js.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AAIjD,MAAM,WAAW,GAAG,cAAc,CAAc,aAAa,EAAE;IAC7D,GAAG,EAAE,GAAG,EAAE,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,IAAI,CAAC,CAAC,cAAc,EAAE,CAAC;CAC/D,CAAC,CAAC;AAEH,cAAc,eAAe,CAAC;AAC9B,OAAO,EAAE,WAAW,EAAE,CAAC"} \ No newline at end of file diff --git a/dist/esm/web.d.ts b/dist/esm/web.d.ts deleted file mode 100644 index adc6edc..0000000 --- a/dist/esm/web.d.ts +++ /dev/null @@ -1,48 +0,0 @@ -import { WebPlugin } from '@capacitor/core'; -import type { ConfigureOptions, PreloadOptions, NativeAudio } from './definitions'; -export declare class NativeAudioWeb extends WebPlugin implements NativeAudio { - private static readonly FILE_LOCATION; - private static readonly AUDIO_ASSET_BY_ASSET_ID; - resume(options: { - assetId: string; - }): Promise; - pause(options: { - assetId: string; - }): Promise; - getCurrentTime(options: { - assetId: string; - }): Promise<{ - currentTime: number; - }>; - getDuration(options: { - assetId: string; - }): Promise<{ - duration: number; - }>; - configure(options: ConfigureOptions): Promise; - preload(options: PreloadOptions): Promise; - play(options: { - assetId: string; - time?: number; - }): Promise; - loop(options: { - assetId: string; - }): Promise; - stop(options: { - assetId: string; - }): Promise; - unload(options: { - assetId: string; - }): Promise; - setVolume(options: { - assetId: string; - volume: number; - }): Promise; - isPlaying(options: { - assetId: string; - }): Promise<{ - isPlaying: boolean; - }>; - private getAudioAsset; - private checkAssetId; -} diff --git a/dist/esm/web.js b/dist/esm/web.js deleted file mode 100644 index 6ca2ee6..0000000 --- a/dist/esm/web.js +++ /dev/null @@ -1,105 +0,0 @@ -import { WebPlugin } from '@capacitor/core'; -import { AudioAsset } from './audio-asset'; -export class NativeAudioWeb extends WebPlugin { - async resume(options) { - const audio = this.getAudioAsset(options.assetId).audio; - if (audio.paused) { - return audio.play(); - } - } - async pause(options) { - const audio = this.getAudioAsset(options.assetId).audio; - return audio.pause(); - } - async getCurrentTime(options) { - const audio = this.getAudioAsset(options.assetId).audio; - return { currentTime: audio.currentTime }; - } - async getDuration(options) { - const audio = this.getAudioAsset(options.assetId).audio; - if (Number.isNaN(audio.duration)) { - throw 'no duration available'; - } - if (!Number.isFinite(audio.duration)) { - throw 'duration not available => media resource is streaming'; - } - return { duration: audio.duration }; - } - async configure(options) { - throw `configure is not supported for web: ${JSON.stringify(options)}`; - } - async preload(options) { - var _a; - if (NativeAudioWeb.AUDIO_ASSET_BY_ASSET_ID.has(options.assetId)) { - throw 'AssetId already exists. Unload first if like to change!'; - } - if (!((_a = options.assetPath) === null || _a === void 0 ? void 0 : _a.length)) { - throw 'no assetPath provided'; - } - if (!options.isUrl && !new RegExp('^/?' + NativeAudioWeb.FILE_LOCATION).test(options.assetPath)) { - const slashPrefix = options.assetPath.startsWith('/') ? '' : '/'; - options.assetPath = `${NativeAudioWeb.FILE_LOCATION}${slashPrefix}${options.assetPath}`; - } - const audio = new Audio(options.assetPath); - audio.autoplay = false; - audio.loop = false; - audio.preload = 'auto'; - if (options.volume) { - audio.volume = options.volume; - } - NativeAudioWeb.AUDIO_ASSET_BY_ASSET_ID.set(options.assetId, new AudioAsset(audio)); - } - async play(options) { - var _a; - const audio = this.getAudioAsset(options.assetId).audio; - await this.stop(options); - audio.loop = false; - audio.currentTime = (_a = options.time) !== null && _a !== void 0 ? _a : 0; - return audio.play(); - } - async loop(options) { - const audio = this.getAudioAsset(options.assetId).audio; - await this.stop(options); - audio.loop = true; - return audio.play(); - } - async stop(options) { - const audio = this.getAudioAsset(options.assetId).audio; - audio.pause(); - audio.loop = false; - audio.currentTime = 0; - } - async unload(options) { - await this.stop(options); - NativeAudioWeb.AUDIO_ASSET_BY_ASSET_ID.delete(options.assetId); - } - async setVolume(options) { - if (typeof (options === null || options === void 0 ? void 0 : options.volume) !== 'number') { - throw 'no volume provided'; - } - const audio = this.getAudioAsset(options.assetId).audio; - audio.volume = options.volume; - } - async isPlaying(options) { - const audio = this.getAudioAsset(options.assetId).audio; - return { isPlaying: !audio.paused }; - } - getAudioAsset(assetId) { - this.checkAssetId(assetId); - if (!NativeAudioWeb.AUDIO_ASSET_BY_ASSET_ID.has(assetId)) { - throw `no asset for assetId "${assetId}" available. Call preload first!`; - } - return NativeAudioWeb.AUDIO_ASSET_BY_ASSET_ID.get(assetId); - } - checkAssetId(assetId) { - if (typeof assetId !== 'string') { - throw 'assetId must be a string'; - } - if (!(assetId === null || assetId === void 0 ? void 0 : assetId.length)) { - throw 'no assetId provided'; - } - } -} -NativeAudioWeb.FILE_LOCATION = 'assets/sounds'; -NativeAudioWeb.AUDIO_ASSET_BY_ASSET_ID = new Map(); -//# sourceMappingURL=web.js.map \ No newline at end of file diff --git a/dist/esm/web.js.map b/dist/esm/web.js.map deleted file mode 100644 index 4a24dba..0000000 --- a/dist/esm/web.js.map +++ /dev/null @@ -1 +0,0 @@ -{"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;AAG3C,MAAM,OAAO,cAAe,SAAQ,SAAS;IAI3C,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;YAChB,OAAO,KAAK,CAAC,IAAI,EAAE,CAAC;SACrB;IACH,CAAC;IAED,KAAK,CAAC,KAAK,CAAC,OAA4B;QACtC,MAAM,KAAK,GAAqB,IAAI,CAAC,aAAa,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,KAAK,CAAC;QAC1E,OAAO,KAAK,CAAC,KAAK,EAAE,CAAC;IACvB,CAAC;IAED,KAAK,CAAC,cAAc,CAAC,OAA4B;QAC/C,MAAM,KAAK,GAAqB,IAAI,CAAC,aAAa,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,KAAK,CAAC;QAC1E,OAAO,EAAE,WAAW,EAAE,KAAK,CAAC,WAAW,EAAE,CAAC;IAC5C,CAAC;IAED,KAAK,CAAC,WAAW,CAAC,OAA4B;QAC5C,MAAM,KAAK,GAAqB,IAAI,CAAC,aAAa,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,KAAK,CAAC;QAC1E,IAAI,MAAM,CAAC,KAAK,CAA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ugin.cjs.js +++ /dev/null @@ -1,126 +0,0 @@ -'use strict'; - -Object.defineProperty(exports, '__esModule', { value: true }); - -var core = require('@capacitor/core'); - -const NativeAudio = core.registerPlugin('NativeAudio', { - web: () => Promise.resolve().then(function () { return web; }).then((m) => new m.NativeAudioWeb()), -}); - -class AudioAsset { - constructor(audio) { - this.audio = audio; - } -} - -class NativeAudioWeb extends core.WebPlugin { - async resume(options) { - const audio = this.getAudioAsset(options.assetId).audio; - if (audio.paused) { - return audio.play(); - } - } - async pause(options) { - const audio = this.getAudioAsset(options.assetId).audio; - return audio.pause(); - } - async getCurrentTime(options) { - const audio = this.getAudioAsset(options.assetId).audio; - return { currentTime: audio.currentTime }; - } - async getDuration(options) { - const audio = this.getAudioAsset(options.assetId).audio; - if (Number.isNaN(audio.duration)) { - throw 'no duration available'; - } - if (!Number.isFinite(audio.duration)) { - throw 'duration not available => media resource is streaming'; - } - return { duration: audio.duration }; - } - async configure(options) { - throw `configure is not supported for web: ${JSON.stringify(options)}`; - } - async preload(options) { - var _a; - if (NativeAudioWeb.AUDIO_ASSET_BY_ASSET_ID.has(options.assetId)) { - throw 'AssetId already exists. Unload first if like to change!'; - } - if (!((_a = options.assetPath) === null || _a === void 0 ? void 0 : _a.length)) { - throw 'no assetPath provided'; - } - if (!options.isUrl && !new RegExp('^/?' + NativeAudioWeb.FILE_LOCATION).test(options.assetPath)) { - const slashPrefix = options.assetPath.startsWith('/') ? '' : '/'; - options.assetPath = `${NativeAudioWeb.FILE_LOCATION}${slashPrefix}${options.assetPath}`; - } - const audio = new Audio(options.assetPath); - audio.autoplay = false; - audio.loop = false; - audio.preload = 'auto'; - if (options.volume) { - audio.volume = options.volume; - } - NativeAudioWeb.AUDIO_ASSET_BY_ASSET_ID.set(options.assetId, new AudioAsset(audio)); - } - async play(options) { - var _a; - const audio = this.getAudioAsset(options.assetId).audio; - await this.stop(options); - audio.loop = false; - audio.currentTime = (_a = options.time) !== null && _a !== void 0 ? _a : 0; - return audio.play(); - } - async loop(options) { - const audio = this.getAudioAsset(options.assetId).audio; - await this.stop(options); - audio.loop = true; - return audio.play(); - } - async stop(options) { - const audio = this.getAudioAsset(options.assetId).audio; - audio.pause(); - audio.loop = false; - audio.currentTime = 0; - } - async unload(options) { - await this.stop(options); - NativeAudioWeb.AUDIO_ASSET_BY_ASSET_ID.delete(options.assetId); - } - async setVolume(options) { - if (typeof (options === null || options === void 0 ? void 0 : options.volume) !== 'number') { - throw 'no volume provided'; - } - const audio = this.getAudioAsset(options.assetId).audio; - audio.volume = options.volume; - } - async isPlaying(options) { - const audio = this.getAudioAsset(options.assetId).audio; - return { isPlaying: !audio.paused }; - } - getAudioAsset(assetId) { - this.checkAssetId(assetId); - if (!NativeAudioWeb.AUDIO_ASSET_BY_ASSET_ID.has(assetId)) { - throw `no asset for assetId "${assetId}" available. Call preload first!`; - } - return NativeAudioWeb.AUDIO_ASSET_BY_ASSET_ID.get(assetId); - } - checkAssetId(assetId) { - if (typeof assetId !== 'string') { - throw 'assetId must be a string'; - } - if (!(assetId === null || assetId === void 0 ? void 0 : assetId.length)) { - throw 'no assetId provided'; - } - } -} -NativeAudioWeb.FILE_LOCATION = 'assets/sounds'; -NativeAudioWeb.AUDIO_ASSET_BY_ASSET_ID = new Map(); - -var web = /*#__PURE__*/Object.freeze({ - __proto__: null, - NativeAudioWeb: NativeAudioWeb -}); - -exports.NativeAudio = NativeAudio; -//# sourceMappingURL=plugin.cjs.js.map diff --git a/dist/plugin.cjs.js.map b/dist/plugin.cjs.js.map deleted file mode 100644 index ccd2c88..0000000 --- a/dist/plugin.cjs.js.map +++ /dev/null @@ -1 +0,0 @@ -{"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 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 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 = 'assets/sounds';\nNativeAudioWeb.AUDIO_ASSET_BY_ASSET_ID = new Map();\n//# sourceMappingURL=web.js.map"],"names":["registerPlugin","WebPlugin"],"mappings":";;;;;;AACK,MAAC,WAAW,GAAGA,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,MAAM,MAAM,CAAC,OAAO,EAAE;AAC1B,QAAQ,MAAM,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AAQ,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;AAC/C,cAAc,CAAC,uBAAuB,GAAG,IAAI,GAAG,EAAE;;;;;;;;;"} \ No newline at end of file diff --git a/dist/plugin.js b/dist/plugin.js deleted file mode 100644 index 57fa9d4..0000000 --- a/dist/plugin.js +++ /dev/null @@ -1,129 +0,0 @@ -var capacitorApp = (function (exports, core) { - 'use strict'; - - const NativeAudio = core.registerPlugin('NativeAudio', { - web: () => Promise.resolve().then(function () { return web; }).then((m) => new m.NativeAudioWeb()), - }); - - class AudioAsset { - constructor(audio) { - this.audio = audio; - } - } - - class NativeAudioWeb extends core.WebPlugin { - async resume(options) { - const audio = this.getAudioAsset(options.assetId).audio; - if (audio.paused) { - return audio.play(); - } - } - async pause(options) { - const audio = this.getAudioAsset(options.assetId).audio; - return audio.pause(); - } - async getCurrentTime(options) { - const audio = this.getAudioAsset(options.assetId).audio; - return { currentTime: audio.currentTime }; - } - async getDuration(options) { - const audio = this.getAudioAsset(options.assetId).audio; - if (Number.isNaN(audio.duration)) { - throw 'no duration available'; - } - if (!Number.isFinite(audio.duration)) { - throw 'duration not available => media resource is streaming'; - } - return { duration: audio.duration }; - } - async configure(options) { - throw `configure is not supported for web: ${JSON.stringify(options)}`; - } - async preload(options) { - var _a; - if (NativeAudioWeb.AUDIO_ASSET_BY_ASSET_ID.has(options.assetId)) { - throw 'AssetId already exists. Unload first if like to change!'; - } - if (!((_a = options.assetPath) === null || _a === void 0 ? void 0 : _a.length)) { - throw 'no assetPath provided'; - } - if (!options.isUrl && !new RegExp('^/?' + NativeAudioWeb.FILE_LOCATION).test(options.assetPath)) { - const slashPrefix = options.assetPath.startsWith('/') ? '' : '/'; - options.assetPath = `${NativeAudioWeb.FILE_LOCATION}${slashPrefix}${options.assetPath}`; - } - const audio = new Audio(options.assetPath); - audio.autoplay = false; - audio.loop = false; - audio.preload = 'auto'; - if (options.volume) { - audio.volume = options.volume; - } - NativeAudioWeb.AUDIO_ASSET_BY_ASSET_ID.set(options.assetId, new AudioAsset(audio)); - } - async play(options) { - var _a; - const audio = this.getAudioAsset(options.assetId).audio; - await this.stop(options); - audio.loop = false; - audio.currentTime = (_a = options.time) !== null && _a !== void 0 ? _a : 0; - return audio.play(); - } - async loop(options) { - const audio = this.getAudioAsset(options.assetId).audio; - await this.stop(options); - audio.loop = true; - return audio.play(); - } - async stop(options) { - const audio = this.getAudioAsset(options.assetId).audio; - audio.pause(); - audio.loop = false; - audio.currentTime = 0; - } - async unload(options) { - await this.stop(options); - NativeAudioWeb.AUDIO_ASSET_BY_ASSET_ID.delete(options.assetId); - } - async setVolume(options) { - if (typeof (options === null || options === void 0 ? void 0 : options.volume) !== 'number') { - throw 'no volume provided'; - } - const audio = this.getAudioAsset(options.assetId).audio; - audio.volume = options.volume; - } - async isPlaying(options) { - const audio = this.getAudioAsset(options.assetId).audio; - return { isPlaying: !audio.paused }; - } - getAudioAsset(assetId) { - this.checkAssetId(assetId); - if (!NativeAudioWeb.AUDIO_ASSET_BY_ASSET_ID.has(assetId)) { - throw `no asset for assetId "${assetId}" available. Call preload first!`; - } - return NativeAudioWeb.AUDIO_ASSET_BY_ASSET_ID.get(assetId); - } - checkAssetId(assetId) { - if (typeof assetId !== 'string') { - throw 'assetId must be a string'; - } - if (!(assetId === null || assetId === void 0 ? void 0 : assetId.length)) { - throw 'no assetId provided'; - } - } - } - NativeAudioWeb.FILE_LOCATION = 'assets/sounds'; - NativeAudioWeb.AUDIO_ASSET_BY_ASSET_ID = new Map(); - - var web = /*#__PURE__*/Object.freeze({ - __proto__: null, - NativeAudioWeb: NativeAudioWeb - }); - - exports.NativeAudio = NativeAudio; - - Object.defineProperty(exports, '__esModule', { value: true }); - - return exports; - -})({}, capacitorExports); -//# sourceMappingURL=plugin.js.map diff --git a/dist/plugin.js.map b/dist/plugin.js.map deleted file mode 100644 index 7b28375..0000000 --- a/dist/plugin.js.map +++ /dev/null @@ -1 +0,0 @@ -{"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 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 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 = 'assets/sounds';\nNativeAudioWeb.AUDIO_ASSET_BY_ASSET_ID = new Map();\n//# sourceMappingURL=web.js.map"],"names":["registerPlugin","WebPlugin"],"mappings":";;;AACK,UAAC,WAAW,GAAGA,mBAAc,CAAC,aA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