亚伦影音工作室 发表于 2024-4-22 13:33

最美的情缘 (DJ何鹏版)

本帖最后由 亚伦影音工作室 于 2024-12-10 19:40 编辑 <br /><br /><style>
/* 播放器id选择器 */
#mplayer {
        width: 30%;
        height: 50px;
        text-align: justify;
        text-align-last: justify;
        font: normal 14px / 40px sans-serif;
        color: #ffffff;
        pointer-events: none;
        position: absolute;
        top:86%; left:15%;z-index: 123;
        --prg: 0%;
}

/* 伪元素公共属性 */
#mplayer::before, #mplayer::after { position: absolute; content: ''; cursor: pointer; pointer-events: auto; }

/* 伪元素 ::before 做进度条 */
#mplayer::before {
        width: 100%;
        height: 30%;
        bottom: 0;
        background: radial-gradient(circle at calc(var(--prg) + 4px) 50%, #ffffff 4px, transparent 5px, transparent),
                linear-gradient(to right, #00ff00, #00ff00, #00ff00 var(--prg), #aed8e6 0) no-repeat 0 50% / 100% 2px;
}

/* 伪元素 ::after 做按钮 */
#mplayer::after {
        width: 35px;
        height: 35px;
        left: calc(50% - 15px);
        transition: all .35s;
        }

