album-player
Version:
an audio tracks player react component using the HTML 5 audio api
44 lines (43 loc) • 1.16 kB
TypeScript
interface AudioPlayerOpts {
onProgress: (n: number) => void;
onTrackEnd: () => void;
}
/**
* An interface to play audio files using the HTML5 audio object. This abstracts
* audio caching and stream so any user can simply access audio tracks using simple play
* and pause methods.
*/
export default class AudioPlayer {
private audio;
private cache;
private onProgress;
private onTrackEnd;
/**
* The AudioPlayer constructor
* @param props The audio player opts
*/
constructor(props: AudioPlayerOpts);
private handleProgress;
/**
* Asynchronously loads the audio file as an array buffer
* @param url The audio source url
*/
private load;
/**
* Plays the audio at the given url. The returned promise is only resolved when
* the audio has been loaded and can be played.
*
* @param url The audio url
*/
play(url: string): Promise<unknown>;
/**
* Pauses the currently playing audio.
*/
pause(): void;
/**
* Removes and event listeners to ensure that there are no
* memory leaks.
*/
destroy(): void;
}
export {};