亚伦影音工作室 发表于 昨天 16:12

落寞频谱

本帖最后由 亚伦影音工作室 于 2026-11-15 16:12 编辑 <br /><br /><style>
#papa {
    margin: 10px -250px;
        width: 1286px;
        height: 740px;
        background:#000;
        box-shadow: 0px 0px 0px 2px #cccccc, 0px 0px 0px 8px #880000;
        position: relative;
        overflow: hidden;
        z-index: 12345;
}

#spectrum {position:absolute;
    transform: scale(0.7);
    transform-origin: -90px 200px;
}
#mediaWrap{
    position:absolute;
    inset:0;
    width:100%;
    height:100%;
    overflow:hidden;
}
#vid {
    width: 100%;
    height: 100%;
    object-fit: cover;
    pointer-events: none;
    opacity: 1;
}
#aud{
    z-index: 115;
    width: 250px;
    top: 8%;
    height: 60px;
    left: 65%;
    display:none;
    position: relative;
}
#musickrc {
    width: 70%;
    top: 78%;
    position: absolute;
    left: 15%;
    cursor: pointer;
    z-index: 115;
    filter: drop-shadow(#000 1px 1px 1px) drop-shadow(#000 1px 1px 1px);
}
#musickrc01 {
    font-family: 华文隶书;
    font-size: 42px;
    margin: 0;
}
#musickrc01 span {
    display: inline-block;
    color: #ccc;
    transition: color 0.22s ease-out;
}
#musickrc02 {
    color: #0066cc;
    font-family: 华文隶书;
    font-size: 40px;
    margin: -10px 0 0 0;
}
/* =========新增:播放按钮样式,写在style标签内========= */
#myPlayBtn{
    position:absolute;
    z-index:200;
    top:40px;
    left:40px;
    width:36px;
    height:36px;
    background:rgba(255,0,0,0.7);
    border-radius:50%;
    cursor:pointer;
    display:flex;
    align-items:center;
    justify-content:center;
    color:#fff;
    font-size:20px;
}
</style>
<div id="papa">
    <!-- 按钮,不再带行内style -->
    <div id="myPlayBtn">▶</div>
   <div id="spectrum">
<script>document.write('<scriptdata-effect="10"src="https://bbs.cnzv.cc/v/waveform/spectrum.js" type="text/javascript" charset="utf-8"><\/script>');</script></div>
<div id="musickrc">
      <p id="musickrc01"></p>
      <p id="musickrc02"></p>
    </div>
    <div id="mediaWrap">
          <video id="vid" muted autoplay loop src="https://img-baofun.zhhainiao.com/pcwallpaper_ugc/preview/0b559548ab1cf9592a5370b82da6e6cc_preview.mp4"></video>
    </div>
<audio id="aud" loop autoplay src="https://aod.cos.tx.xmcdn.com/storages/1874-audiofreehighqps/41/FB/GAqhp50M0p5VACAAAAQpnCkh.m4a" crossorigin="anonymous" >
</audio>
</div>


