玫瑰 发表于 2026-7-13 11:44

欣赏又学习

玫瑰 发表于 2026-7-13 11:44


甜蜜中藏痛处,痛与爱并存
热烈里隐藏清醒,那是通透人世间爱与情

玫瑰 发表于 2026-7-13 11:44

聆听一首歌曲,

玫瑰 发表于 2026-7-13 11:46


<style>
#papa {margin: 100px -150px;width: 1286px;height: 720px;background: url('https://img.wyc520.com.cn/data/attachment/forum/202606/22/153058e0kf3b8ymtmr3mmp.jpg') no-repeat 90% 50%/100px 200px,url('https://img.wyc520.com.cn/data/attachment/forum/202606/22/153058e0kf3b8ymtmr3mmp.jpg') no-repeat 80% 35%/220px 300px, url('https://img.wyc520.com.cn/data/attachment/forum/202606/22/153228r1uh11ryg8ntyo53.jpg') no-repeat center/cover; z-index: 1;display: grid; overflow: hidden;position: relative;}
#aud {position:absolute;bottom: -10px; margin-left:0px;z-index: 60;
    display: block;
    width:102%;clip-path: inset(20% 1% 20% 1%);filter:invert(100%);margin: 0px -14px;
}

#lrc {
      --state: paused;
      --motion: cover2;
      --tt: 2s;
      --bg: linear-gradient(0deg, #ff0000, #ff0000, #ff0000);
      position: absolute;z-index: 6;
      left: 52%;
      transform: translate(-50%);
      top: 480px;
      font:normal 3em 华文新魏;
      font-weight:400;
      color: #eeeeee;
      white-space: pre;
      -webkit-background-clip: text;
      filter:drop-shadow(#000 1px 0 0)drop-shadow(#000 0 1px 0)drop-shadow(#000 -1px 0 0) drop-shadow(#000 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%;}100% { width: 100%;}}
@keyframes cover2 { 0% { width: 0%;}100% { width: 100%;}}

#canvas{position: absolute;width: 55%;z-index: 4;top:340px; left:250px; }
</style>
<div id="papa">
<audio   id="aud"src="https://s2.ananas.chaoxing.com/sv-w8/audio/e6/20/2a/da37d85940ed4d18cd8a6ad814754d2e/audio.mp3" autoplay loopcontrols crossOrigin="anonymous"></audio>
<div data-lrc="亚伦影音工作室" id="lrc" title="歌词显示">亚伦影音工作室</div>
<canvas id="canvas" "></canvas>
</div>
<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); /*获得歌词数组*/
})();
</script>
<script>
window.onload = function () {
      var oAudio = document.getElementById('aud');
   
      // 创建音频上下文对象
      var oCtx = new AudioContext();
      // console.log(oCtx);
      // 创建媒体源,除了audio本身可以获取,也可以通过oCtx对象提供的api进行媒体源操作
      var audioSrc = oCtx.createMediaElementSource(oAudio);
      // 创建分析机
      var analyser = oCtx.createAnalyser();
      // 媒体源与分析机连接
      audioSrc.connect(analyser);
      // 输出的目标:将分析机分析出来的处理结果与目标点(耳机/扬声器)连接
      analyser.connect(oCtx.destination);

      // 利用cancas渐变进行音频绘制
      var ctx = canvas.getContext('2d');
      canvas.width = window.innerWidth;
      canvas.height = window.innerHeight;
      var oW = canvas.width;
      var oH = canvas.height;
      var color1 = ctx.createLinearGradient(oW / 2, oH / 2 - 30, oW / 2, oH / 2 - 100);
      var color2 = ctx.createLinearGradient(oW / 2, oH / 2 + 30, oW / 2, oH / 2 + 100);
      color1.addColorStop(0, '#ffffff');
      color1.addColorStop(.5, '#fff000');
      color1.addColorStop(1, '#00ff00');
      color2.addColorStop(0, '#ffffff');
      color2.addColorStop(.5, '#fff000');
      color2.addColorStop(1, '#00ff00');
      // 音频图的条数
      var count = 200;
      // 缓冲区:进行数据的缓冲处理,转换成二进制数据
      var voiceHeight = new Uint8Array(analyser.frequencyBinCount);
      // console.log(voiceHeight);

      function draw() {
      // 将当前的频率数据复制到传入的无符号字节数组中,做到实时连接
      analyser.getByteFrequencyData(voiceHeight);
      // console.log(voiceHeight);
      // 自定义获取数组里边数据的频步
      var step = Math.round(voiceHeight.length / count);
      ctx.clearRect(0, 0, oW, oH);
      for (var i = 0; i < count; i++) {
          var audioHeight = voiceHeight;
          ctx.fillStyle = color1;// 绘制向上的线条
          ctx.fillRect(oW / 2 + (i * 5), oH / 2, 2, -audioHeight);
          ctx.fillRect(oW / 2 - (i * 5), oH / 2, 2, -audioHeight);
          ctx.fillStyle = color2;// 绘制向下的线条
          ctx.fillRect(oW / 2 + (i * 5), oH / 2, 2, audioHeight);
          ctx.fillRect(oW / 2 - (i * 5), oH / 2, 2, audioHeight);
      }
      window.requestAnimationFrame(draw);
      }
      draw();

    }
</script>

玫瑰 发表于 2026-7-13 11:46

聆听好听的旋律

玫瑰 发表于 2026-7-13 11:47

温柔的眼睛

玫瑰 发表于 2026-7-13 11:47

星星很美丽

玫瑰 发表于 2026-7-13 11:47

美的耀眼

玫瑰 发表于 2026-7-13 11:48

好听的歌曲

玫瑰 发表于 2026-7-13 11:48

百听不厌

玫瑰 发表于 2026-7-13 11:48

让音乐伴随这天

玫瑰 发表于 2026-7-13 11:48

一首情歌。

玫瑰 发表于 2026-7-13 11:49

爱在歌词无不表现淋漓尽致,

玫瑰 发表于 2026-7-13 11:50

娓娓道来诉说唯美的情怀

玫瑰 发表于 2026-7-13 11:51

无论聆听欢快、忧伤的旋律,都是能够自愈快乐源泉。

玫瑰 发表于 2026-7-13 11:55

爱音乐、听音乐,品读美诗,做自己喜欢事情,是一种好习惯、保持好的心情,聆听、好诗意是生活刚刚开始。{:4_204:}

玫瑰 发表于 2026-7-13 12:35

倾听音乐

玫瑰 发表于 2026-7-13 12:36

倾听音乐



玫瑰 发表于 2026-7-13 12:36

倾听音乐




倾听音乐

玫瑰 发表于 2026-7-13 12:37

带来好心情
页: 14 15 16 17 18 19 20 21 22 23 [24] 25 26 27 28 29 30 31 32 33
查看完整版本: 【玫瑰楼】倾听音乐