/* class选择器 :播放按钮 */
.play { background:url(https://pic.imgdb.cn/item/64d863391ddac507cc4a7798.png)no-repeat50% 0px/35px 35px; display: var(--play);}

/* class选择器 :暂停按钮 */
.pause { background:url(https://pic.imgdb.cn/item/64d863801ddac507cc4b2204.png)no-repeat   50% 0px/35px 35px; display: var(--pause);}
#lb{ position: absolute;top: 75%;left: 5%; width: 40px; height: 30px; }
#lb img{ width: 100%; height: 100%;   opacity: 1; }
</style>
<div id="papa">
<div id="dt"> <img id="Img" src="https://pic.imgdb.cn/item/65e712979f345e8d039e5ada.gif" alt="" /></div>
<div id="lb"> <img id="lbImg" src="https://pic.imgdb.cn/item/662615500ea9cb14035d435e.gif" alt="" /></div>
<div data-lrc="亚伦影音工作室" id="lrc">亚伦影音工作室</div>
<div id="mplayer" class="play"></div>
<audio id="aud" src="https://s2.ananas.chaoxing.com/sv-w8/audio/6b/a5/56/20b6752b04d0ab8c9a28255446cd5291/audio.mp3" autoplay loop></audio>
</div>
<script>

//函数 :秒 → 分:秒
let toMin = (val) => {
        if (!val) return '00:00';
        let min = parseInt(val / 60), sec = parseFloat(Math.floor(val) % 60);
        if(sec < 10) sec = '0' + sec;
        return min + ':' + sec;
};

// 函数 :根据播放/暂停状态控制按钮样式
let mState = () => mplayer.className = aud.paused ? 'play' : 'pause';

// 鼠标指针移动显示 tiptop 信息
mplayer.onmousemove = (e) => {
        mplayer.title = e.offsetY < 0.7 * mplayer.offsetHeight ? '播放/暂停' : '调节进度';
}

// 单击事件 :播放/暂停或调节进度
mplayer.onclick = (e) => {
        if(e.offsetY > 0.7 * mplayer.offsetHeight) {
                aud.currentTime = e.offsetX * aud.duration / (mplayer.offsetWidth - 5);
        }else{
                aud.paused ? (aud.play(),image.play(),imagelb.play()): (aud.pause(),image.stop(),imagelb.stop());
        }
}

// 监听播放进度 :更新进度条
aud.addEventListener('timeupdate', ()=> {
        mplayer.style.setProperty('--prg', aud.currentTime / (aud.duration + 10) * 100 + '%');
        mplayer.innerText = toMin(aud.currentTime) + ' ' + toMin(aud.duration);
});

// 监听暂停事件
aud.addEventListener('pause', () => mState());

//监听播放事件
aud.addEventListener('play', () => mState());

</script>

<style type="text/css">
#papa {margin: 150px -300px;
        width: 1164px;
        height: 640px;
        background:url(https://pic.imgdb.cn/item/6600e7829f345e8d03a9a674.jpg)no-repeat center/cover;
        box-shadow: 0px 0px 0px 2px #cccccc, 0px 0px 0px 8px #880000;
        position: relative;overflow: hidden;
        z-index: 12345;
}

#dt { position: absolute;top: 15%;left: 5%; width: 250px; height: 140px;}
#dt img{ width: 100%;    opacity: 1; }


#lrc {
        --state: paused;
        --motion: cover2;
        --tt: 2s;
        --bg: linear-gradient(180deg, #880000, #880000);
        position: absolute;z-index: 4;
        left: 30%;
        transform: translate(-50%);
        top: 75%;
        font:normal 2.5em 华文隶书;
        color: #000078;
        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: 20%;
        height: 100%;
        color: transparent;
        overflow: hidden;
        white-space: pre;
        background: var(--bg);
       
        -webkit-background-clip: text;
        animation: var(--motion) var(--tt) linear forwards;
        animation-play-state: var(--state);
}
@keyframes cover1 { from { width: 0; } to { width: 100%; } }
@keyframes cover2 { from { width: 0; } to { width: 100%; } }
</style>
<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')) : (lrc.style.setProperty('--state','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>
if ('getContext' in document.createElement('canvas')) {
    HTMLImageElement.prototype.play = function() {
      if (this.storeCanvas) {
            // 移除存储的canvas
            this.storeCanvas.parentElement.removeChild(this.storeCanvas);
            this.storeCanvas = null;
            // 透明度还原
            image.style.opacity = '';imagelb.style.opacity = '';
      }
      if (this.storeUrl) {
            this.src = this.storeUrl;   
      }
    };
    HTMLImageElement.prototype.stop = function() {
      var canvas = document.createElement('canvas');
      // 尺寸
      var width = this.width, height = this.height;
      if (width && height) {
            // 存储之前的地址
            if (!this.storeUrl) {
                this.storeUrl = this.src;
            }
            // canvas大小
            canvas.width = width;
            canvas.height = height;
            // 绘制图片帧(第一帧)
            canvas.getContext('2d').drawImage(this, 0, 0, width, height);
            // 重置当前图片
            try {
                this.src = canvas.toDataURL("image/gif");
            } catch(e) {
                // 跨域
                this.removeAttribute('src');
                // 载入canvas元素
                canvas.style.position = 'absolute';
                // 前面插入图片
                this.parentElement.insertBefore(canvas, this);
                // 隐藏原图
                this.style.opacity = '0';
                // 存储canvas
                this.storeCanvas = canvas;
            }
      }
    };
}

var image= document.getElementById("Img");
var imagelb= document.getElementById("lbImg");
aud.addEventListener('play', () => mState());
aud.addEventListener('pause', () => mState());
</script>

愤怒的葡萄 发表于 2024-4-22 13:37

来欣赏聆听一下音乐,感谢楼主的无私分享。

庶民 发表于 2024-4-22 16:23

给人无限遐思。

红影 发表于 2024-4-22 18:07

这窗外的夜空好美啊。播放进度条上还有个小喇叭动态图呢,有趣。还是一键全控呢。
这制作真漂亮,欣赏亚伦老师好帖{:4_199:}

起个网名好难 发表于 2024-4-22 18:11

https://img.soogif.com/olrt53z1tMMdY6VqE2K7nSCkMRVWeFe0.gif

老谟深虑 发表于 2024-4-22 18:22

          欣赏老师的精美音画,点赞!
页: [1]
查看完整版本: 最美的情缘 (DJ何鹏版)