mirror of
https://github.com/d0zingcat/NotionNext.git
synced 2026-05-18 15:09:34 +00:00
feat: 支持Aplayer播放音乐的配置
This commit is contained in:
7
components/MusicPlayer.js
Normal file
7
components/MusicPlayer.js
Normal 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
33
components/Player.js
Normal 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
|
||||
Reference in New Issue
Block a user