马黑黑 发表于 2022-10-31 12:20

大风歌(新频谱播放器测试)

本帖最后由 马黑黑 于 2022-10-31 12:23 编辑 <br /><br /><style>
#papa {
        left: -214px;
        width: 1024px;
        height: 640px;
        background: #666 url('https://638183.freep.cn/638183/t22/webp/dafggee.webp') no-repeat center/cover;
        box-shadow: 3px 3px 20px #000;
        position: relative;
        z-index: 1;
}
#mplayer {
        position: absolute;
        display: grid;
        grid-template-areas:
                'cur btnplay dur'
                'prog prog prog';
        gap: 4px;
        place-items: end center;
        font-size: 14px;
        bottom: 20px;
        left: 20px;
}
#cur { grid-area: cur; color: snow; }
#dur { grid-area: dur; color: snow; }
#btnplay {
        grid-area: btnplay;
        display: grid;
        grid-auto-flow: column;
        place-items: end center;
        gap: 0 4px;
        height: 60px;
        cursor: pointer;
}
#btnplay > span {
        background: red;
        width: 4px;
        transition: .6s;
}
#prog {
        --ww: 0px;
        grid-area: prog;
        width: 400px;
        height: 12px;
        border-radius: 6px;
        background: snow;
        opacity: .65;
        cursor: pointer;
        position: relative;
}
#prog::before {
        position: absolute;
        content: '';
        width: var(--ww);
        height: 12px;
        border-radius: 6px;
        background: snow linear-gradient(90deg, green,red);
        opacity: .65;
}
#lrc {
        --motion: cover1;
        --tt: 5s;
        --state: paused;
        position: absolute;
        top: 20px;
        left: 20px;
        font: bold 2.4em sans-serif;
        color: hsl(0, 10%, 90%);
        -webkit-background-clip: text;
        filter: drop-shadow(1px 1px 2px hsla(0, 0%, 0%, .95));
}
#lrc::before {
        position: absolute;
        content: attr(data-lrc);
        width: 20%;
        height: 100%;
        color: transparent;
        overflow: hidden;
        white-space: nowrap;
        background: linear-gradient(180deg, hsla(60, 50%, 50%, .45), hsla(0, 100%, 50%, .75));
        filter: inherit;
        -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>

<div id="papa">
        <div id="lrc" data-lrc="花潮lrc在线">花潮lrc在线</div>
        <div id="mplayer">
                <div id="cur">00:00</div>
                <div id="btnplay"></div>
                <div id="dur">00:00</div>
                <div id="prog"></div>
        </div>
        <audio id="aud" src="https://music.163.com/song/media/outer/url?id=31587566.mp3" loop autoplay></audio>
</div>

<script>
(function() {
        let mKey = 0, mFlag = true;
let lrcAr = [
        ,
        ,
        ,
        ,
        ,
        ,
        ,
        ,
        ,
        ,
        ,
        ,
        ,
        ,
       
];
        for(j=0; j<20; j++) {
                let pinpu = document.createElement('span');
                pinpu.className = 'pinpu';
                pinpu.style.cssText += `height: ${Math.floor(Math.random()*50) + 10}px; background: #${Math.random().toString(16).substr(-6)};`;
                btnplay.appendChild(pinpu);
        }
        btnplay.onclick = () => aud.paused ? aud.play() : aud.pause();
        prog.onclick = (e) => aud.currentTime = aud.duration * e.offsetX / prog.offsetWidth;
        aud.addEventListener('seeked', () => calcKey());
        aud.addEventListener('pause', () => mState());
        aud.addEventListener('play', () => mState());
        aud.addEventListener('timeupdate', () => {
                let prg = aud.currentTime * prog.offsetWidth / aud.duration < 6 ? 6 : aud.currentTime * prog.offsetWidth / aud.duration;
                prog.style.setProperty('--ww', prg + 'px');
                cur.innerText = toMin(aud.currentTime);
                dur.innerText = toMin(aud.duration);
                setPinpu();
                for (j = 0; j < lrcAr.length; j++) {
                        if (aud.currentTime >= lrcAr) {
                                cKey = j;
                                if (mKey === j) showLrc(lrcAr);
                                else continue;
                        }
                }
        });
        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 showLrc = (time) => {
                let name = mFlag ? 'cover1' : 'cover2';
                lrc.innerHTML = lrc.dataset.lrc = lrcAr;
                lrc.style.setProperty('--motion', name);
                lrc.style.setProperty('--tt', time + 's');
                lrc.style.setProperty('--state', 'running');
                mKey += 1;
                mFlag = !mFlag;
        };
        let mState = () => lrc.style.setProperty('--state', aud.paused ? 'paused' : 'running');
        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 setPinpu = ()=> {
                let eles = document.querySelectorAll('.pinpu');
                eles.forEach((item) => item.style.height = `${Math.floor(Math.random()*50) + 10}px`);
        };
})();
</script>

