酷我音乐频谱跨域外链
本帖最后由 亚伦影音工作室 于 2023-12-19 23:20 编辑 <br /><br /><style type="text/css">#bj{position: relative;width: 1164px;height: 620px;MARGIN-LEFT:-300px;margin-top:0px;;overflow:hidden;background:url('https://www.kumeiwp.com/sub/filestores/2023/02/02/3295f5c9ebd5f999c6bae779d2fef4c0.jpg')no-repeat center / cover;--opt: .2;}
#mplayer{width: 400px; height: 400px; position: absolute; left: 60%;top: 10%;
animation: spin 18s linear infinite; }
@keyframes spin {
0% { transform: rotate(360deg)scale(0.7);filter:hue-rotate(360deg)contrast(100%)brightness(200%); } 50% { transform: rotate(0deg)scale(0.7);filter:hue-rotate(0deg)contrast(100%)brightness(100%); opacity: 1;}100% { transform: rotate(-360deg)scale(0.7);filter:hue-rotate(0deg)contrast(100%)brightness(100%); opacity: 1;}
}
#tmsg {position: absolute;z-index:2 ;
font: normal 12px sans-serif;
color: #ffffff;
top:300px;
left:75%;}
#prog {position: absolute;z-index:2 ;
width: 100%;
height: 3%;
cursor: pointer;
top:97%;
margin:0px 0%;
border-radius: 0px;}
#canv {display: block; position: absolute;width:100%; height: 200px; bottom: 20px; left: 0px;z-index:1 ; animation: sp 1s linear infinite;}
@keyframes sp {
0% { filter:hue-rotate(360deg)contrast(150%)brightness(100%); }
}
</style>
<divid="bj">
<div id="mplayer" onmouseover="this.style.opacity=.04"onmouseout="this.style.opacity=.8">
<svg width="400" height="400">
<polygonpoints="400.00,200.00 2.04,171.54 391.90,256.35 18.07,116.92 368.25,308.13 48.85,69.03 330.97,351.15 91.87,31.75 283.08,381.93 143.65,8.10 228.46,397.96 200.00,0.00 171.54,397.96 256.35,8.10 116.92,381.93 308.13,31.75 69.03,351.15 351.15,69.03 31.75,308.13 381.93,116.92 8.10,256.35 397.96,171.54 0.00,200.00 397.96,228.46 8.10,143.65 381.93,283.08 31.75,91.87 351.15,330.97 69.03,48.85 308.13,368.25 116.92,18.07 256.35,391.90 171.54,2.04 200.00,400.00 228.46,2.04 143.65,391.90 283.08,18.07 91.87,368.25 330.97,48.85 48.85,330.97 368.25,91.87 18.07,283.08 391.90,143.65 2.04,228.46" fill-rule="nonzero | evenodd" fill="#ff0000" stroke="#00f000" stroke-width="1" />
</svg>
</div>
<divid="prog"></div>
<div id="tmsg">00:00 | 00:00</div>
<div data-lrc="" id="lrc"></div>
<canvas id='canv' width="1200" height="250"></canvas>
<audio autoplay="" id="aud" loop="" src="https://mp3.t57.cn:7087/kwlink_d.php?id=324734614.mp3" crossOrigin="anonymous"> </audio>
</div>
<style type="text/css">#lrc {
--state: paused;
--motion: cover2;
--tt: 2s;
--bg: linear-gradient(180deg, #880000, #880000);
position: absolute;z-index: 4;
left: 50%;
transform: translate(-50%);
top: 85%;
font:normal 3em 华文隶书;
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 = `《美人关》
作词:王琪
作曲:王琪
演唱:王琪
编曲:方珲
录音缩混:顾潇予
母带处理:顾潇予
弦乐:国际首席爱乐乐团
唢呐:宋京
竹笛:王华
吉它:崔磊
酒虽好
不是万能的解药
借酒消愁
想醉的人却醉不了
剑在手
斩不断你的妖娆
武功盖世
躲不过你温柔一刀
你让我哭我就哭
你让我笑我就笑
你让我疯我就疯
你让我痴我也逃不掉
自古英雄
难逃美人的圈套
千金散尽难换
红颜一笑
色字头上
一把刀
落花无情莫要
随着流水漂
你让我哭我就哭
你让我笑我就笑
你让我疯我就疯
你让我痴我也逃不掉
自古英雄
难逃美人的圈套
千金散尽难换
红颜一笑
色字头上
一把刀
落花无情莫要
随着流水漂
自古英雄
难逃美人的圈套
千金散尽难换
红颜一笑
色字头上
一把刀
落花无情莫要
随着流水漂
落花无情莫要
随着流水漂`;
/*变量 :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());/*监听查询事件*/
let lrcAr = getLrcAr(lrcStr); /*获得歌词数组*/
})();
mplayer.addEventListener('click', () => { aud.paused ? aud.play() : aud.pause(); });
mplayer.style.animationPlayState = aud.paused ? 'paused' : 'running';
aud.addEventListener('playing', () =>mplayer.style.animationPlayState = 'running');
aud.addEventListener('pause', () =>mplayer.style.animationPlayState = 'paused');
prog.onclick = (e) => {
aud.currentTime = aud.duration * e.offsetX / prog.offsetWidth;
}
aud.addEventListener('timeupdate', () => {
aud.addEventListener('timeupdate', () => {prog.style.background= 'linear-gradient(90deg, #924B0A ,#924B0A,#924B0A ' + aud.currentTime / aud.duration * 100 + '%, #2F4F4F 0)';});
tmsg.innerText = toMin(aud.currentTime) + ' | ' + toMin(aud.duration);
});
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;
};
</script>
<script>
(function () {
let Act = new AudioContext();
let audSrc = Act.createMediaElementSource(aud);
let analyser = Act.createAnalyser();
audSrc.connect(analyser);
analyser.connect(Act.destination);
let ctx = canv.getContext('2d');
let width = canv.width;
let height = canv.height;
let ppColor = ctx.createLinearGradient(350,200,350,0);
ppColor.addColorStop(0.6, '#00ff00');
ppColor.addColorStop(0.4, '#00ff00');
ppColor.addColorStop(0, '#00ff00');
let ppNum = 200;
let voiceHeight = new Uint8Array(analyser.frequencyBinCount);
(function draw() {
analyser.getByteFrequencyData(voiceHeight);
let step = Math.round(voiceHeight.length / ppNum);
ctx.clearRect(0, 0, width, height);
for (let j = 0; j < ppNum; j++) {
let audiheighteight = voiceHeight;
ctx.fillStyle = ppColor;
ctx.fillRect(width / 2 + (j * 8), height, 4, -audiheighteight);
ctx.fillRect(width / 2 - (j * 8), height, 4, -audiheighteight);
}
window.requestAnimationFrame(draw);
})();
canv.onclick = () => aud.paused ? aud.play() : aud.pause();
})();
</script> 问好亚伦老师!谢谢分享!{:4_190:}准备学习模仿一个! 牛人赞一个
看看跨域频谱
欣赏学习 欣赏欣赏{:4_187:} 漂亮的频谱制作{:4_187:} 欣赏佳作,感谢分享 恭喜亚伦老师又找到个跨域的外链地方,这个制作真漂亮,还把太阳花做成了变色播放器按钮,真棒{:4_199:} 响应式频谱也是变色的,歌曲也好听。欣赏亚伦老师好帖{:4_199:} 好看{:6_244:}
页:
[1]