@capgo/native-audio 6.4.14 → 6.4.18
Sign up to get free protection for your applications and to get access to all the features.
- package/README.md +2 -2
- package/android/src/main/java/ee/forgr/audio/NativeAudio.java +1 -0
- package/dist/docs.json +2 -2
- package/dist/esm/definitions.d.ts +3 -1
- package/dist/esm/definitions.js.map +1 -1
- package/dist/esm/web.d.ts +3 -1
- package/dist/esm/web.js +2 -2
- package/dist/esm/web.js.map +1 -1
- package/dist/plugin.cjs.js +2 -2
- package/dist/plugin.cjs.js.map +1 -1
- package/dist/plugin.js +2 -2
- package/dist/plugin.js.map +1 -1
- package/ios/Plugin/Plugin.swift +139 -131
- package/package.json +1 -1
package/README.md
CHANGED
@@ -252,7 +252,7 @@ Load an audio file
|
|
252
252
|
### isPreloaded(...)
|
253
253
|
|
254
254
|
```typescript
|
255
|
-
isPreloaded(options: PreloadOptions) => Promise<boolean>
|
255
|
+
isPreloaded(options: PreloadOptions) => Promise<{ found: boolean; }>
|
256
256
|
```
|
257
257
|
|
258
258
|
Check if an audio file is preloaded
|
@@ -261,7 +261,7 @@ Check if an audio file is preloaded
|
|
261
261
|
| ------------- | --------------------------------------------------------- |
|
262
262
|
| **`options`** | <code><a href="#preloadoptions">PreloadOptions</a></code> |
|
263
263
|
|
264
|
-
**Returns:** <code>Promise<boolean></code>
|
264
|
+
**Returns:** <code>Promise<{ found: boolean; }></code>
|
265
265
|
|
266
266
|
**Since:** 6.1.0
|
267
267
|
|
package/dist/docs.json
CHANGED
@@ -75,7 +75,7 @@
|
|
75
75
|
},
|
76
76
|
{
|
77
77
|
"name": "isPreloaded",
|
78
|
-
"signature": "(options: PreloadOptions) => Promise<boolean>",
|
78
|
+
"signature": "(options: PreloadOptions) => Promise<{ found: boolean; }>",
|
79
79
|
"parameters": [
|
80
80
|
{
|
81
81
|
"name": "options",
|
@@ -83,7 +83,7 @@
|
|
83
83
|
"type": "PreloadOptions"
|
84
84
|
}
|
85
85
|
],
|
86
|
-
"returns": "Promise<boolean>",
|
86
|
+
"returns": "Promise<{ found: boolean; }>",
|
87
87
|
"tags": [
|
88
88
|
{
|
89
89
|
"name": "since",
|
@@ -106,7 +106,9 @@ export interface NativeAudio {
|
|
106
106
|
* @param option {@link Assets}
|
107
107
|
* @returns {Promise<boolean>}
|
108
108
|
*/
|
109
|
-
isPreloaded(options: PreloadOptions): Promise<
|
109
|
+
isPreloaded(options: PreloadOptions): Promise<{
|
110
|
+
found: boolean;
|
111
|
+
}>;
|
110
112
|
/**
|
111
113
|
* Play an audio file
|
112
114
|
* @since 5.0.0
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"definitions.js","sourceRoot":"","sources":["../../src/definitions.ts"],"names":[],"mappings":"","sourcesContent":["import type { PluginListenerHandle } from \"@capacitor/core\";\n\nexport interface CompletedEvent {\n /**\n * Emit when a play completes\n *\n * @since 5.0.0\n */\n assetId: string;\n}\nexport type CompletedListener = (state: CompletedEvent) => void;\nexport interface Assets {\n /**\n * Asset Id, unique identifier of the file\n */\n assetId: string;\n}\nexport interface AssetVolume {\n /**\n * Asset Id, unique identifier of the file\n */\n assetId: string;\n /**\n * Volume of the audio, between 0.1 and 1.0\n */\n volume: number;\n}\n\nexport interface AssetRate {\n /**\n * Asset Id, unique identifier of the file\n */\n assetId: string;\n /**\n * Rate of the audio, between 0.1 and 1.0\n */\n rate: number;\n}\n\nexport interface AssetPlayOptions {\n /**\n * Asset Id, unique identifier of the file\n */\n assetId: string;\n /**\n * Time to start playing the audio, in milliseconds\n */\n time?: number;\n /**\n * Delay to start playing the audio, in milliseconds\n */\n delay?: number;\n}\n\nexport interface ConfigureOptions {\n /**\n * Play the audio with Fade effect, only available for IOS\n */\n fade?: boolean;\n /**\n * focus the audio with Audio Focus\n */\n focus?: boolean;\n /**\n * Play the audio in the background\n */\n background?: boolean;\n}\n\nexport interface PreloadOptions {\n /**\n * Path to the audio file, relative path of the file, absolute url (file://) or remote url (https://)\n */\n assetPath: string;\n /**\n * Asset Id, unique identifier of the file\n */\n assetId: string;\n /**\n * Volume of the audio, between 0.1 and 1.0\n */\n volume?: number;\n /**\n * Audio channel number, default is 1\n */\n audioChannelNum?: number;\n /**\n * Is the audio file a URL, pass true if assetPath is a `file://` url\n */\n isUrl?: boolean;\n}\n\nexport interface NativeAudio {\n /**\n * Configure the audio player\n * @since 5.0.0\n * @param option {@link ConfigureOptions}\n * @returns\n */\n configure(options: ConfigureOptions): Promise<void>;\n /**\n * Load an audio file\n * @since 5.0.0\n * @param option {@link PreloadOptions}\n * @returns\n */\n preload(options: PreloadOptions): Promise<void>;\n /**\n * Check if an audio file is preloaded\n *\n * @since 6.1.0\n * @param option {@link Assets}\n * @returns {Promise<boolean>}\n */\n isPreloaded(options: PreloadOptions): Promise<boolean>;\n /**\n * Play an audio file\n * @since 5.0.0\n * @param option {@link PlayOptions}\n * @returns\n */\n play(options: {\n assetId: string;\n time?: number;\n delay?: number;\n }): Promise<void>;\n /**\n * Pause an audio file\n * @since 5.0.0\n * @param option {@link Assets}\n * @returns\n */\n pause(options: Assets): Promise<void>;\n /**\n * Resume an audio file\n * @since 5.0.0\n * @param option {@link Assets}\n * @returns\n */\n resume(options: Assets): Promise<void>;\n /**\n * Stop an audio file\n * @since 5.0.0\n * @param option {@link Assets}\n * @returns\n */\n loop(options: Assets): Promise<void>;\n /**\n * Stop an audio file\n * @since 5.0.0\n * @param option {@link Assets}\n * @returns\n */\n stop(options: Assets): Promise<void>;\n /**\n * Unload an audio file\n * @since 5.0.0\n * @param option {@link Assets}\n * @returns\n */\n unload(options: Assets): Promise<void>;\n /**\n * Set the volume of an audio file\n * @since 5.0.0\n * @param option {@link AssetVolume}\n * @returns {Promise<void>}\n */\n setVolume(options: { assetId: string; volume: number }): Promise<void>;\n /**\n * Set the rate of an audio file\n * @since 5.0.0\n * @param option {@link AssetPlayOptions}\n * @returns {Promise<void>}\n */\n setRate(options: { assetId: string; rate: number }): Promise<void>;\n /**\n * Set the current time of an audio file\n * @since 5.0.0\n * @param option {@link AssetPlayOptions}\n * @returns {Promise<{ currentTime: number }>}\n */\n getCurrentTime(options: {\n assetId: string;\n }): Promise<{ currentTime: number }>;\n /**\n * Get the duration of an audio file\n * @since 5.0.0\n * @param option {@link AssetPlayOptions}\n * @returns {Promise<{ duration: number }>}\n */\n getDuration(options: Assets): Promise<{ duration: number }>;\n /**\n * Check if an audio file is playing\n *\n * @since 5.0.0\n * @param option {@link AssetPlayOptions}\n * @returns {Promise<boolean>}\n */\n isPlaying(options: Assets): Promise<{ isPlaying: boolean }>;\n /**\n * Listen for complete event\n *\n * @since 5.0.0\n * return {@link CompletedEvent}\n */\n addListener(\n eventName: \"complete\",\n listenerFunc: CompletedListener,\n ): Promise<PluginListenerHandle>;\n}\n"]}
|
1
|
+
{"version":3,"file":"definitions.js","sourceRoot":"","sources":["../../src/definitions.ts"],"names":[],"mappings":"","sourcesContent":["import type { PluginListenerHandle } from \"@capacitor/core\";\n\nexport interface CompletedEvent {\n /**\n * Emit when a play completes\n *\n * @since 5.0.0\n */\n assetId: string;\n}\nexport type CompletedListener = (state: CompletedEvent) => void;\nexport interface Assets {\n /**\n * Asset Id, unique identifier of the file\n */\n assetId: string;\n}\nexport interface AssetVolume {\n /**\n * Asset Id, unique identifier of the file\n */\n assetId: string;\n /**\n * Volume of the audio, between 0.1 and 1.0\n */\n volume: number;\n}\n\nexport interface AssetRate {\n /**\n * Asset Id, unique identifier of the file\n */\n assetId: string;\n /**\n * Rate of the audio, between 0.1 and 1.0\n */\n rate: number;\n}\n\nexport interface AssetPlayOptions {\n /**\n * Asset Id, unique identifier of the file\n */\n assetId: string;\n /**\n * Time to start playing the audio, in milliseconds\n */\n time?: number;\n /**\n * Delay to start playing the audio, in milliseconds\n */\n delay?: number;\n}\n\nexport interface ConfigureOptions {\n /**\n * Play the audio with Fade effect, only available for IOS\n */\n fade?: boolean;\n /**\n * focus the audio with Audio Focus\n */\n focus?: boolean;\n /**\n * Play the audio in the background\n */\n background?: boolean;\n}\n\nexport interface PreloadOptions {\n /**\n * Path to the audio file, relative path of the file, absolute url (file://) or remote url (https://)\n */\n assetPath: string;\n /**\n * Asset Id, unique identifier of the file\n */\n assetId: string;\n /**\n * Volume of the audio, between 0.1 and 1.0\n */\n volume?: number;\n /**\n * Audio channel number, default is 1\n */\n audioChannelNum?: number;\n /**\n * Is the audio file a URL, pass true if assetPath is a `file://` url\n */\n isUrl?: boolean;\n}\n\nexport interface NativeAudio {\n /**\n * Configure the audio player\n * @since 5.0.0\n * @param option {@link ConfigureOptions}\n * @returns\n */\n configure(options: ConfigureOptions): Promise<void>;\n /**\n * Load an audio file\n * @since 5.0.0\n * @param option {@link PreloadOptions}\n * @returns\n */\n preload(options: PreloadOptions): Promise<void>;\n /**\n * Check if an audio file is preloaded\n *\n * @since 6.1.0\n * @param option {@link Assets}\n * @returns {Promise<boolean>}\n */\n isPreloaded(options: PreloadOptions): Promise<{ found: boolean }>;\n /**\n * Play an audio file\n * @since 5.0.0\n * @param option {@link PlayOptions}\n * @returns\n */\n play(options: {\n assetId: string;\n time?: number;\n delay?: number;\n }): Promise<void>;\n /**\n * Pause an audio file\n * @since 5.0.0\n * @param option {@link Assets}\n * @returns\n */\n pause(options: Assets): Promise<void>;\n /**\n * Resume an audio file\n * @since 5.0.0\n * @param option {@link Assets}\n * @returns\n */\n resume(options: Assets): Promise<void>;\n /**\n * Stop an audio file\n * @since 5.0.0\n * @param option {@link Assets}\n * @returns\n */\n loop(options: Assets): Promise<void>;\n /**\n * Stop an audio file\n * @since 5.0.0\n * @param option {@link Assets}\n * @returns\n */\n stop(options: Assets): Promise<void>;\n /**\n * Unload an audio file\n * @since 5.0.0\n * @param option {@link Assets}\n * @returns\n */\n unload(options: Assets): Promise<void>;\n /**\n * Set the volume of an audio file\n * @since 5.0.0\n * @param option {@link AssetVolume}\n * @returns {Promise<void>}\n */\n setVolume(options: { assetId: string; volume: number }): Promise<void>;\n /**\n * Set the rate of an audio file\n * @since 5.0.0\n * @param option {@link AssetPlayOptions}\n * @returns {Promise<void>}\n */\n setRate(options: { assetId: string; rate: number }): Promise<void>;\n /**\n * Set the current time of an audio file\n * @since 5.0.0\n * @param option {@link AssetPlayOptions}\n * @returns {Promise<{ currentTime: number }>}\n */\n getCurrentTime(options: {\n assetId: string;\n }): Promise<{ currentTime: number }>;\n /**\n * Get the duration of an audio file\n * @since 5.0.0\n * @param option {@link AssetPlayOptions}\n * @returns {Promise<{ duration: number }>}\n */\n getDuration(options: Assets): Promise<{ duration: number }>;\n /**\n * Check if an audio file is playing\n *\n * @since 5.0.0\n * @param option {@link AssetPlayOptions}\n * @returns {Promise<boolean>}\n */\n isPlaying(options: Assets): Promise<{ isPlaying: boolean }>;\n /**\n * Listen for complete event\n *\n * @since 5.0.0\n * return {@link CompletedEvent}\n */\n addListener(\n eventName: \"complete\",\n listenerFunc: CompletedListener,\n ): Promise<PluginListenerHandle>;\n}\n"]}
|
package/dist/esm/web.d.ts
CHANGED
@@ -22,7 +22,9 @@ export declare class NativeAudioWeb extends WebPlugin implements NativeAudio {
|
|
22
22
|
duration: number;
|
23
23
|
}>;
|
24
24
|
configure(options: ConfigureOptions): Promise<void>;
|
25
|
-
isPreloaded(options: PreloadOptions): Promise<
|
25
|
+
isPreloaded(options: PreloadOptions): Promise<{
|
26
|
+
found: boolean;
|
27
|
+
}>;
|
26
28
|
preload(options: PreloadOptions): Promise<void>;
|
27
29
|
private onEnded;
|
28
30
|
play(options: {
|
package/dist/esm/web.js
CHANGED
@@ -33,10 +33,10 @@ export class NativeAudioWeb extends WebPlugin {
|
|
33
33
|
}
|
34
34
|
async isPreloaded(options) {
|
35
35
|
try {
|
36
|
-
return !!this.getAudioAsset(options.assetId);
|
36
|
+
return { found: !!this.getAudioAsset(options.assetId) };
|
37
37
|
}
|
38
38
|
catch (e) {
|
39
|
-
return false;
|
39
|
+
return { found: false };
|
40
40
|
}
|
41
41
|
}
|
42
42
|
async preload(options) {
|
package/dist/esm/web.js.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"web.js","sourceRoot":"","sources":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,CAAC,KAAK,CAAC,MAAM,EAAE,CAAC;IACtC,CAAC;IAEO,aAAa,CAAC,OAAe;QACnC,IAAI,CAAC,YAAY,CAAC,OAAO,CAAC,CAAC;QAE3B,IAAI,CAAC,cAAc,CAAC,uBAAuB,CAAC,GAAG,CAAC,OAAO,CAAC,EAAE,CAAC;YACzD,MAAM,yBAAyB,OAAO,kCAAkC,CAAC;QAC3E,CAAC;QAED,OAAO,cAAc,CAAC,uBAAuB,CAAC,GAAG,CAAC,OAAO,CAAe,CAAC;IAC3E,CAAC;IAEO,YAAY,CAAC,OAAe;QAClC,IAAI,OAAO,OAAO,KAAK,QAAQ,EAAE,CAAC;YAChC,MAAM,0BAA0B,CAAC;QACnC,CAAC;QAED,IAAI,CAAC,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<boolean> {\n try {\n return !!this.getAudioAsset(options.assetId);\n } catch (e) {\n return 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":"AA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AAO,EAAE,SAAS,EAAE,CAAC,KAAK,CAAC,MAAM,EAAE,CAAC;IACtC,CAAC;IAEO,aAAa,CAAC,OAAe;QACnC,IAAI,CAAC,YAAY,CAAC,OAAO,CAAC,CAAC;QAE3B,IAAI,CAAC,cAAc,CAAC,uBAAuB,CAAC,GAAG,CAAC,OAAO,CAAC,EAAE,CAAC;YACzD,MAAM,yBAAyB,OAAO,kCAAkC,CAAC;QAC3E,CAAC;QAED,OAAO,cAAc,CAAC,uBAAuB,CAAC,GAAG,CAAC,OAAO,CAAe,CAAC;IAC3E,CAAC;IAEO,YAAY,CAAC,OAAe;QAClC,IAAI,OAAO,OAAO,KAAK,QAAQ,EAAE,CAAC;YAChC,MAAM,0BAA0B,CAAC;QACnC,CAAC;QAED,IAAI,CAAC,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"]}
|
package/dist/plugin.cjs.js
CHANGED
@@ -45,10 +45,10 @@ class NativeAudioWeb extends core.WebPlugin {
|
|
45
45
|
}
|
46
46
|
async isPreloaded(options) {
|
47
47
|
try {
|
48
|
-
return !!this.getAudioAsset(options.assetId);
|
48
|
+
return { found: !!this.getAudioAsset(options.assetId) };
|
49
49
|
}
|
50
50
|
catch (e) {
|
51
|
-
return false;
|
51
|
+
return { found: false };
|
52
52
|
}
|
53
53
|
}
|
54
54
|
async preload(options) {
|
package/dist/plugin.cjs.js.map
CHANGED
@@ -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 !!this.getAudioAsset(options.assetId);\n }\n catch (e) {\n return 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,KA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acitor/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,CAAC,CAAC,KAAK,CAAC;AAChE,QAAQ,OAAO,EAAE,WAAW,EAAE,KAAK,CAAC,WAAW,EAAE,CAAC;AAClD,KAAK;AACL,I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AQ,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;;;;;;;;;;"}
|
package/dist/plugin.js
CHANGED
@@ -44,10 +44,10 @@ var capacitorCapacitorNativeAudio = (function (exports, core) {
|
|
44
44
|
}
|
45
45
|
async isPreloaded(options) {
|
46
46
|
try {
|
47
|
-
return !!this.getAudioAsset(options.assetId);
|
47
|
+
return { found: !!this.getAudioAsset(options.assetId) };
|
48
48
|
}
|
49
49
|
catch (e) {
|
50
|
-
return false;
|
50
|
+
return { found: false };
|
51
51
|
}
|
52
52
|
}
|
53
53
|
async preload(options) {
|
package/dist/plugin.js.map
CHANGED
@@ -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 !!this.getAudioAsset(options.assetId);\n }\n catch (e) {\n return 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,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;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,MAAM,cAAc,CAAC,OAAO,EAAE;IAClC,QAAQ,MAAM,KAAK,GAAG,IAAI,CAAC,aAAa,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,KAAK,CAAC;IAChE,QAAQ,OAAO,EAAE,WAAW,EAAE,KAAK,CAAC,WAAW,EAAE,CAAC;IAClD,KAAK;IACL,IAAI,MAAM,WAAW,CAAC,OA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AAc,CAAC,uBAAuB,CAAC,GAAG,CAAC,OAAO,CAAC,EAAE;IAClE,YAAY,MAAM,CAAC,sBAAsB,EAAE,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(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,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;I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;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;;;;;;;;;;;;;;;;"}
|
package/ios/Plugin/Plugin.swift
CHANGED
@@ -135,33 +135,37 @@ public class NativeAudio: CAPPlugin, AVAudioPlayerDelegate {
|
|
135
135
|
let audioId = call.getString(Constant.AssetIdKey) ?? ""
|
136
136
|
let time = call.getDouble("time") ?? 0
|
137
137
|
let delay = call.getDouble("delay") ?? 0
|
138
|
-
if audioId
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
} else {
|
161
|
-
call.reject(Constant.ErrorAssetNotFound)
|
162
|
-
}
|
163
|
-
}
|
138
|
+
if audioId == "" {
|
139
|
+
call.reject(Constant.ErrorAssetId)
|
140
|
+
return
|
141
|
+
}
|
142
|
+
if self.audioList.count == 0 {
|
143
|
+
call.reject("Audio list is empty")
|
144
|
+
return
|
145
|
+
}
|
146
|
+
let queue = DispatchQueue(label: "ee.forgr.audio.complex.queue", qos: .userInitiated)
|
147
|
+
let asset = self.audioList[audioId]
|
148
|
+
if asset == nil {
|
149
|
+
call.reject(Constant.ErrorAssetNotFound)
|
150
|
+
return
|
151
|
+
}
|
152
|
+
queue.async {
|
153
|
+
if asset is AudioAsset {
|
154
|
+
let audioAsset = asset as? AudioAsset
|
155
|
+
self.activateSession()
|
156
|
+
if self.fadeMusic {
|
157
|
+
audioAsset?.playWithFade(time: time)
|
158
|
+
} else {
|
159
|
+
audioAsset?.play(time: time, delay: delay)
|
164
160
|
}
|
161
|
+
call.resolve()
|
162
|
+
} else if asset is Int32 {
|
163
|
+
let audioAsset = asset as? NSNumber ?? 0
|
164
|
+
self.activateSession()
|
165
|
+
AudioServicesPlaySystemSound(SystemSoundID(audioAsset.intValue))
|
166
|
+
call.resolve()
|
167
|
+
} else {
|
168
|
+
call.reject(Constant.ErrorAssetNotFound)
|
165
169
|
}
|
166
170
|
}
|
167
171
|
}
|
@@ -172,14 +176,16 @@ public class NativeAudio: CAPPlugin, AVAudioPlayerDelegate {
|
|
172
176
|
call.reject(Constant.ErrorAssetId)
|
173
177
|
return nil
|
174
178
|
}
|
175
|
-
if self.audioList.count
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
179
|
+
if self.audioList.count == 0 {
|
180
|
+
call.reject("Audio list is empty")
|
181
|
+
return nil
|
182
|
+
}
|
183
|
+
let asset = self.audioList[audioId]
|
184
|
+
if asset == nil || !(asset is AudioAsset) {
|
185
|
+
call.reject(Constant.ErrorAssetNotFound + " - " + audioId)
|
186
|
+
return nil
|
180
187
|
}
|
181
|
-
|
182
|
-
return nil
|
188
|
+
return asset as? AudioAsset
|
183
189
|
}
|
184
190
|
|
185
191
|
@objc func getDuration(_ call: CAPPluginCall) {
|
@@ -224,6 +230,10 @@ public class NativeAudio: CAPPlugin, AVAudioPlayerDelegate {
|
|
224
230
|
@objc func stop(_ call: CAPPluginCall) {
|
225
231
|
let audioId = call.getString(Constant.AssetIdKey) ?? ""
|
226
232
|
|
233
|
+
if self.audioList.count == 0 {
|
234
|
+
call.reject("Audio list is empty")
|
235
|
+
return
|
236
|
+
}
|
227
237
|
do {
|
228
238
|
try stopAudio(audioId: audioId)
|
229
239
|
self.endSession()
|
@@ -244,16 +254,18 @@ public class NativeAudio: CAPPlugin, AVAudioPlayerDelegate {
|
|
244
254
|
|
245
255
|
@objc func unload(_ call: CAPPluginCall) {
|
246
256
|
let audioId = call.getString(Constant.AssetIdKey) ?? ""
|
247
|
-
if self.audioList.count
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
257
|
+
if self.audioList.count == 0 {
|
258
|
+
call.reject("Audio list is empty")
|
259
|
+
return
|
260
|
+
}
|
261
|
+
let asset = self.audioList[audioId]
|
262
|
+
if asset != nil && asset is AudioAsset {
|
263
|
+
guard let audioAsset = asset as? AudioAsset else {
|
264
|
+
call.reject("Cannot cast to AudioAsset")
|
265
|
+
return
|
256
266
|
}
|
267
|
+
audioAsset.unload()
|
268
|
+
self.audioList[audioId] = nil
|
257
269
|
}
|
258
270
|
call.resolve()
|
259
271
|
}
|
@@ -295,109 +307,105 @@ public class NativeAudio: CAPPlugin, AVAudioPlayerDelegate {
|
|
295
307
|
let volume: Float?
|
296
308
|
let delay: Float?
|
297
309
|
var isLocalUrl: Bool = call.getBool("isUrl") ?? false
|
310
|
+
if audioId == "" {
|
311
|
+
call.reject(Constant.ErrorAssetId)
|
312
|
+
return
|
313
|
+
}
|
314
|
+
var assetPath: String = call.getString(Constant.AssetPathKey) ?? ""
|
315
|
+
|
316
|
+
if complex {
|
317
|
+
volume = call.getFloat("volume") ?? 1.0
|
318
|
+
channels = call.getInt("channels") ?? 1
|
319
|
+
delay = call.getFloat("delay") ?? 1.0
|
320
|
+
} else {
|
321
|
+
channels = 0
|
322
|
+
volume = 0
|
323
|
+
delay = 0
|
324
|
+
isLocalUrl = false
|
325
|
+
}
|
298
326
|
|
299
|
-
if
|
300
|
-
|
327
|
+
if audioList.isEmpty {
|
328
|
+
audioList = [:]
|
329
|
+
}
|
301
330
|
|
302
|
-
|
303
|
-
|
304
|
-
|
305
|
-
|
331
|
+
let asset = audioList[audioId]
|
332
|
+
let queue = DispatchQueue(label: "ee.forgr.audio.simple.queue", qos: .userInitiated)
|
333
|
+
if asset != nil {
|
334
|
+
call.reject(Constant.ErrorAssetAlreadyLoaded + " - " + audioId)
|
335
|
+
return
|
336
|
+
}
|
337
|
+
queue.async {
|
338
|
+
var basePath: String?
|
339
|
+
if let url = URL(string: assetPath), url.scheme != nil {
|
340
|
+
// Handle remote URL
|
341
|
+
let remoteAudioAsset = RemoteAudioAsset(owner: self, withAssetId: audioId, withPath: assetPath, withChannels: channels, withVolume: volume, withFadeDelay: delay)
|
342
|
+
self.audioList[audioId] = remoteAudioAsset
|
343
|
+
call.resolve()
|
344
|
+
return
|
345
|
+
} else if isLocalUrl == false {
|
346
|
+
// Handle public folder
|
347
|
+
// if assetPath doesnt start with public/ add it
|
348
|
+
assetPath = assetPath.starts(with: "public/") ? assetPath : "public/" + assetPath
|
349
|
+
|
350
|
+
let assetPathSplit = assetPath.components(separatedBy: ".")
|
351
|
+
basePath = Bundle.main.path(forResource: assetPathSplit[0], ofType: assetPathSplit[1])
|
306
352
|
} else {
|
307
|
-
|
308
|
-
|
309
|
-
|
310
|
-
isLocalUrl = false
|
311
|
-
}
|
312
|
-
|
313
|
-
if audioList.isEmpty {
|
314
|
-
audioList = [:]
|
353
|
+
// Handle local file URL
|
354
|
+
let fileURL = URL(fileURLWithPath: assetPath)
|
355
|
+
basePath = fileURL.path
|
315
356
|
}
|
316
357
|
|
317
|
-
let
|
318
|
-
|
319
|
-
|
320
|
-
|
321
|
-
|
322
|
-
|
323
|
-
// Handle remote URL
|
324
|
-
let remoteAudioAsset = RemoteAudioAsset(owner: self, withAssetId: audioId, withPath: assetPath, withChannels: channels, withVolume: volume, withFadeDelay: delay)
|
325
|
-
self.audioList[audioId] = remoteAudioAsset
|
326
|
-
call.resolve()
|
327
|
-
} else if isLocalUrl == false {
|
328
|
-
// Handle public folder
|
329
|
-
// if assetPath doesnt start with public/ add it
|
330
|
-
assetPath = assetPath.starts(with: "public/") ? assetPath : "public/" + assetPath
|
331
|
-
|
332
|
-
let assetPathSplit = assetPath.components(separatedBy: ".")
|
333
|
-
basePath = Bundle.main.path(forResource: assetPathSplit[0], ofType: assetPathSplit[1])
|
334
|
-
} else {
|
335
|
-
// Handle local file URL
|
336
|
-
let fileURL = URL(fileURLWithPath: assetPath)
|
337
|
-
basePath = fileURL.path
|
338
|
-
}
|
339
|
-
|
340
|
-
if let basePath = basePath, FileManager.default.fileExists(atPath: basePath) {
|
341
|
-
if !complex {
|
342
|
-
let soundFileUrl = URL(fileURLWithPath: basePath)
|
343
|
-
var soundId = SystemSoundID()
|
344
|
-
AudioServicesCreateSystemSoundID(soundFileUrl as CFURL, &soundId)
|
345
|
-
self.audioList[audioId] = NSNumber(value: Int32(soundId))
|
346
|
-
call.resolve()
|
347
|
-
} else {
|
348
|
-
let audioAsset = AudioAsset(
|
349
|
-
owner: self,
|
350
|
-
withAssetId: audioId, withPath: basePath, withChannels: channels,
|
351
|
-
withVolume: volume, withFadeDelay: delay)
|
352
|
-
self.audioList[audioId] = audioAsset
|
353
|
-
call.resolve()
|
354
|
-
}
|
355
|
-
} else {
|
356
|
-
if FileManager.default.fileExists(atPath: assetPath) {
|
357
|
-
// Use the original assetPath
|
358
|
-
if !complex {
|
359
|
-
let soundFileUrl = URL(fileURLWithPath: assetPath)
|
360
|
-
var soundId = SystemSoundID()
|
361
|
-
AudioServicesCreateSystemSoundID(soundFileUrl as CFURL, &soundId)
|
362
|
-
self.audioList[audioId] = NSNumber(value: Int32(soundId))
|
363
|
-
call.resolve()
|
364
|
-
} else {
|
365
|
-
let audioAsset = AudioAsset(
|
366
|
-
owner: self,
|
367
|
-
withAssetId: audioId, withPath: assetPath, withChannels: channels,
|
368
|
-
withVolume: volume, withFadeDelay: delay)
|
369
|
-
self.audioList[audioId] = audioAsset
|
370
|
-
call.resolve()
|
371
|
-
}
|
372
|
-
} else {
|
373
|
-
let attributes = try? FileManager.default.attributesOfItem(atPath: assetPath)
|
374
|
-
call.reject(Constant.ErrorAssetPath + " - " + assetPath)
|
375
|
-
}
|
376
|
-
}
|
358
|
+
if let basePath = basePath, FileManager.default.fileExists(atPath: basePath) {
|
359
|
+
if !complex {
|
360
|
+
let soundFileUrl = URL(fileURLWithPath: basePath)
|
361
|
+
var soundId = SystemSoundID()
|
362
|
+
AudioServicesCreateSystemSoundID(soundFileUrl as CFURL, &soundId)
|
363
|
+
self.audioList[audioId] = NSNumber(value: Int32(soundId))
|
377
364
|
} else {
|
378
|
-
|
365
|
+
let audioAsset = AudioAsset(
|
366
|
+
owner: self,
|
367
|
+
withAssetId: audioId, withPath: basePath, withChannels: channels,
|
368
|
+
withVolume: volume, withFadeDelay: delay)
|
369
|
+
self.audioList[audioId] = audioAsset
|
370
|
+
}
|
371
|
+
} else {
|
372
|
+
if !FileManager.default.fileExists(atPath: assetPath) {
|
373
|
+
call.reject(Constant.ErrorAssetPath + " - " + assetPath)
|
374
|
+
return
|
375
|
+
}
|
376
|
+
// Use the original assetPath
|
377
|
+
if !complex {
|
378
|
+
let soundFileUrl = URL(fileURLWithPath: assetPath)
|
379
|
+
var soundId = SystemSoundID()
|
380
|
+
AudioServicesCreateSystemSoundID(soundFileUrl as CFURL, &soundId)
|
381
|
+
self.audioList[audioId] = NSNumber(value: Int32(soundId))
|
382
|
+
} else {
|
383
|
+
let audioAsset = AudioAsset(
|
384
|
+
owner: self,
|
385
|
+
withAssetId: audioId, withPath: assetPath, withChannels: channels,
|
386
|
+
withVolume: volume, withFadeDelay: delay)
|
387
|
+
self.audioList[audioId] = audioAsset
|
379
388
|
}
|
380
389
|
}
|
390
|
+
call.resolve()
|
381
391
|
}
|
382
392
|
}
|
383
393
|
|
384
394
|
private func stopAudio(audioId: String) throws {
|
385
|
-
|
386
|
-
let asset = self.audioList[audioId]
|
395
|
+
let asset = self.audioList[audioId]
|
387
396
|
|
388
|
-
|
389
|
-
|
390
|
-
|
397
|
+
if asset == nil {
|
398
|
+
throw MyError.runtimeError(Constant.ErrorAssetNotFound)
|
399
|
+
}
|
400
|
+
if !(asset is AudioAsset) {
|
401
|
+
throw MyError.runtimeError(Constant.ErrorAssetNotFound)
|
402
|
+
}
|
403
|
+
let audioAsset = asset as? AudioAsset
|
391
404
|
|
392
|
-
|
393
|
-
|
394
|
-
|
395
|
-
|
396
|
-
}
|
397
|
-
}
|
398
|
-
} else {
|
399
|
-
throw MyError.runtimeError(Constant.ErrorAssetNotFound)
|
400
|
-
}
|
405
|
+
if self.fadeMusic {
|
406
|
+
audioAsset?.playWithFade(time: audioAsset?.getCurrentTime() ?? 0)
|
407
|
+
} else {
|
408
|
+
audioAsset?.stop()
|
401
409
|
}
|
402
410
|
}
|
403
411
|
}
|