马黑黑 发表于 2022-10-31 12:24

代码(都展开)
<style>
#papa {
        margin: auto;
        width: 1024px;
        height: 640px;
        background: #666 url('https://638183.freep.cn/638183/t22/webp/dafggee.webp') no-repeat center/cover;
        box-shadow: 3px 3px 20px #000;
        position: relative;
        z-index: 1;
}
#mplayer {
        position: absolute;
        display: grid;
        grid-template-areas:
                'cur btnplay dur'
                'prog prog prog';
        gap: 4px;
        place-items: end center;
        font-size: 14px;
        bottom: 20px;
        left: 20px;
}
#cur { grid-area: cur; color: snow; }
#dur { grid-area: dur; color: snow; }
#btnplay {
        grid-area: btnplay;
        display: grid;
        grid-auto-flow: column;
        place-items: end center;
        gap: 0 4px;
        height: 60px;
        cursor: pointer;
}
#btnplay > span {
        background: red;
        width: 4px;
        transition: .6s;
}
#prog {
        --ww: 0px;
        grid-area: prog;
        width: 400px;
        height: 12px;
        border-radius: 6px;
        background: snow;
        opacity: .65;
        cursor: pointer;
        position: relative;
}
#prog::before {
        position: absolute;
        content: '';
        width: var(--ww);
        height: 12px;
        border-radius: 6px;
        background: snow linear-gradient(90deg, green,red);
        opacity: .65;
}
#lrc {
        --motion: cover1;
        --tt: 5s;
        --state: paused;
        position: absolute;
        top: 20px;
        left: 20px;
        font: bold 2.4em sans-serif;
        color: hsl(0, 10%, 90%);
        -webkit-background-clip: text;
        filter: drop-shadow(1px 1px 2px hsla(0, 0%, 0%, .95));
}
#lrc::before {
        position: absolute;
        content: attr(data-lrc);
        width: 20%;
        height: 100%;
        color: transparent;
        overflow: hidden;
        white-space: nowrap;
        background: linear-gradient(180deg, hsla(60, 50%, 50%, .45), hsla(0, 100%, 50%, .75));
        filter: inherit;
        -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>

<div id="papa">
        <div id="lrc" data-lrc="花潮lrc在线">花潮lrc在线</div>
        <div id="mplayer">
                <div id="cur">00:00</div>
                <div id="btnplay"></div>
                <div id="dur">00:00</div>
                <div id="prog"></div>
        </div>
        <audio id="aud" src="https://music.163.com/song/media/outer/url?id=31587566.mp3" loop autoplay></audio>
</div>

<script>
(function() {
        let mKey = 0, mFlag = true;
let lrcAr = [
        ,
        ,
        ,
        ,
        ,
        ,
        ,
        ,
        ,
        ,
        ,
        ,
        ,
        ,
       
];
        for(j=0; j<20; j++) {
                let pinpu = document.createElement('span');
                pinpu.className = 'pinpu';
                pinpu.style.cssText += `height: ${Math.floor(Math.random()*50) + 10}px; background: #${Math.random().toString(16).substr(-6)};`;
                btnplay.appendChild(pinpu);
        }
        btnplay.onclick = () => aud.paused ? aud.play() : aud.pause();
        prog.onclick = (e) => aud.currentTime = aud.duration * e.offsetX / prog.offsetWidth;
        aud.addEventListener('seeked', () => calcKey());
        aud.addEventListener('pause', () => mState());
        aud.addEventListener('play', () => mState());
        aud.addEventListener('timeupdate', () => {
                let prg = aud.currentTime * prog.offsetWidth / aud.duration < 6 ? 6 : aud.currentTime * prog.offsetWidth / aud.duration;
                prog.style.setProperty('--ww', prg + 'px');
                cur.innerText = toMin(aud.currentTime);
                dur.innerText = toMin(aud.duration);
                setPinpu();
                for (j = 0; j < lrcAr.length; j++) {
                        if (aud.currentTime >= lrcAr) {
                                cKey = j;
                                if (mKey === j) showLrc(lrcAr);
                                else continue;
                        }
                }
        });
        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 showLrc = (time) => {
                let name = mFlag ? 'cover1' : 'cover2';
                lrc.innerHTML = lrc.dataset.lrc = lrcAr;
                lrc.style.setProperty('--motion', name);
                lrc.style.setProperty('--tt', time + 's');
                lrc.style.setProperty('--state', 'running');
                mKey += 1;
                mFlag = !mFlag;
        };
        let mState = () => lrc.style.setProperty('--state', aud.paused ? 'paused' : 'running');
        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 setPinpu = ()=> {
                let eles = document.querySelectorAll('.pinpu');
                eles.forEach((item) => item.style.height = `${Math.floor(Math.random()*50) + 10}px`);
        };
})();
</script>

