亚伦影音工作室 发表于 2024-12-10 20:11

最美情缘DJ默涵版【精美小播】

本帖最后由 亚伦影音工作室 于 2024-12-11 18:58 编辑 <br /><br /><style>
#papa{margin: 150px 0 20px calc(50% - 721px); background:#000080 url('https://pic.imgdb.cn/item/6732a9bed29ded1a8cf916f5.webp')no-repeat center/cover;width: 1286px; height: 720px;   box-shadow: 3px 3px 6px gray; overflow: hidden; z-index: 1234567; position: relative;}

#cndpt{margin: 650px 20px ;
    position: relative;width: 40px; height: 40px;
    background: url(https://pic.imgdb.cn/item/675813f6d0e0a243d4e14a48.png)no-repeat 0px 0px/cover; }
#enopg{
    position: relative;width: 40px; height: 40px;
   background: url(https://pic.imgdb.cn/item/675813e7d0e0a243d4e14a18.png) no-repeat 0px 0px/cover;
    display:none;
}
#mypic {top:30%; left:75%;z-index: 6;
display: block;position: absolute;
    width: 250px; height: 250px;
    background: url(https://pic.imgdb.cn/item/67502acbd0e0a243d4dd5ddc.png)no-repeat center/3250px 250px;
animation: heart-burst steps(13) 2s infinite;mix-blend-mode: difference;
}
@keyframes heart-burst {
0% {background-position: 0px 0;}
100% {background-position: -3250px 0;}
}
#lrc {--state: paused;--motion: cover2;--tt: 2s;--bg: linear-gradient(0deg, #880000, #880000, #880000);
position: absolute;z-index: 6;left: 50%; top: 90%;transform: translate(-50%);font:normal 3.5em/1em 华文隶书; font-weight:400;color: #000080;white-space: pre;-webkit-background-clip: text;filter:drop-shadow(#FFFFFF 1px 0 0)drop-shadow(#FFFFFF 0 1px 0)drop-shadow(#FFFFFF -1px 0 0) drop-shadow(#FFFFFF 0 -1px0);}
#lrc::before {position: absolute;content: attr(data-lrc);width: 100%; height: 100%;color: transparent;overflow: hidden;white-space: pre;background: var(--bg);clip-path: inset(0 100% 0 0);-webkit-background-clip: text;animation: var(--motion) var(--tt) linear forwards;animation-play-state: var(--state);}
@keyframes cover1{ to { clip-path: inset(0 0 0 0); } }@keyframes cover2 { to { clip-path: inset(0 0 0 0); } }
</style>
<div id="papa">
<div id="cndpt" onclick="pic()" >
<div id="enopg" ></div>
</div>
<div id="mypic" ></div>
<div data-lrc="" id="lrc"></div>
<canvas id='canvas' width="1286" height="250"style="position: absolute; left:0px; bottom:0px;z-index: -1;"></canvas>
</div>
<audio id="aud" src="https://s2.ananas.chaoxing.com/sv-w8/audio/6b/a5/56/20b6752b04d0ab8c9a28255446cd5291/audio.mp3" autoplay loop crossOrigin="anonymous"></audio>
<script >
function pic(){
    varimgElement= document.getElementById('enopg');
    if (imgElement.style.display === 'none' || imgElement.style.display === '') {
       imgElement.style.display = 'block';aud.pause();
    } else {
    imgElement .style.display = 'none';aud.play();
    }
}
mypic.style.animationPlayState = aud.paused ? 'paused' : 'running';
aud.addEventListener('playing', () =>mypic.style.animationPlayState = 'running');
aud.addEventListener('pause', () =>mypic.style.animationPlayState = 'paused');

</script >
<script >
(function() {
/*原始lrc歌词*/
let lrcStr = `最美的情缘 (DJ何鹏版)
作词:玉镯儿
作曲:崔伟立
演唱:魏新雨
☆★Lrc编辑 梅竹★☆
☆★协编 兰菊★☆
● ● ● ● ● ● ●
等到那一天 风停了花谢了
等到那一天 雪化了月落了
我就化作 化作一只蝴蝶
轻轻落在 落在你指尖
(Music)
多情的下关风吹呀吹
吹不干千年的洱海
我遇见你的那一天
世上才有风花雪月
十里香上关花开呀开
开不完相思的缠绵
我相信最美的情缘
不在天上在人间
落在你指尖
(Music)
☆★梅竹谢谢欣赏★☆
=End=
`;
/*变量 :mKey - 当前歌词索引;mFlag :调用关键帧动画索引;averAdd :平均值补偿*/
let mKey = 0, mFlag = true, averAdd = 0.3;

/*函数 :获取每句歌词用时,歌词用时若超过平均值则取平均值,最后一句歌词则取平均值*/
let lrcTime = (ar) => {
        let tmpAr = [];
        for(j = 0; j <ar.length - 1; j ++) {
                if(j !== ar.length - 1) tmpAr = parseFloat((ar - ar).toFixed(1));
        }
        let aver = parseInt(tmpAr.reduce((a,b) => a + b) / (tmpAr.length - 1)) + averAdd;
        tmpAr.push(aver);
        tmpAr.forEach((item,key) => {
                ar = item > aver ? aver : item;
        });
        return ar;
};

/*函数 :从原始lrc歌词获取信息并存入 n*3 数组*/
let getLrcAr = (text) => {
        let lrcAr = [];
        let calcRule = ;
        for(x of text.split('\n')) {
                let ar = [];
                let re = /\d+[\.:]\d+([\.:]\d+)?/g;
                let geci = x.replace(re,'');
                if(geci) {
                        geci = geci.replace(/[\[\]\'\"\t,]s?/g,'');
                        let time = x.match(re);
                        if(time != null) {
                                for(y of time) {
                                        let tmp = y.match(/\d+/g);
                                        let sec = 0;
                                        for(z in tmp) sec += tmp * calcRule;
                                        ar = ;
                                        lrcAr.push(ar);
                                }
                        }
                }
        }
        lrcAr.sort((a,b)=> a - b);
        return(lrcTime(lrcAr));
};

/*函数 :模拟显示同步歌词*/
let showLrc = (time) => {
        let name = mFlag ? 'cover1' : 'cover2';
        lrc.innerHTML = lrcAr;
        lrc.dataset.lrc = lrcAr;
        lrc.style.setProperty('--motion', name);
        lrc.style.setProperty('--tt', time + 's');
        lrc.style.setProperty('--state', 'running');
        mKey += 1;
        mFlag = !mFlag;
};

/*函数 :处理当前歌词索引 mKey*/
let calcKey = () => {
        for (j = 0; j < lrcAr.length; j++) {
                if (aud.currentTime <= lrcAr) {
                        mKey = j - 1;
                        break;
                }
        }
        if (mKey < 0) mKey = 0;
        if (mKey > lrcAr.length - 1) mKey = lrcAr.length - 1;
        let time = lrcAr - (aud.currentTime - lrcAr);
        showLrc(time);
};

/*格式化时间信息*/
let toMin = (val) => {
        if (!val) return '00:00';
        val = Math.floor(val);
        let min = parseInt(val / 60),
        sec = parseFloat(val % 60);
        if (min < 10) min = '0' + min;
        if (sec < 10) sec = '0' + sec;
        return min + ':' + sec;
}

/*函数 :关键帧动画状态切换*/
let mState = () => aud.paused ? (lrc.style.setProperty('--state','paused'),player.style.animationPlayState = 'paused') : (lrc.style.setProperty('--state','running'),player.style.animationPlayState = 'running');

/*监听播放进度*/
aud.addEventListener('timeupdate', () => {
        for (j = 0; j < lrcAr.length; j++) {
                if (aud.currentTime >= lrcAr) {
                        cKey = j;
                        if (mKey === j) showLrc(lrcAr);
                        else continue;
                }
        }
});
aud.addEventListener('pause', () => mState());/*监听暂停事件*/
aud.addEventListener('play', () => mState());/*监听播放事件*/
aud.addEventListener('seeked', () => calcKey());/*监听查询事件*/
let lrcAr = getLrcAr(lrcStr); /*获得歌词数组*/
})();
</script>
<script>
window.onload = function() {
    var audio = document.getElementById('audio');
    var ctx = new AudioContext();
    var analyser = ctx.createAnalyser();
    var audioSrc = ctx.createMediaElementSource(aud);
    // we have to connect the MediaElementSource with the analyser
    audioSrc.connect(analyser);
    analyser.connect(ctx.destination);
    // we could configure the analyser: e.g. analyser.fftSize (for further infos read the spec)
    // analyser.fftSize = 70;
    // frequencyBinCount tells you how many values you'll receive from the analyser
    var frequencyData = new Uint8Array(analyser.frequencyBinCount);

    // we're ready to receive some data!
    var canvas = document.getElementById('canvas'),
      cwidth = canvas.width,
      cheight = canvas.height - 2,
      meterWidth = 6, //width of the meters in the spectrum
      gap = 2, //gap between meters
      capHeight = 2,
      capStyle = '#fff',
      meterNum = 1286 / (6 + 2), //count of the meters
      capYPositionArray = []; ////store the vertical position of hte caps for the preivous frame
    ctx = canvas.getContext('2d'),
    gradient = ctx.createLinearGradient(10, 20, 10, 250);
    gradient.addColorStop(0.4, '#ff0000');
    gradient.addColorStop(0.6, '#fff000');
    gradient.addColorStop(1, '#00ee00');

// loop
    function renderFrame() {
      var array = new Uint8Array(analyser.frequencyBinCount);
      analyser.getByteFrequencyData(array);
      var step = Math.round(array.length / meterNum); //sample limited data from the total array
      ctx.clearRect(0, 0, cwidth, cheight);
      for (var i = 0; i < meterNum; i++) {
            var value = array;
            if (capYPositionArray.length < Math.round(meterNum)) {
                capYPositionArray.push(value);
            };
            ctx.fillStyle = capStyle;
            //draw the cap, with transition effect
            if (value < capYPositionArray) {
                ctx.fillRect(i * 10, cheight - (--capYPositionArray), meterWidth, capHeight);
            } else {
                ctx.fillRect(i * 10, cheight - value, meterWidth, capHeight);
                capYPositionArray = value;
            };
            ctx.fillStyle = gradient; //set the filllStyle to gradient for a better look
            ctx.fillRect(i * 10 /*meterWidth+gap*/ , cheight - value + capHeight, meterWidth, cheight); //the meter
      }
      requestAnimationFrame(renderFrame);
    }
    renderFrame();
    audio.play();
};

</script>

起个网名好难 发表于 2024-12-10 20:24

蝴蝶没反应, 按钮也没反应

小辣椒 发表于 2024-12-10 20:36

按钮被频谱挡住了,点击没有用

小辣椒 发表于 2024-12-10 20:38

现在修改了,按钮代码要在频谱的前面

亚伦影音工作室 发表于 2024-12-10 20:39

小辣椒 发表于 2024-12-10 20:36
按钮被频谱挡住了,点击没有用

更正!

红影 发表于 2024-12-10 21:58

漂亮的频谱,好久没看到这种频谱了。这个小播按钮也漂亮,就是亚伦老师那个小播吧{:4_187:}

红影 发表于 2024-12-10 21:58

一键全控。歌词也漂亮。
欣赏亚伦老师好帖{:4_199:}

秋思梦景 发表于 2024-12-11 05:45

问候老师好!精美音画佳作,精心制作分享。为您点赞!{:5_116:}{:4_187:}

世外桃源 发表于 2024-12-11 17:09

动感音乐,漂亮的,楼主制作辛苦了

世外桃源 发表于 2024-12-11 17:09

感谢分享
页: [1]
查看完整版本: 最美情缘DJ默涵版【精美小播】