feat: 支持Aplayer播放音乐的配置

This commit is contained in:
ykxkykx
2023-01-01 20:34:03 +08:00
parent 42586992b0
commit 0d0fb07eef
5 changed files with 66 additions and 0 deletions

View File

@@ -0,0 +1,7 @@
import dynamic from 'next/dynamic'
const MusicPlayer = dynamic(
() => import('@/components/Player'),
{ ssr: false }
)
export default MusicPlayer

33
components/Player.js Normal file
View File

@@ -0,0 +1,33 @@
import React from 'react'
import Aplayer from 'aplayer'
import BLOG from '@/blog.config'
const Player = () => {
const [player, setPlayer] = React.useState()
const ref = React.useRef(null)
React.useEffect(() => {
if (BLOG.MUSIC_PLAYER) {
setPlayer(new Aplayer({
container: ref.current,
fixed: true,
order: BLOG.MUSIC_PLAYER_ORDER,
autoplay: BLOG.MUSIC_PLAYER_AUTO_PLAY,
audio: BLOG.MUSIC_PLAYER_AUDIO_LIST
}))
}
return () => {
setPlayer(undefined)
}
}, [])
return (
<div
ref={ref}
data-player={player}
className={BLOG.MUSIC_PLAYER_VISIBLE ? 'visible' : 'invisible'}
/>
)
}
export default Player