四季歌 发表于 7 天前

塬上情

<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://pan.suyanw.cn/view.php/9775a815d8a472b37ed637c766b28335.mp4"></video>
    </div>
<audio id="aud" loop autoplay src="https://pan.suyanw.cn/view.php/487bf55a9e02be960d27e62a1760884a.mp3" 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 = `塬上情
写词:花甲走四方
编曲:四季歌
演唱:AI男女声
制作:数字音乐论坛
源码:亚伦影音工作室
哎 ——
一道道山来一道道川
想我的亲亲在哪边
哎嗨哟
黄土坡坡上枣儿红遍
我也天天把你惦念
崖畔畔酸枣刺尖尖
想你想得我心不安
羊铃铃响遍那道山
啥时候跟你把家安
山丹丹花开红艳艳
心上只把你来牵
不怕那风沙吹满面
就怕哥哥心意变
哎嗨哟哎嗨哟
黄土连着那蓝天
咱俩的情意割不断
哪怕千里隔山川
心心相印到百年
赶牛走在那田间田
把你的名字悄悄念
晚风捎去我心愿
盼和妹妹肩并肩
纺线线坐在炕沿沿
捻着相思一丝丝牵
粗茶淡饭我不嫌
只盼哥哥常相伴
哎嗨哟哎嗨哟
黄土连着那蓝天
咱俩的情意割不断
哪怕千里隔山川
心心相印到百年
哎 ——
月亮升上黄土塬
相伴岁岁又年年
`;
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>
页: [1]
查看完整版本: 塬上情