亚伦影音工作室 发表于 2023-7-29 09:36

如果失去你都是天意 - 赵洋

本帖最后由 亚伦影音工作室 于 2023-7-29 20:05 编辑 <br /><br /><style>
#papa{margin: 10px -300px ;
width: 1164px;box-shadow: 0px 0px 0px 2px #cccccc, 0px 0px 0px 6px #880000; overflow: hidden;
height: 620px;
border: 1px solid;
background: #333 url('https://pic.imgdb.cn/item/648496571ddac507cc654bc7.jpg') no-repeat center/cover;
position: relative;z-index: 12345;}
.dt {width: 100%; height: 100%;   z-index: -3;position: absolute; mix-blend-mode: lighten;}
:root { --state: running; --prg: 0%; --delay: 0s; }
.mydiv {width: 100%; height: 100%;   overflow: hidden; z-index: 10; display: grid; place-items: center; position: relative; }
.heart { position: absolute; font: normal 30px sans-serif; animation: up 5s var(--delay) infinite var(--state); }
.heart:nth-of-type(2) { --delay: -2.5s; }
#mplayer { position: absolute; bottom: 10px; width: 900px; height: 40px; background: linear-gradient(to right,red var(--prg),#FFFFFF 0) repeat-x 0 50% / 100% 2px; }
#mplayer::before, #mplayer::after { position: absolute; top: 28%; font-size: 14px; }
#mplayer::before { content: attr(data-cu); left: -50px;color: #FFFFFF; }
#mplayer::after { content: attr(data-du); right: -50px;color: #FFFFFF; }
#btnplay { position: absolute; left: calc(var(--prg) - 15px); bottom: 24px; font: normal 3em/0em serif; cursor: pointer; animation: swing 2s infinite linear var(--state); color:#ffFFFF;}
@keyframes swing {from { transform: rotate(0deg) skew(0deg); } to { transform: rotate(0deg) skew(0deg); } }
@keyframes up { 0% { opacity: 0; transform: rotate(0deg) translateY(0px); } 75% { opacity: 1; transform: rotate(-10deg) translateY(-300px); } 100% { opacity: 0; transform: rotate(-60deg) translateY(0px); } }
#lrc {
        --state: paused;
        --motion: cover2;
        --tt: 2s;
        --bg: linear-gradient(180deg, #880000, #880000);
        position: absolute;
        left: 50%;z-index: 20;
        transform: translate(-50%);
        top: 80%;
        font:normal 3.5em 华文隶书;
        color: #0000;
        white-space: pre;
        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{ 0% { width: 0%;letter-spacing: 15px; color:#000090;}100% { width: 350%; letter-spacing: 0px;color:#ff0000; }   }
@keyframes cover2 {0% { width: 0%;letter-spacing: 0px; color:#00ff00;}100% { width: 350%; letter-spacing: 15px;color:#ff0000; }}
#papa:hover #fullscreen { display:block ;}
#fullscreen { position: absolute; top:5%; left:80%;color:#FFffff; filter:drop-shadow( 1px 1px 1px #000000);font: normal 3em华文隶书; opacity: 1; cursor: pointer; z-index: 111}

</style>
<div id='papa'>
<span id="fullscreen">全屏观赏</span>
<div id="lrc" data-lrc="亚伦影音工作室">亚伦影音工作室</div>
<div class="dt"><img id="Img"src="https://pic.imgdb.cn/item/64be4b991ddac507cc68b62e.gif" width="100%" height="100%" ></div>
<div class="mydiv">
    <span class="heart">&#128158;</span>
    <span class="heart">&#127809;</span>
    <div id="mplayer" data-cu="00:00" data-du="00:00" title="调节进度">
            <div id="btnplay" title="暂停/播放">&#127928;</div>
</div>
</div>

    <audio id="aud" src="https://www.qqmc.com/mp3/music283066125.mp3" loop autoplay></audio>

</div>
<script>
(function() {
    let root = document.querySelector(':root');
    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 = () => root.style.setProperty('--state', aud.paused ? 'paused' : 'running');
    aud.addEventListener('pause', mState, false);
    aud.addEventListener('play', mState, false);
    aud.addEventListener('timeupdate', () => { root.style.setProperty('--prg', aud.currentTime / aud.duration * 100 + '%'); mplayer.dataset.cu = toMin(aud.currentTime); mplayer.dataset.du = toMin(aud.duration); });
    btnplay.onclick = (e) => { e.stopPropagation(); aud.paused ? aud.play() : aud.pause(); }
    mplayer.onclick = (e) => aud.currentTime = aud.duration * e.offsetX / mplayer.offsetWidth;
})();


(function() {
/*原始lrc歌词*/
let lrcStr = `
如果失去你都是天意 - 赵洋
词:张海宝
曲:张海宝
编曲:姜峨眉山升
和声:小佑
混音:冯鑫阳
制作人:亚伦
OP:亚伦影音工作室
安静的时候总会想起你
知心话语和温柔气息
简单的幸福温暖着梦里
梦醒时分剩一个自己
想你的时候你又在哪里
时过境迁成物是人非
流年把岁月堆砌成距离
来时的路找不回
如果失去你都是天意
为何还想在一起
听着情歌又流着眼泪
孤单寂寞伴随着四季
如果失去你都是天意
为何不愿说分离
情愿赌上这毕生运气
只换能与你再次相遇
想你的时候你在哪里
时过境迁成物是人非
流年把岁月堆砌成距离
来时的路找不回
如果失去你都是天意
为何还想在一起
听着情歌又流着眼泪
孤单寂寞伴随着四季
如果失去你都是天意
为何不愿说分离
情愿赌上这毕生运气
只换能与你再次相遇
如果失去你都是天意
为何还想在一起
听着情歌又流着眼泪
孤单寂寞伴随着四季
如果失去你都是天意
为何不愿说分离
情愿赌上这毕生运气
只换能与你再次相遇`;

/*变量 :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'),mplayer.style.animationPlayState = 'paused') : (lrc.style.setProperty('--state','running'),mplayer.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());/*监听查询事件*/
mplayer.addEventListener('click', () => { aud.paused ?aud.play() : aud.pause(); });

let lrcAr = getLrcAr(lrcStr); /*获得歌词数组*/
})();

let fs = true;
        fullscreen.onclick = () => {
                fs ? (fullscreen.innerText = '退出全屏', papa.requestFullscreen()) : (fullscreen.innerText = '全屏观赏', document.exitFullscreen());
                fs = !fs;
        };
</script>

红影 发表于 2023-7-29 10:32

这个小吉他的播放器的滑块真漂亮,欣赏亚伦老师好帖{:4_199:}

红影 发表于 2023-7-29 10:34

这个不知道为什么无法评分,评分界面点开后出现变形,无法选分数。

红影 发表于 2023-7-29 10:37

这个也没法点暂停,只要点了就跳回最初了。而且拉进度条也会出现问题,导致歌词无法正常显示。
只有什么都不动,才显示正常。

红影 发表于 2023-7-29 10:38

可能我电脑问题?我去清理一下。。。

小辣椒 发表于 2023-7-29 11:06

亚伦这个好像代码有错误,再仔细检查一下看看

小辣椒 发表于 2023-7-29 11:07

这种播放器构思很好,这种修改我有也是挺喜欢的

亚伦影音工作室 发表于 2023-7-29 11:27

小辣椒 发表于 2023-7-29 11:07
这种播放器构思很好,这种修改我有也是挺喜欢的

修改完毕,谢谢!

小辣椒 发表于 2023-7-29 11:29

亚伦影音工作室 发表于 2023-7-29 11:27
修改完毕,谢谢!

亚伦再看看我怎么不能加分

小辣椒 发表于 2023-7-29 11:31

我给你加了隔行码也是不行

醉美水芙蓉 发表于 2023-7-29 18:03

页: [1]
查看完整版本: 如果失去你都是天意 - 赵洋