<script>
const audio = document.getElementById('aud');
const video = document.getElementById('vid');
const lineEl = document.getElementById('musickrc01');
const nextEl = document.getElementById('musickrc02');
const krcWrap = document.getElementById('musickrc');
// =========切换这里!1=单行居中,2=双行错开=========
const showMode = 2;
// ==========================================
const songkrc = `作词:乙二
作曲:阿末@走心音乐   
当初对我承诺地久天长
现在看来确实太过荒唐
对于你来讲不论谁在身旁
都只是临时爱一场
如果早知道会变成这样
就不该把心交到你手上
直到受过了伤才看清真相
无数次失眠到天亮
动了情的人才会觉得夜漫长
毕竟放不下的心事最难藏
誓言说的漂亮不过是你撒的谎
留我一个人空想到天亮
动了情的人才会觉得夜太长
只怪念念不忘却得不到回响
努力付出一场最后红了眼眶
所有期待成了昂贵奢望
LRC编辑:小辣椒
如果早知道会变成这样
就不该把心交到你手上
直到受过了伤才看清真相
无数次失眠到天亮
动了情的人才会觉得夜漫长
毕竟放不下的心事最难藏
誓言说的漂亮不过是你撒的谎
留我一个人空想到天亮
动了情的人才会觉得夜太长
只怪念念不忘却得不到回响
努力付出一场最后红了眼眶
所有期待成了昂贵奢望
谢谢欣赏

`;
const colorList = ['#ff4444','#ffbb33','#00C851','#33b5e5','#AA66CC','#ff8800','#00ffff','#ff00aa'];
function getColor(idx){
    return colorList;
}
function parseLyric(text) {
    const lines = text.split(/\r|\n|\r\n/);
    const pattern = /\[\d{1,2}:\d{2}(?:\.\d{1,3})?\]/g;
    const result = [];
    for (const line of lines) {
      const match = line.match(pattern);
      if (!match) continue;
      const content = line.replace(pattern, '').trim();
      if (!content) continue;
      for (const m of match) {
            const parts = m.slice(1, -1).split(':');
            const min = parseInt(parts, 10);
            const sec = parseFloat(parts);
            result.push();
      }
    }
    return result.sort((a, b) => a - b);
}
function wordToSpan(str) {
    return [...str].map((ch,i)=>{
      return `<span data-ci="${i}">${ch}</span>`;
    }).join('');
}
const lyric = parseLyric(songkrc);
let currentLineIndex = -1;

musickrc.addEventListener('click', ()=>{
    if(aud.paused){
      aud.play();
      vid.play();
    }else{
      aud.pause();
      vid.pause();
    }
});

// 缓动函数 easeOut,柔和曲线
function easeOut(t){
    return 1 - Math.pow(1 - t, 2.2);
}

audio.addEventListener('timeupdate', () => {
    const t = audio.currentTime;
    let idx = 0;
    for (let i = 0; i < lyric.length; i++) {
      if (t >= lyric) {
            idx = i;
      }
    }
    if (currentLineIndex !== idx) {
      currentLineIndex = idx;
      lineEl.innerHTML = wordToSpan(lyric);
      if(showMode === 2){
            lineEl.style.textAlign = 'left';
            nextEl.style.textAlign = 'right';
            nextEl.textContent = lyric ? lyric : '';
            nextEl.style.display = 'block';
      }else{
            lineEl.style.textAlign = 'center';
            nextEl.textContent = '';
            nextEl.style.display = 'none';
      }
    }
    const lineStart = lyric;
    const lineEnd = lyric ? lyric : audio.duration || t + 5;
    const lineDuration = lineEnd - lineStart;
    if (lineDuration <= 0) return;
    const spans = lineEl.querySelectorAll('span');
    const totalWord = spans.length;
    if (totalWord === 0) return;
    let lineProgress = Math.min(Math.max((t - lineStart) / lineDuration, 0), 1);
    lineProgress = easeOut(lineProgress);
    let activeWordCount = Math.ceil(lineProgress * totalWord);
    if(activeWordCount > totalWord) activeWordCount = totalWord;

    spans.forEach((sp, i)=>{
      if(i < activeWordCount){
            sp.style.color = getColor(i);
      }else{
            sp.style.color = '#ccc';
      }
    })
});
</script>

<!-- 按钮控制JS -->
<script>
const btn = document.querySelector('#myPlayBtn');
const aud = document.querySelector('#aud');
const vid = document.querySelector('#vid');

function updateBtnText(){
    btn.innerText = aud.paused ? "▶" : "∥";
}
btn.onclick = function(){
    if(aud.paused){
      aud.play();
      vid.play();
    }else{
      aud.pause();
      vid.pause();
    }
    updateBtnText();
}
aud.addEventListener('play',updateBtnText);
aud.addEventListener('pause',updateBtnText);
updateBtnText();
</script>

醉美水芙蓉 发表于 昨天 19:06

欣赏亚伦老师精彩播放器!
页: [1]
查看完整版本: 落寞频谱