import { siteConfig } from '@/lib/config' import { loadExternalResource } from '@/lib/utils' import { useEffect, useRef, useState } from 'react' /** * 音乐播放器 * @returns */ const Player = () => { const [player, setPlayer] = useState() const ref = useRef(null) const lrcType = JSON.parse(siteConfig('MUSIC_PLAYER_LRC_TYPE')) const playerVisible = JSON.parse(siteConfig('MUSIC_PLAYER_VISIBLE')) const autoPlay = JSON.parse(siteConfig('MUSIC_PLAYER_AUTO_PLAY')) const meting = JSON.parse(siteConfig('MUSIC_PLAYER_METING')) const order = siteConfig('MUSIC_PLAYER_ORDER') const audio = siteConfig('MUSIC_PLAYER_AUDIO_LIST') const musicPlayerEnable = siteConfig('MUSIC_PLAYER') const musicPlayerCDN = siteConfig('MUSIC_PLAYER_CDN_URL') const musicMetingEnable = siteConfig('MUSIC_PLAYER_METING') const musicMetingCDNUrl = siteConfig('MUSIC_PLAYER_METING_CDN_URL', 'https://cdnjs.cloudflare.com/ajax/libs/meting/2.0.1/Meting.min.js') const initMusicPlayer = async () => { if (!musicPlayerEnable) { return } try { await loadExternalResource(musicPlayerCDN, 'js') } catch (error) { console.error('音乐组件异常', error) } if (musicMetingEnable) { await loadExternalResource(musicMetingCDNUrl, 'js') } if (!meting && window.APlayer) { setPlayer(new window.APlayer({ container: ref.current, fixed: true, lrcType: lrcType, autoplay: autoPlay, order: order, audio: audio })) } } useEffect(() => { initMusicPlayer() return () => { setPlayer(undefined) } }, []) return (