Merge pull request #12631 from WatchBeam/feature/howler-2.0.0

Update Howler to 2.0.0
This commit is contained in:
Andy
2016-11-15 12:39:23 -08:00
committed by GitHub
2 changed files with 120 additions and 65 deletions
+33 -12
View File
@@ -1,19 +1,13 @@
/**
* howler-tests.ts
* Created by xperiments on 02/09/14.
*/
import * as howler from "howler";
Howler.codecs('ogg');
Howler.iOSAutoEnable = true;
var sound = new Howl({
urls: ['sound.mp3']
}).play();
src: ['sound.mp3']
});
sound.play();
var sound = new Howl({
urls: ['sound.mp3', 'sound.ogg', 'sound.wav'],
src: ['sound.webm', 'sound.mp3', 'sound.wav'],
autoplay: true,
loop: true,
volume: 0.5,
@@ -23,7 +17,7 @@ var sound = new Howl({
});
var sound = new Howl({
urls: ['sounds.mp3', 'sounds.ogg'],
src: ['sounds.webm', 'sounds.mp3'],
sprite: {
blast: [0, 1000],
laser: [2000, 3000],
@@ -31,5 +25,32 @@ var sound = new Howl({
}
});
// shoot the laser!
// Shoot the laser!
sound.play('laser');
var sound = new Howl({
src: ['sound.webm', 'sound.mp3']
});
// Clear listener after first call.
sound.once('load', function(){
sound.play();
});
// Fires when the sound finishes playing.
sound.on('end', function(){
console.log('Finished!');
});
var sound = new Howl({
src: ['sound.webm', 'sound.mp3']
});
// Play returns a uniqe Sound ID that can be passed
// into any method on Howl to control that specific sound.
var id1 = sound.play();
var id2 = sound.play();
// Fade out the first sound and speed up the second.
sound.fade(1, 0, 1000, id1);
sound.rate(1.5, id2);
+87 -53
View File
@@ -1,73 +1,107 @@
// Type definitions for howler.js v1.1.29
// Type definitions for howler.js v2.0.0
// Project: https://github.com/goldfire/howler.js
// Definitions by: Pedro Casaubon <https://github.com/xperiments/>
// Definitions by: Pedro Casaubon <https://github.com/xperiments/>, Todd Dukart <https://github.com/tdukart/>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
declare class HowlerGlobal {
mute(muted: boolean): HowlerGlobal;
interface HowlerGlobal {
mute(muted: boolean): void;
volume(): number;
volume(volume: number): HowlerGlobal;
codecs(extension: string): boolean;
iOSAutoEnable: boolean;
volume(volume: number): this;
codecs(ext: string): boolean;
unload(): void;
usingWebAudio: boolean;
noAudio: boolean;
mobileAudioEnable: boolean;
autoSuspend: boolean;
ctx: AudioContext;
masterGain: GainNode;
}
declare var Howler: HowlerGlobal;
declare let Howler: HowlerGlobal;
interface IHowlSoundSpriteDefinition {
[name: string]: number[];
[name: string]: [number, number]|[number, number, boolean]
}
declare type HowlPos3d = [number, number, number]|[number, number, number, number];
interface IHowlProperties {
autoplay?: boolean;
buffer?: boolean;
duration?: number;
format?: string;
loop?: boolean;
sprite?: IHowlSoundSpriteDefinition;
src?: string;
pos3d?: HowlPos3d;
src: string|string[];
volume?: number;
urls?: string[];
html5?: boolean;
loop?: boolean;
preload?: boolean;
autoplay?: boolean;
mute?: boolean;
sprite?: IHowlSoundSpriteDefinition;
rate?: number;
model?: 'equalpower'|'HRTF';
onend?: Function;
onload?: Function;
onloaderror?: Function;
onpause?: Function;
onplay?: Function;
pool?: number;
format?: string[] | string;
onload?: () => void;
onloaderror?: (soundId: number, error: any) => void;
onplay?: (soundId: number) => void;
onend?: (soundId: number) => void;
onpause?: (soundId: number) => void;
onstop?: (soundId: number) => void;
onmute?: (soundId: number) => void;
onvolume?: (soundId: number) => void;
onrate?: (soundId: number) => void;
onseek?: (soundId: number) => void;
onfade?: (soundId: number) => void;
}
interface Howl {
autoplay: Boolean;
buffer: Boolean;
format: string;
rate: number;
model: string;
onend: Function;
onload: Function;
onloaderror: Function;
onpause: Function;
onplay: Function;
load(): Howl;
play(sprite?: string, callback?: (soundId: string) => void): Howl;
play(callback?: (soundId: string) => void): Howl;
pause(soundId?: string): Howl;
stop(soundId?: string): Howl;
mute(muted?: boolean, soundId?: string): Howl;
fade(from: number, to: number, duration: number, callback?: Function, soundId?: string): Howl;
loop(): boolean;
loop(loop: boolean): Howl;
pos(position?: number, soundId?: string): number;
pos3d(x: number, y: number, z: number, soundId?: string): any;
sprite(definition?: IHowlSoundSpriteDefinition): IHowlSoundSpriteDefinition;
play(spriteOrId?: string|number): number; // .play() is not chainable; the other methods are
pause(id?: number): this;
stop(id?: number): this;
mute(): boolean;
mute(muted: boolean, id?: number): this;
volume(): number;
volume(volume?: number, soundId?: string): Howl;
urls(): string[];
urls(urls: string[]): Howl;
on(event: string, listener?: Function): Howl;
off(event: string, listener?: Function): Howl;
volume(idOrSetVolume: number): this | number;
volume(volume: number, id: number): this;
fade(from: number, to: number, duration: number, id?: number): this;
rate(): number;
rate(idOrSetRate: number): this | number;
rate(rate: number, id: number): this;
seek(seek?: number, id?: number): this;
loop(loop?: boolean, id?: number): this;
playing(id?: number): boolean;
duration(id?: number): number;
on(event: 'load', callback: () => void, id?: number): this;
on(event: 'loaderror', callback: (soundId: number, error: any) => void, id?: number): this;
on(event: 'play', callback: (soundId: number) => void, id?: number): this;
on(event: 'end', callback: (soundId: number) => void, id?: number): this;
on(event: 'pause', callback: (soundId: number) => void, id?: number): this;
on(event: 'stop', callback: (soundId: number) => void, id?: number): this;
on(event: 'mute', callback: (soundId: number) => void, id?: number): this;
on(event: 'volume', callback: (soundId: number) => void, id?: number): this;
on(event: 'rate', callback: (soundId: number) => void, id?: number): this;
on(event: 'seek', callback: (soundId: number) => void, id?: number): this;
on(event: 'fade', callback: (soundId: number) => void, id?: number): this;
on(event: string, callback: Function, id?: number): this;
once(event: 'load', callback: () => void, id?: number): this;
once(event: 'loaderror', callback: (soundId: number, error: any) => void, id?: number): this;
once(event: 'play', callback: (soundId: number) => void, id?: number): this;
once(event: 'end', callback: (soundId: number) => void, id?: number): this;
once(event: 'pause', callback: (soundId: number) => void, id?: number): this;
once(event: 'stop', callback: (soundId: number) => void, id?: number): this;
once(event: 'mute', callback: (soundId: number) => void, id?: number): this;
once(event: 'volume', callback: (soundId: number) => void, id?: number): this;
once(event: 'rate', callback: (soundId: number) => void, id?: number): this;
once(event: 'seek', callback: (soundId: number) => void, id?: number): this;
once(event: 'fade', callback: (soundId: number) => void, id?: number): this;
once(event: string, callback: Function, id?: number): this;
off(event: string, callback?: Function, id?: number): this;
state(): 'unloaded' | 'loading' | 'loaded';
load(): void;
unload(): void;
}