-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexample.js
100 lines (80 loc) · 2.76 KB
/
example.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
window.addEventListener('DOMContentLoaded', () => {
'use strict';
const AudioVisualizer = AudioVisualizeTool.AudioVisualizer;
const {
Ripple
} = AudioVisualizeTool.defaultElements;
const {
renderTime,
renderInfo,
renderLoading,
clearLoading,
renderBackgroundImg,
renderLounge,
renderProgressbar,
renderProgressbarShadow,
renderSeekBar,
renderSeekBarShadow,
bindSeekBarEvent,
renderPlayControl,
bindPlayControlEvent,
renderVolumeBar,
bindVolumeBarEvent
} = AudioVisualizeTool.defaultRenderHooks;
const {
setCanvasStyle,
setStaticCanvasStyle
} = AudioVisualizeTool.defaultInitHooks;
let ripple = new Ripple();
let audioVisualizer = new AudioVisualizer({
autoplay: false,
loop: true,
initVolume: 0.5, // 0 to 1;
// the frequency sample size for audio analyzer
// Must be a power of 2 between 25 and 215, like 32, 64, 128, 256, 512, 1024, 2048,
// Defaults to 512.
fftSize: 512,
// the refresh rate for rendering canvas (not static canvas)
framesPerSecond: 60,
audio: 'myAudio',
canvas: 'myCanvas', // main canvas for rendering frames
canvasStatic: 'myStaticCanvas', // static canvas
customCanvases: [], // you can add your own canvases
// customize your theme
theme: {
barWidth: 2,
barHeight: 5,
barSpacing: 7,
barColor: '#ffffff',
shadowBlur: 20, // avoid this attribute for rendering frames, it can reduce the performance
shadowColor: '#444',
font: ['12px', 'Helvetica'],
},
// hooks contain callbacks just before/after differency lifecycle stage
// cb in before hooks should return promises
beforeInitHook: [],
afterInitHook: [setCanvasStyle, setStaticCanvasStyle],
beforeLoadAudioHook: [renderLoading],
afterLoadAudioHook: [clearLoading, renderPlayControl],
beforeStartHook: [],
afterStartHook: [],
beforePauseHook: [],
afterPauseHook: [renderProgressbar, renderTime, renderSeekBar, renderPlayControl],
beforeResumeHook: [],
afterResumeHook: [],
// you can react to volume change here
onVolumeChangeHook: [renderVolumeBar],
// hook for static canvas
beforeStaticHook: [renderBackgroundImg],
onStaticHook: [renderProgressbarShadow, renderInfo, renderSeekBarShadow, renderVolumeBar],
// hooks that will be excuted for each frame
// used for the main canvas
onFrameHook: [renderLounge, renderProgressbar, renderTime, renderSeekBar, ripple.render()],
// you may bind your events here
onEventHook: [bindPlayControlEvent, bindSeekBarEvent, bindVolumeBarEvent],
// you may release some resourse here
// if loop is ture this hook will not be excuted
onEndHook: [],
})
audioVisualizer.init();
}, false);