music-visualization-canvas
Version:
50 lines (49 loc) • 1.26 kB
TypeScript
/// <reference types="resize-observer-browser" />
declare type AudioEventMap = {
[K in keyof HTMLMediaElementEventMap]: (this: HTMLAudioElement, ev: HTMLMediaElementEventMap[K]) => any;
};
export interface Options {
src: string;
el?: HTMLElement;
minHeight?: number;
gap?: number;
audioEvents?: Partial<AudioEventMap>;
}
declare class MusicVisualization {
options: Required<Options>;
container: HTMLDivElement;
audio: HTMLAudioElement;
analyser: AnalyserNode | null;
canvas: HTMLCanvasElement;
canvasCtx: CanvasRenderingContext2D;
drawRafId: number | null;
objectUrl: string;
resizeObserver: ResizeObserver;
constructor(options: Options);
start(): Promise<void> | undefined;
stop(): void;
destroy(): void;
changeMusic(file: any): void;
/**
* 创建canvas
*/
private createCanvas;
/**
* 创建audio
*/
private createAudio;
/**
* 创建auido 分析器
* @param audio
*/
private createAnalyser;
/**
* 画曲线
* @param param0
*/
private drawCurveLine;
private drawGraph;
private drawLine;
private draw;
}
export default MusicVisualization;