react-hifi
Version:
A set of react components wich provides simple abstraption to manipulate HTML5 AudioContext API (Equalizer, visualisation, stereo, basic controls)
77 lines (76 loc) • 2.46 kB
TypeScript
import React, { ReactElement } from 'react';
declare enum SoundStatus {
PAUSED = "PAUSED",
PLAYING = "PLAYING",
STOPPED = "STOPPED"
}
export declare enum SoundErrors {
MEDIA_ERR_ABORTED = "Video playback aborted by the user.",
MEDIA_ERR_NETWORK = "A network error caused the audio download to fail.",
MEDIA_ERR_DECODE = "The audio playback was aborted due to a corruption problem.",
MEDIA_ERR_SRC_NOT_SUPPORTED = "The audio playback can not be loaded, either because the server or network failed or because the format is not supported.",
UNKNOWN = "An unknown error occurred during audio playback loading."
}
interface Stream {
type: string;
url: string;
}
declare type OnPlayingArgs = {
position: number;
duration: number;
};
/**
* Sound Props
*/
export interface SoundProps {
/** the url of the stream to play */
url: string | Stream[];
/** PLAYING, PAUSED or STOPPED */
playStatus?: SoundStatus;
/** the position in second */
position?: number;
/** onTimeUpdate handler */
onPlaying?: (args: OnPlayingArgs) => void;
/** trigger when the sound is over */
onFinishedPlaying?: (event: any) => void;
/** trigger when the load start */
onLoading?: (event: any) => void;
/** trigger when the file is ready to play */
onLoad?: (event: any) => void;
/** trigger when an error is thrown */
onError?: (error: Error) => void;
children?: ReactElement[] | ReactElement;
}
export interface SoundState {
/** html5 AudioContext instance */
audioContext: AudioContext;
/** the AudioNode register by childrens */
audioNodes: AudioNode[];
}
/**
* Sound Component
*/
export declare class Sound extends React.Component<SoundProps, SoundState> {
private audio;
private source;
state: SoundState;
static status: typeof SoundStatus;
constructor(props: SoundProps);
private attachRef;
private renderPlugins;
private handleRegisterPlugin;
private handleTimeUpdate;
private setPlayerState;
private shouldUpdatePosition;
private setPosition;
private play;
private pause;
private stop;
private handleError;
componentDidUpdate(prevProps: SoundProps): void;
componentDidMount(): void;
componentWillUnmount(): void;
componentDidCatch(err: Error): void;
render(): JSX.Element;
}
export {};