马黑黑 发表于 2022-10-31 12:36

一些说明:

https://www.huachaowang.com/forum.php?mod=viewthread&tid=64243&extra=page%3D1

相约爱晚亭 发表于 2022-10-31 13:26

欣赏!学习!

小辣椒 发表于 2022-10-31 13:54

黑黑辛苦,又有新的播放器出来了而且是频谱的{:4_178:}

小辣椒 发表于 2022-10-31 13:55

手机欣赏完美{:4_177:}

红影 发表于 2022-10-31 15:34

这个播放器在帖子里非常漂亮。大风歌,是刘邦的大气豪迈的抱负,发现领袖人物的诗句大都与常人不同,真正的文如其人了。

梦油 发表于 2022-10-31 15:54

气吞山河、排山倒海,真有气势!

醉美水芙蓉 发表于 2022-10-31 17:07

马黑黑 发表于 2022-10-31 18:09

醉美水芙蓉 发表于 2022-10-31 17:07
制作漂亮,这个播放器非常完美!

看看有木有啥问题

马黑黑 发表于 2022-10-31 18:14

梦油 发表于 2022-10-31 15:54
气吞山河、排山倒海,真有气势!

刘邦的气势也是一点一滴积累的

樵歌 发表于 2022-10-31 18:15

气势恢宏!大风起兮云飞扬。

马黑黑 发表于 2022-10-31 18:16

红影 发表于 2022-10-31 15:34
这个播放器在帖子里非常漂亮。大风歌,是刘邦的大气豪迈的抱负,发现领袖人物的诗句大都与常人不同,真正的 ...

刘邦文化不高,不会写诗。得天下后回老家,有感而发,就这么几句:大风起兮云飞扬,威加海内兮归故乡,安得猛士兮守四方。很朴素但有气势,气势是点点滴滴积累而来,从流氓习气到霸气,再渐渐演变为杀气、豪气。

马黑黑 发表于 2022-10-31 18:16

小辣椒 发表于 2022-10-31 13:55
手机欣赏完美

应该可以的

马黑黑 发表于 2022-10-31 18:17

小辣椒 发表于 2022-10-31 13:54
黑黑辛苦,又有新的播放器出来了而且是频谱的

频谱之前是做过的,这个呢,还是未能与音频的高低建立起关系(代码会很多,兼容性目前也未必好)。

马黑黑 发表于 2022-10-31 18:18

相约爱晚亭 发表于 2022-10-31 13:26
欣赏!学习!

感谢支持

马黑黑 发表于 2022-10-31 18:18

樵歌 发表于 2022-10-31 18:15
气势恢宏!大风起兮云飞扬。

若换作你,你的大风歌会比这个豪气

樵歌 发表于 2022-10-31 18:40

马黑黑 发表于 2022-10-31 18:18
若换作你,你的大风歌会比这个豪气

成王败寇,没有运气。{:4_189:}

马黑黑 发表于 2022-10-31 18:59

樵歌 发表于 2022-10-31 18:40
成王败寇,没有运气。

一起都是靠运气,这个道理,在刘邦身上最经典

红影 发表于 2022-10-31 19:47

马黑黑 发表于 2022-10-31 18:16
刘邦文化不高,不会写诗。得天下后回老家,有感而发,就这么几句:大风起兮云飞扬,威加海内兮归故乡,安 ...

最后养成真正的帝王之气。
页: [1] 2 3
查看完整版本: 大风歌(新频谱播放器测试)