醉美水芙蓉 发表于 7 天前

马黑黑AudioPlayer插件源码

<span class="atips_close" onclick="this.parentNode.style.display='none'"></span>
</div>
<div class="blockcode"><div id="code_DzS"><ol><li>/** audioplayer.js(2026年5月5日更新)<br />
<li><br />
<li>&nbsp; &nbsp; 在指定父元素生成播放器+全屏按钮,<br />
<li>&nbsp; &nbsp; 支持添加多个自定义音频控制按钮,<br />
<li>&nbsp; &nbsp; 支持热键操作(F11、Alt+X/N/P/L)<br />
<li><br />
<li>&nbsp; &nbsp; 1. 前台配置:<br />
<li>&nbsp; &nbsp; let option = {<br />
<li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;pa: '.pa'; // 或者 '#pa' | pa<br />
<li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;urls: [<br />
<li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;['歌曲地址1', '曲名1'],<br />
<li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;['歌曲地址2', '曲名2'],<br />
<li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;],<br />
<li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;fs: false, // 禁用全屏按钮,缺省值 true(启用)<br />
<li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;btns: , // 自定义播放控制器(若需要)<br />
<li>&nbsp; &nbsp; }<br />
<li><br />
<li>&nbsp; &nbsp; 2. 实例化举例:const aud = new AudPlayer(option);<br />
<li><br />
<li>&nbsp; &nbsp; 3. 前台CSS:<br />
<li>&nbsp; &nbsp; ① 播 放 器: .player { width: 420px; bottom: 10px; right: 20px; color: gold; }<br />
<li>&nbsp; &nbsp; ② 全屏按钮: .btnFs { top: 20px; right: 20px; color: gold; }<br />
<li>*/<br />
<li>class AudPlayer {<br />
<li>&nbsp; &nbsp; constructor(config = {}) {<br />
<li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;// 基础配置<br />
<li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;this.config = {<br />
<li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;pa: config.pa || document.body,<br />
<li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;urls: config.urls || [],<br />
<li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;fs: true,<br />
<li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;btns: config.btns,<br />
<li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;};<br />
<li><br />
<li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;// 关键DOM+核心状态<br />
<li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;this.pa = this.getParentElement();<br />
<li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;this.aud = new Audio();<br />
<li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;this.fs_btn = null;<br />
<li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;this.playList = [...this.config.urls]; // 原始歌单<br />
<li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;this.randomQueue = []; // 随机播放队列<br />
<li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;this.currentIndex = 0; // 当前播放索引<br />
<li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;this.isPlaying = false;<br />
<li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;this.isSingle = this.playList.length === 1;<br />
<li><br />
<li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;// 初始化<br />
<li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;this.generateUI();<br />
<li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;this.initRandomQueue();<br />
<li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;this.placeMList();<br />
<li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;this.displayPlayer();<br />
<li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;this.bindAudEvents();<br />
<li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;this.playFirst();<br />
<li>&nbsp; &nbsp; }<br />
<li><br />
<li>&nbsp; &nbsp; // 加载+播放曲目<br />
<li>&nbsp; &nbsp; loadTrack(index) {<br />
<li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;if (index &lt; 0 || index &gt;= this.playList.length) return;<br />
<li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;this.currentIndex = index;<br />
<li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;const = this.playList;<br />
<li><br />
<li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;this.aud.src = url;<br />
<li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;this.aud.play().catch(err =&gt; this.showError('自动播放受限,请点击播放按钮'));<br />
<li><br />
<li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;// 歌单高亮+翻页<br />
<li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;if (!this.isSingle) {<br />
<li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;this.mlist.dataset.currentsong = '正在播放 :' + title;<br />
<li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;const lists = this.mlist.querySelectorAll('li');<br />
<li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;const curList = this.mlist.querySelector(`li`);<br />
<li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;lists.forEach(li =&gt; li.classList.remove('list-highlight'));<br />
<li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;curList.classList.add('list-highlight');<br />
<li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;curList.scrollIntoView({ behavior: 'smooth'});<br />
<li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;console.log(this.mlist.scrollHeight, curList.offsetTop)<br />
<li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;}<br />
<li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;this.mState();<br />
<li>&nbsp; &nbsp; }<br />
<li><br />
<li>&nbsp; &nbsp; // 首次播放<br />
<li>&nbsp; &nbsp; playFirst() {<br />
<li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;const idx = Math.floor(Math.random() * this.playList.length);<br />
<li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;this.loadTrack(idx);<br />
<li>&nbsp; &nbsp; }<br />
<li><br />
<li>&nbsp; &nbsp; // 手动选曲(不影响随机队列)<br />
<li>&nbsp; &nbsp; selectTrack(index) {<br />
<li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;this.loadTrack(index);<br />
<li>&nbsp; &nbsp; }<br />
<li><br />
<li>&nbsp; &nbsp; // 上一首<br />
<li>&nbsp; &nbsp; playPrev() {<br />
<li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;if (this.isSingle) return;<br />
<li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;let prevIndex = this.currentIndex - 1;<br />
<li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;if (prevIndex &lt; 0) prevIndex = this.playList.length - 1;<br />
<li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;this.loadTrack(prevIndex);<br />
<li>&nbsp; &nbsp; }<br />
<li><br />
<li>&nbsp; &nbsp; // 下一首<br />
<li>&nbsp; &nbsp; playNext() {<br />
<li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;if (this.isSingle) return;<br />
<li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;let nextIndex = this.currentIndex + 1;<br />
<li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;if (nextIndex &gt;= this.playList.length) nextIndex = 0;<br />
<li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;this.loadTrack(nextIndex);<br />
<li>&nbsp; &nbsp; }<br />
<li><br />
<li>&nbsp; &nbsp; // 切换播放/暂停<br />
<li>&nbsp; &nbsp; togglePlay() {<br />
<li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;if (this.isPlaying) {<br />
<li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;this.aud.pause();<br />
<li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;} else {<br />
<li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;this.aud.play().catch(err =&gt; this.showError('播放失败,请检查音频链接'));<br />
<li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;}<br />
<li>&nbsp; &nbsp; }<br />
<li><br />
<li>&nbsp; &nbsp; // 按钮、视频等状态维护<br />
<li>&nbsp; &nbsp; mState() {<br />
<li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;const vids = this.pa.querySelectorAll('video');<br />
<li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;if (this.aud.paused) {<br />
<li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;this.playbtn.classList.remove('clip-pause');<br />
<li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;this.playbtn.classList.add('clip-play');<br />
<li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;this.pa.style.setProperty('--state', 'paused');<br />
<li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;if (vids) vids.forEach(vid =&gt; vid.pause());<br />
<li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;} else {<br />
<li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;this.playbtn.classList.remove('clip-play');<br />
<li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;this.playbtn.classList.add('clip-pause');<br />
<li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;this.pa.style.setProperty('--state', 'running');<br />
<li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;if (vids) vids.forEach(vid =&gt; vid.play());<br />
<li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;}<br />
<li>&nbsp; &nbsp; }<br />
<li><br />
<li>&nbsp; &nbsp; // 播放结束处理<br />
<li>&nbsp; &nbsp; handlePlayEnd() {<br />
<li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;if (this.isSingle) {<br />
<li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;// 单曲循环<br />
<li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;this.aud.currentTime = 0;<br />
<li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;this.aud.play();<br />
<li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;} else {<br />
<li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;// 多曲:从随机队列取歌<br />
<li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;if (this.randomQueue.length === 0) {<br />
<li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; this.resetRandomQueue(); // 周期结束,重置随机队列<br />
<li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;}<br />
<li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;const nextTrack = this.randomQueue.shift();<br />
<li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;const nextIndex = this.playList.findIndex(item =&gt; item === nextTrack);<br />
<li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;this.loadTrack(nextIndex);<br />
<li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;}<br />
<li>&nbsp; &nbsp; }<br />
<li><br />
<li>&nbsp; &nbsp; // 初始化随机播放队列<br />
<li>&nbsp; &nbsp; initRandomQueue() {<br />
<li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;if (this.isSingle) return;<br />
<li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;this.randomQueue = [...this.playList].sort(() =&gt; Math.random() - 0.5);<br />
<li>&nbsp; &nbsp; }<br />
<li><br />
<li>&nbsp; &nbsp; // 重置随机队列(一个周期结束后)<br />
<li>&nbsp; &nbsp; resetRandomQueue() {<br />
<li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;this.initRandomQueue();<br />
<li>&nbsp; &nbsp; }<br />
<li><br />
<li>&nbsp; &nbsp; // 音频事件绑定<br />
<li>&nbsp; &nbsp; bindAudEvents() {<br />
<li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;// 时间更新<br />
<li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;this.aud.addEventListener('timeupdate', () =&gt; {<br />
<li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;const { currentTime, duration } = this.aud;<br />
<li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;this.prog.style.setProperty('--prog',&nbsp;&nbsp;`${currentTime / duration * 100}%`);<br />
<li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;this.tmsg.textContent = `${this.s2m(currentTime)} / ${this.s2m(duration)}`;<br />
<li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;});<br />
<li><br />
<li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;// 播放结束<br />
<li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;this.aud.addEventListener('ended', () =&gt; {<br />
<li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;this.handlePlayEnd();<br />
<li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;});<br />
<li><br />
<li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;// 播放/暂停状态同步<br />
<li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;this.aud.addEventListener('play', () =&gt; {<br />
<li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;this.isPlaying = true;<br />
<li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;this.mState();<br />
<li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;});<br />
<li><br />
<li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;// 暂停<br />
<li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;this.aud.addEventListener('pause', () =&gt; {<br />
<li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;this.isPlaying = false;<br />
<li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;this.mState();<br />
<li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;});<br />
<li><br />
<li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;// 出错<br />
<li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;this.aud.addEventListener('error', (e) =&gt; {<br />
<li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;this.showError(`播放失败:${this.playList}`);<br />
<li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;this.handlePlayEnd();<br />
<li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;});<br />
<li>&nbsp; &nbsp; }<br />
<li><br />
<li>&nbsp; &nbsp; // 创建UI<br />
<li>&nbsp; &nbsp; generateUI() {<br />
<li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;if (document.querySelector('#audio-player-style')) return;<br />
<li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;const style = document.createElement('style');<br />
<li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;style.id = 'audio-player-style';<br />
<li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;style.textContent = [<br />
<li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;`.player { position: absolute; padding: 6px; width: 460px; height: 40px; line-height: 40px; display: flex; align-items: center; gap: 10px; transition: .75s; opacity: var(--opacity); }`,<br />
<li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;`.player * { box-sizing: border-box; }`,<br />
<li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;`.aud-btn { width: 35px; height: 35px; border: 1px solid currentColor; border-radius: 50%; cursor: pointer; position: relative; display: grid; place-items: center; }`,<br />
<li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;`.aud-btn:hover { background: rgba(0,0,0,.25); }`,<br />
<li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;`.aud-btn::before { content: ''; position: absolute; width: 50%; height: 50%; background: currentColor; clip-path: var(--clip-path); }`,<br />
<li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;`.aud-prog { flex-grow: 1; height: 12px; background: linear-gradient(to right, currentColor var(--prog), transparent var(--prog), transparent 0); border: 1px solid currentColor; border-radius: 12px; cursor: pointer; --prog: 0%; }`,<br />
<li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;`.common-btn { width: 26px; height: 26px; border: 1px solid currentColor; border-radius: 6px; padding: 0; font: normal 16px/26px sans-serif; text-align: center; user-select: none; cursor: pointer; }`,<br />
<li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;`.common-btn:hover { background: rgba(0,0,0,.25); }`,<br />
<li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;`.music-list { position: absolute; left: 50%; transform: translateX(-50%); width: 100%; max-width: 460px; min-height: 100%; height: 232px; border-radius: 6px; background: rgba(0,0,0,.25); box-shadow: 3px 3px 6px gray; display: none; }`,<br />
<li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;`.music-list::before { position: sticky; content: attr(data-currentsong); font-weight: bold; padding: 5px 15px;}`,<br />
<li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;`.music-list ol { height: 160px; overflow: auto; scrollbar-width: thin; scrollbar-color: currentColor transparent; }`,<br />
<li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;`.music-list ol li span { cursor: pointer; }`,<br />
<li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;`.music-list ol li span:hover { opacity: .75; }`,<br />
<li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;`.aud-tmsg { user-select: none; cursor: default; }`,<br />
<li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;`.clip-play { --clip-path: polygon(0 0, 0 100%, 100% 50%);}`,<br />
<li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;`.clip-pause { --clip-path: polygon(45% 0, 45% 100%, 10% 100%, 10% 0, 90% 0, 90% 100%, 55% 100%, 55% 0); }`,<br />
<li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;`.list-highlight { color: red; }`,<br />
<li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;`.btnFs { position: absolute; padding: 6px 12px; border: 3px solid currentColor; border-radius: 12px; font-size: 1.2em; color: currentColor; background: rgba(0,0,0,.25); transition: .75s; opacity: var(--opacity); user-select: none; cursor: pointer; }`,<br />
<li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;`.btnFs:hover { font-weight: bold; }`,<br />
<li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;].join('');<br />
<li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;document.head.appendChild(style);<br />
<li><br />
<li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;// 播放器容器<br />
<li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;this.player = document.createElement('div');<br />
<li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;this.player.classList.add('player');<br />
<li><br />
<li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;// 前一首按钮<br />
<li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;if (!this.isSingle) {<br />
<li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;const btnPrev = document.createElement('div');<br />
<li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;btnPrev.classList.add('common-btn');<br />
<li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;btnPrev.textContent = '←';<br />
<li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;btnPrev.title = '前一首(Alt+P)';<br />
<li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;btnPrev.addEventListener('click', () =&gt; this.playPrev());<br />
<li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;this.player.appendChild(btnPrev);<br />
<li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;}<br />
<li><br />
<li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;// 播放|暂停按钮<br />
<li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;this.playbtn = document.createElement('div');<br />
<li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;this.playbtn.classList.add('aud-btn', 'clip-pause');<br />
<li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;this.playbtn.title = '播放/暂停(Alt+X)';<br />
<li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;this.playbtn.addEventListener('click', () =&gt; this.togglePlay());<br />
<li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;this.player.appendChild(this.playbtn);<br />
<li><br />
<li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;// 下一首按钮<br />
<li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;if (!this.isSingle) {<br />
<li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;const btnNext = document.createElement('div');<br />
<li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;btnNext.classList.add('common-btn');<br />
<li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;btnNext.textContent = '→';<br />
<li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;btnNext.title = '下一首(Alt+N)';<br />
<li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;btnNext.addEventListener('click', () =&gt; this.playNext());<br />
<li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;this.player.appendChild(btnNext);<br />
<li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;}<br />
<li><br />
<li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;// 进度条<br />
<li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;this.prog = document.createElement('div');<br />
<li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;this.prog.classList.add('aud-prog');<br />
<li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;this.prog.addEventListener('click', (e) =&gt; {<br />
<li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;const duration = this.aud.duration;<br />
<li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;if (isNaN(duration)) return;<br />
<li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;this.aud.currentTime = duration * e.offsetX / this.prog.offsetWidth;<br />
<li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;});<br />
<li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;this.prog.addEventListener('mousemove', (e) =&gt; {<br />
<li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;const duration = this.aud.duration;<br />
<li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;this.prog.title = this.s2m(duration * e.offsetX / this.prog.offsetWidth);<br />
<li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;});<br />
<li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;this.player.appendChild(this.prog);<br />
<li><br />
<li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;// 数字时间<br />
<li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;this.tmsg = document.createElement('div');<br />
<li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;this.tmsg.classList.add('aud-tmsg');<br />
<li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;this.tmsg.textContent = '00:00 / 00:00';<br />
<li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;this.player.appendChild(this.tmsg);<br />
<li><br />
<li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;// 列表控制按钮<br />
<li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;if (!this.isSingle) {<br />
<li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;this.listControl = document.createElement('div');<br />
<li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;this.listControl.classList.add('common-btn');<br />
<li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;this.listControl.textContent = '▼';<br />
<li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;this.listControl.title = '音乐列表(Alt+L)';<br />
<li><br />
<li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;// 列表弹出/收起+按钮箭头变换<br />
<li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;this.listControl.addEventListener('click', () =&gt; {<br />
<li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;let hide = this.mlist.style.display === 'block';<br />
<li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;this.mlist.style.display = hide ? 'none' : 'block';<br />
<li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;this.listControl.textContent = this.listControl.textContent === '▲' ? '▼' : '▲';<br />
<li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;if (!hide) {<br />
<li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; this.mlist.querySelector(`li`).scrollIntoView({behavior: 'smooth'});<br />
<li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;}<br />
<li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;});<br />
<li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;this.player.appendChild(this.listControl);<br />
<li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;// 音乐列表<br />
<li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;this.mlist = document.createElement('div');<br />
<li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;this.mlist.classList.add('music-list');<br />
<li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;this.generateMusicList();<br />
<li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;this.player.appendChild(this.mlist);<br />
<li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;}<br />
<li><br />
<li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;// 全屏按钮<br />
<li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;if (this.config.fs) {<br />
<li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;this.fs_btn = document.createElement('div');<br />
<li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;this.fs_btn.classList.add('btnFs');<br />
<li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;this.fullScreen(this.fs_btn);<br />
<li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;this.pa.appendChild(this.fs_btn);<br />
<li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;}<br />
<li><br />
<li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;this.pa.appendChild(this.player);<br />
<li><br />
<li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;// 自定义添加的播放按钮(数组doms传参)<br />
<li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;if (this.config.btns) {<br />
<li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;this.config.btns.forEach(btn =&gt; {<br />
<li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; btn.title = '播放/暂停(Alt+X)';<br />
<li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; btn.addEventListener('click', () =&gt; {<br />
<li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;this.togglePlay();<br />
<li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; });<br />
<li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;});<br />
<li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;}<br />
<li><br />
<li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;// 热键<br />
<li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;document.addEventListener('keydown', (e) =&gt; {<br />
<li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;if(e.altKey) {<br />
<li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; if (e.key === 'x') this.togglePlay();<br />
<li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; if (e.key === 'p') this.playPrev();<br />
<li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; if (e.key === 'n') this.playNext();<br />
<li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; if (e.key === 'l') this.listControl.click();<br />
<li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;}<br />
<li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;});<br />
<li>&nbsp; &nbsp; }<br />
<li><br />
<li>&nbsp; &nbsp; // 列表定位+控制按钮状态<br />
<li>&nbsp; &nbsp; placeMList() {<br />
<li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;if (this.isSingle) return;<br />
<li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;const style = window.getComputedStyle(this.player);<br />
<li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;const up = parseInt(style.getPropertyValue('bottom')) &gt;= parseInt(style.getPropertyValue('top'));<br />
<li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;const ar = ['▲','▼' ];<br />
<li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;this.listControl.textContent = ar[+up];<br />
<li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;this.mlist.style.setProperty(`${up ? 'top' : 'bottom'}`, '100%');<br />
<li>&nbsp; &nbsp; }<br />
<li><br />
<li>&nbsp; &nbsp; // 生成列表<br />
<li>&nbsp; &nbsp; generateMusicList() {<br />
<li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;const ol = document.createElement('ol');<br />
<li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;this.playList.forEach((list, idx) =&gt; {<br />
<li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;const li = document.createElement('li');<br />
<li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;li.innerHTML = `&lt;span&gt;${list}&lt;/span&gt;`;<br />
<li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;li.dataset.idx = idx;<br />
<li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;li.onclick = () =&gt; {<br />
<li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; this.selectTrack(idx);<br />
<li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;}<br />
<li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;ol.appendChild(li);<br />
<li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;});<br />
<li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;this.mlist.appendChild(ol);<br />
<li>&nbsp; &nbsp; }<br />
<li><br />
<li>&nbsp; &nbsp; // 全屏<br />
<li>&nbsp; &nbsp; fullScreen = (btn) =&gt; {<br />
<li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;let isFullscreen = false;<br />
<li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;btn.textContent = '进入全屏';<br />
<li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;btn.title = 'F11';<br />
<li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;btn.addEventListener('click', () =&gt; {<br />
<li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;isFullscreen ? document.exitFullscreen() : this.pa.requestFullscreen();<br />
<li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;});<br />
<li><br />
<li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;document.addEventListener('fullscreenchange', () =&gt; {<br />
<li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;if (document.fullscreenElement !== null) {<br />
<li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; isFullscreen = true;<br />
<li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; btn.textContent = '退出全屏';<br />
<li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;} else {<br />
<li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; isFullscreen = false;<br />
<li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; btn.textContent = '进入全屏';<br />
<li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;}<br />
<li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;});<br />
<li><br />
<li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;document.addEventListener('keydown', (e) =&gt; {<br />
<li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;if (e.key === 'F11') {<br />
<li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; e.preventDefault();<br />
<li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; isFullscreen ? document.exitFullscreen() : this.pa.requestFullscreen();<br />
<li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;}<br />
<li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;});<br />
<li>&nbsp; &nbsp; };<br />
<li><br />
<li>&nbsp; &nbsp; // 播放器+全屏隐身现身<br />
<li>&nbsp; &nbsp; displayPlayer() {<br />
<li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;let timerId;<br />
<li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;this.pa.addEventListener('mousemove', () =&gt; {<br />
<li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;clearTimeout(timerId);<br />
<li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;this.pa.style.setProperty('--opacity', '1');<br />
<li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;timerId = setTimeout(() =&gt; this.pa.style.setProperty('--opacity', '0'), 3000);<br />
<li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;});<br />
<li>&nbsp; &nbsp; }<br />
<li><br />
<li>&nbsp; &nbsp;&nbsp; &nbsp;// 获取元素(支持 id/class/元素实体)<br />
<li>&nbsp; &nbsp;&nbsp; &nbsp;getParentElement() {<br />
<li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; const pa = this.config.pa;<br />
<li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; if (pa instanceof HTMLElement) return pa;<br />
<li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; return document.querySelector(pa) || document.body;<br />
<li>&nbsp; &nbsp;&nbsp; &nbsp;}<br />
<li><br />
<li>&nbsp; &nbsp; // 错误处理<br />
<li>&nbsp; &nbsp;&nbsp; &nbsp;showError(msg) {<br />
<li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; this.mlist.dataset.currentsong = msg;<br />
<li>&nbsp; &nbsp;&nbsp; &nbsp;}<br />
<li><br />
<li>&nbsp; &nbsp; // 时间格式化<br />
<li>&nbsp; &nbsp; s2m(seconds) {<br />
<li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;const min = Math.floor(seconds / 60).toString().padStart(2, '0');<br />
<li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;const sec = Math.floor(seconds % 60).toString().padStart(2, '0');<br />
<li>&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;return `${min}:${sec}`;<br />
<li>&nbsp; &nbsp; }<br />
<li>}</ol></div><em onclick="copycode($('code_DzS'));">复制代码</em></div>

醉美水芙蓉 发表于 7 天前

5月5日更新的 AudioPlayer 插件实现在指定的元素上生成播放器+全屏机制。主要更新内容:

(一)支持热键交互

Alt + X :播放/暂停
Alt + L :呼出/关闭音乐列表
Alt + P :前一首
Alt + N :下一首

F11 :全屏/常规模式切换
Esc :关闭全屏

(二)支持添加多个自定义播放控制元素

使用方法:在配置中加入 btns 键,键值为数组,数组元素为 dom 实体。

【例一】假如帖子中有两个拥有 id 的元素,id="myplayer1" 和 id="myplayer2",想让它们也能通过点击控制音频的播放、暂停,则:

var setting = {
    // 其它配置
    btns: ,
};

【例二】假设帖子中有一组 class="mypic" 的图片,现在想让它们能成为音频控制器,则:

var setting = {
    // 其它配置
    btns: document.querySelectorAll('.mypic'),
};

注意:请不要将帖子主元素加入 btns 键值中,因为这会影响其下子元素的所有点击操作。


页: [1]
查看完整版本: 马黑黑AudioPlayer插件源码