播放详情页新增音频可视化功能

This commit is contained in:
lyswhut
2021-12-24 17:39:50 +08:00
parent dcfe055461
commit c2d6737796
11 changed files with 171 additions and 3 deletions
+14 -1
View File
@@ -1,5 +1,7 @@
let audio
let audioContext
let mediaSource
let analyser
export const createAudio = () => {
if (audio) return
window.audio = audio = new window.Audio()
@@ -8,6 +10,17 @@ export const createAudio = () => {
audio.preload = 'auto'
}
export const getAnalyser = () => {
if (audioContext == null) {
audioContext = new window.AudioContext()
mediaSource = audioContext.createMediaElementSource(audio)
analyser = audioContext.createAnalyser()
mediaSource.connect(analyser)
analyser.connect(audioContext.destination)
}
return analyser
}
export const setResource = src => {
if (audio) audio.src = src
}