@ohos-ports/dm-howler 2.2.4-beta.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,301 @@
1
+ // Type definitions for howler.js 2.2
2
+ // Project: https://github.com/goldfire/howler.js
3
+ // Definitions by: Pedro Casaubon <https://github.com/xperiments>
4
+ // Alexander Leon <https://github.com/alien35>
5
+ // Nicholas Higgins <https://github.com/nicholashza>
6
+ // Carlos Urango <https://github.com/cjurango>
7
+ // R.J. <https://github.com/jun-sheaf>
8
+ // Hagen <https://github.com/MrGriefs>
9
+ // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
10
+
11
+ export type HowlCallback = (soundId: number) => void;
12
+ export type HowlErrorCallback = (soundId: number, error: unknown) => void;
13
+ export type SpatialOrientation = [number, number, number];
14
+ export type SpatialPosition = [number, number, number];
15
+
16
+ export enum State {
17
+ Unloaded = 'unloaded',
18
+ Loading = 'loading',
19
+ Loaded = 'loaded',
20
+ }
21
+
22
+ export interface SoundSpriteDefinitions {
23
+ [name: string]: [number, number] | [number, number, boolean];
24
+ }
25
+
26
+ export interface PannerAttributes {
27
+ coneInnerAngle?: number | undefined;
28
+ coneOuterAngle?: number | undefined;
29
+ coneOuterGain?: number | undefined;
30
+ distanceModel?: 'inverse' | 'linear';
31
+ maxDistance?: number;
32
+ panningModel?: 'HRTF' | 'equalpower';
33
+ refDistance?: number;
34
+ rolloffFactor?: number;
35
+ }
36
+
37
+ export interface Sound {
38
+ (howl: Howl): this;
39
+ }
40
+
41
+ export interface HowlListeners {
42
+ /** Fires when the sound has been stopped. The first parameter is the ID of the sound. */
43
+ onstop?: HowlCallback | undefined;
44
+
45
+ /** Fires when the sound has been paused. The first parameter is the ID of the sound. */
46
+ onpause?: HowlCallback | undefined;
47
+
48
+ /** Fires when the sound is loaded. */
49
+ onload?: HowlCallback | undefined;
50
+
51
+ /** Fires when the sound has been muted/unmuted. The first parameter is the ID of the sound. */
52
+ onmute?: HowlCallback | undefined;
53
+
54
+ /** Fires when the sound's volume has changed. The first parameter is the ID of the sound. */
55
+ onvolume?: HowlCallback | undefined;
56
+
57
+ /** Fires when the sound's playback rate has changed. The first parameter is the ID of the sound. */
58
+ onrate?: HowlCallback | undefined;
59
+
60
+ /** Fires when the sound has been seeked. The first parameter is the ID of the sound. */
61
+ onseek?: HowlCallback | undefined;
62
+
63
+ /** Fires when the current sound finishes fading in/out. The first parameter is the ID of the sound. */
64
+ onfade?: HowlCallback | undefined;
65
+
66
+ /** Fires when audio has been automatically unlocked through a touch/click event. */
67
+ onunlock?: HowlCallback | undefined;
68
+
69
+ /**
70
+ * Fires when the sound finishes playing (if it is looping, it'll fire at the end of each loop).
71
+ * The first parameter is the ID of the sound.
72
+ */
73
+ onend?: HowlCallback | undefined;
74
+
75
+ /** Fires when the sound begins playing. The first parameter is the ID of the sound. */
76
+ onplay?: HowlCallback | undefined;
77
+
78
+ /**
79
+ * Fires when the sound is unable to load. The first parameter is the ID
80
+ * of the sound (if it exists) and the second is the error message/code.
81
+ */
82
+ onloaderror?: HowlErrorCallback | undefined;
83
+
84
+ /**
85
+ * Fires when the sound is unable to play. The first parameter is
86
+ * the ID of the sound and the second is the error message/code.
87
+ */
88
+ onplayerror?: HowlErrorCallback | undefined;
89
+ }
90
+
91
+ export interface HowlOptions extends HowlListeners {
92
+ /**
93
+ * The sources to the track(s) to be loaded for the sound (URLs or base64 data URIs). These should
94
+ * be in order of preference, howler.js will automatically load the first one that is compatible
95
+ * with the current browser. If your files have no extensions, you will need to explicitly specify
96
+ * the extension using the format property.
97
+ */
98
+ src: string | string[];
99
+
100
+ /**
101
+ * The volume of the specific track, from 0.0 to 1.0.
102
+ * @default 1.0
103
+ */
104
+ volume?: number | undefined;
105
+
106
+ /**
107
+ * Set to true to force HTML5 Audio. This should be used for large audio files so that you don't
108
+ * have to wait for the full file to be downloaded and decoded before playing.
109
+ * @default false
110
+ */
111
+ html5?: boolean | undefined;
112
+
113
+ /**
114
+ * Set to true to automatically loop the sound forever.
115
+ * @default false
116
+ */
117
+ loop?: boolean | undefined;
118
+
119
+ /**
120
+ * Automatically begin downloading the audio file when the Howl is defined. If using HTML5 Audio,
121
+ * you can set this to 'metadata' to only preload the file's metadata (to get its duration without
122
+ * download the entire file, for example).
123
+ * @default true
124
+ */
125
+ preload?: boolean | 'metadata' | undefined;
126
+
127
+ /**
128
+ * Set to true to automatically start playback when sound is loaded.
129
+ * @default false
130
+ */
131
+ autoplay?: boolean | undefined;
132
+
133
+ /**
134
+ * Set to true to load the audio muted.
135
+ * @default false
136
+ */
137
+ mute?: boolean | undefined;
138
+
139
+ /**
140
+ * Define a sound sprite for the sound. The offset and duration are defined in milliseconds. A
141
+ * third (optional) parameter is available to set a sprite as looping. An easy way to generate
142
+ * compatible sound sprites is with audiosprite.
143
+ */
144
+ sprite?: SoundSpriteDefinitions | undefined;
145
+
146
+ /**
147
+ * The rate of playback. 0.5 to 4.0, with 1.0 being normal speed.
148
+ * @default 1.0
149
+ */
150
+ rate?: number | undefined;
151
+
152
+ /**
153
+ * The size of the inactive sounds pool. Once sounds are stopped or finish playing, they are marked
154
+ * as ended and ready for cleanup. We keep a pool of these to recycle for improved performance.
155
+ * Generally this doesn't need to be changed. It is important to keep in mind that when a sound is
156
+ * paused, it won't be removed from the pool and will still be considered active so that it can be
157
+ * resumed later.
158
+ * @default 5
159
+ */
160
+ pool?: number | undefined;
161
+
162
+ /**
163
+ * howler.js automatically detects your file format from the extension, but you may also specify a
164
+ * format in situations where extraction won't work (such as with a SoundCloud stream).
165
+ */
166
+ format?: string | string[] | undefined;
167
+
168
+ /**
169
+ * When using Web Audio, howler.js uses an XHR request to load the audio files. If you need to send
170
+ * custom headers, set the HTTP method or enable withCredentials (see reference), include them with
171
+ * this parameter. Each is optional (method defaults to GET, headers default to null and
172
+ * withCredentials defaults to false).
173
+ */
174
+ xhr?:
175
+ | {
176
+ method?: string | undefined;
177
+ headers?: Record<string, string> | undefined;
178
+ withCredentials?: boolean | undefined;
179
+ }
180
+ | undefined;
181
+ }
182
+
183
+ export class Howl {
184
+ constructor(options: HowlOptions);
185
+
186
+ play(spriteOrId?: string | number): number; // .play() is not chainable; the other methods are
187
+ pause(id?: number): this;
188
+ stop(id?: number): this;
189
+
190
+ mute(): boolean;
191
+ mute(muted: boolean, id?: number): this;
192
+
193
+ volume(): number;
194
+ volume(idOrSetVolume: number): this | number;
195
+ volume(volume: number, id: number): this;
196
+
197
+ fade(from: number, to: number, duration: number, id?: number): this;
198
+
199
+ rate(id?: number): number;
200
+ rate(rate: number, id?: number): this;
201
+
202
+ seek(id?: number): number;
203
+ seek(seek: number, id?: number): this;
204
+
205
+ loop(id?: number): boolean;
206
+ loop(loop: boolean, id?: number): this;
207
+
208
+ playing(id?: number): boolean;
209
+ duration(id?: number): number;
210
+ state(): 'unloaded' | 'loading' | 'loaded';
211
+ load(): this;
212
+ unload(): null;
213
+
214
+ on(event: 'load', callback: () => void, id?: number): this;
215
+ on(event: 'loaderror' | 'playerror', callback: HowlErrorCallback, id?: number): this;
216
+ on(
217
+ event: 'play' | 'end' | 'pause' | 'stop' | 'mute' | 'volume' | 'rate' | 'seek' | 'fade' | 'unlock',
218
+ callback: HowlCallback,
219
+ id?: number,
220
+ ): this;
221
+ on(event: string, callback: HowlCallback | HowlErrorCallback, id?: number): this;
222
+
223
+ once(event: 'load', callback: () => void, id?: number): this;
224
+ once(event: 'loaderror' | 'playerror', callback: HowlErrorCallback, id?: number): this;
225
+ once(
226
+ event: 'play' | 'end' | 'pause' | 'stop' | 'mute' | 'volume' | 'rate' | 'seek' | 'fade' | 'unlock',
227
+ callback: HowlCallback,
228
+ id?: number,
229
+ ): this;
230
+ once(event: string, callback: HowlCallback | HowlErrorCallback, id?: number): this;
231
+
232
+ off(event: 'load', callback?: () => void, id?: number): this;
233
+ off(event: 'loaderror' | 'playerror', callback?: HowlErrorCallback, id?: number): this;
234
+ off(
235
+ event: 'play' | 'end' | 'pause' | 'stop' | 'mute' | 'volume' | 'rate' | 'seek' | 'fade' | 'unlock',
236
+ callback?: HowlCallback,
237
+ id?: number,
238
+ ): this;
239
+ // off() also supports passing id as second argument: internally it is type checked and treated as an id if it is a number
240
+ off(
241
+ event:
242
+ | 'load'
243
+ | 'loaderror'
244
+ | 'playerror'
245
+ | 'play'
246
+ | 'end'
247
+ | 'pause'
248
+ | 'stop'
249
+ | 'mute'
250
+ | 'volume'
251
+ | 'rate'
252
+ | 'seek'
253
+ | 'fade'
254
+ | 'unlock',
255
+ id: number,
256
+ ): this;
257
+ off(event?: string, callback?: HowlCallback | HowlErrorCallback, id?: number): this;
258
+
259
+ stereo(): number;
260
+ stereo(pan: number, id?: number): number | this;
261
+
262
+ pos(): SpatialPosition;
263
+ pos(x: number, y?: number, z?: number, id?: number): this;
264
+
265
+ orientation(): SpatialOrientation;
266
+ orientation(x: number, y?: number, z?: number, id?: number): this;
267
+
268
+ pannerAttr(id?: number): PannerAttributes;
269
+ pannerAttr(options: PannerAttributes, id?: number): this;
270
+ }
271
+
272
+ declare global {
273
+ class HowlerGlobal {
274
+ mute(muted: boolean): this;
275
+ stop(): this;
276
+
277
+ volume(): number;
278
+ volume(volume: number): this;
279
+
280
+ codecs(ext: string): boolean;
281
+ unload(): this;
282
+ usingWebAudio: boolean;
283
+ html5PoolSize: number;
284
+ noAudio: boolean;
285
+ autoUnlock: boolean;
286
+ autoSuspend: boolean;
287
+ ctx: AudioContext;
288
+ masterGain: GainNode;
289
+
290
+ stereo(pan: number): this;
291
+
292
+ pos(): SpatialPosition;
293
+ pos(x: number, y?: number, z?: number): this;
294
+
295
+ orientation(): SpatialOrientation;
296
+ orientation(x: number, y?: number, z?: number, xUp?: number, yUp?: number, zUp?: number): this;
297
+ }
298
+ const Howler: HowlerGlobal;
299
+ }
300
+
301
+ export const Howler: HowlerGlobal;