周旋 - 天涯歌女
本帖最后由 马黑黑 于 2022-9-19 07:25 编辑 <br /><br /><style>#papa { left: -214px; width: 1024px; height: 640px; background: #ccc url('/data/attachment/forum/202209/19/072429vo4tzt453j6soj36.jpg') no-repeat center/cover; box-shadow: 3px 3px 20px #000; display: grid; place-items: center; overflow: hidden; position: relative; z-index: 1; }
#mplayer { position: absolute; left: 10px; bottom: 10px; }
#btnwrap { display: block; fill: #ccc; cursor: pointer; }
#btnwrap:hover { fill: orange; }
#tmsg { fill: snow; stroke: gray; stroke-width: 1px; font: bold 1em sans-serif; }
#lrc { position: absolute; bottom: 10px; right: 100px; font: bold 2em sans-serif; color: transparent; letter-spacing: 2px; background: linear-gradient(-90deg, purple, orange) 100% 100% / 200% 200%; background-clip: text; -webkit-background-clip: text; }
#feather {position: absolute; left: 0; top: 0; width: 50px;offset-distance: 0;offset-path: path("M500 -60 Q300 80, 600 200 T900 640");animation: move 8s linear infinite;}
@keyframes bgMove1 { from { background-position: 0 0; } to { background-position: -100% 0; } }
@keyframes bgMove2 { from { background-position: 0 0; } to { background-position: -100% 0; } }
@keyframes move { to { offset-distance: 100%;} }
</style>
<div id="papa">
<img id="feather" src="/data/attachment/forum/202209/19/072054nefdifokfiaonowf.png" alt="" />
<div id="lrc">花潮lrc在线</div>
<svg id="mplayer" width="120" height="120">
<g id="mama" transform="rotate(-90, 60, 60)" style="cursor: pointer;">
<circle id="track" cx="60" cy="60" r="50" fill="none" stroke-width="10" stroke="rgba(255,255,255,0.65)" />
<circle id="prog" cx="60" cy="60" r="50" fill="none" stroke-width="6" stroke="rgba(57,54,81,0.85)" />
</g>
<g id="btnwrap">
<path id="btnplay" d="M 50 50,50 70,70, 60 z"></path>
<path id="btnpause" d="M 52 50,52 70,57 70,57 50,52 50 z M 60 50,60 70,65 70,65 50,60 50 z"></path>
<path d="M 57 50,60 50,60 70,57 70 z" fill="transparent" />
</g>
<path id="curPath" d="M 20 70 Q 60 0 100 70" fill="none" stroke="none"/>
<path id="durPath" d="M 20 55 Q 60 110 100 55" fill="none" stroke="none"/>
<g id="tmsg">
<text x="34" y="0"><textPath id="curMsg" xlink:href="#curPath" dominant-baseline="text-after-edge">00:00</textPath></text>
<text x="29" y="0"><textPath id="durMsg" xlink:href="#durPath" dominant-baseline="text-before-edge">00:00</textPath></text>
</g>
</svg>
</div>
<script>
let lrcAr = [
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
];
let mKey = 0, mSeek = false, mFlag = true;
let aud = new Audio();
let cc = {
x: 1*track.getAttribute('cx'),
y: 1*track.getAttribute('cy'),
r: 1*track.getAttribute('r'),
sw: 1*track.getAttribute('stroke-width'),
len: track.getTotalLength(),
};
prog.style.strokeDasharray = prog.style.strokeDashoffset =cc.len;
aud.src = 'https://music.163.com/song/media/outer/url?id=1809278238.mp3';
aud.autoplay = true;
aud.loop = true;
mama.onclick = (e) => {
let deg = Math.atan2(e.offsetY - cc.y, e.offsetX - cc.x) * 180 / Math.PI;
deg += (e.offsetX < cc.x && e.offsetY < cc.y) ? 450 : 90;
aud.currentTime = aud.duration * deg / 360;
};
btnwrap.onclick = () => aud.paused ? aud.play() : aud.pause();
aud.addEventListener('pause', () => mState());
aud.addEventListener('play', () => mState());
aud.addEventListener('seeked', () => calcKey());
aud.addEventListener('timeupdate', () => {
prog.style.strokeDashoffset = cc.len - cc.len * aud.currentTime / aud.duration;
curMsg.textContent = toMin(aud.currentTime);
durMsg.textContent = toMin(aud.duration);
for(j=0; j<lrcAr.length; j++) {
if(aud.currentTime >= lrcAr) {
if(mKey === j) showLrc(lrcAr);
else continue;
}
}
});
let mState = () => aud.paused ? (btnplay.style.display = 'block', btnpause.style.display = 'none', lrc.style.animationPlayState = 'paused') : (btnplay.style.display = 'none', btnpause.style.display = 'block', lrc.style.animationPlayState = 'running');
let showLrc = (time) => {
lrc.style.animation = (mFlag ? 'bgMove1 ' : 'bgMove2 ') + time + 's linear forwards';
lrc.innerHTML = lrcAr;
mKey += 1;
mFlag = !mFlag;
}
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 mtime = lrcAr - (aud.currentTime - lrcAr);
showLrc(mtime);
}
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>
代码
<style>
#papa { left: -214px; width: 1024px; height: 640px; background: #ccc url('/data/attachment/forum/202209/19/072429vo4tzt453j6soj36.jpg') no-repeat center/cover; box-shadow: 3px 3px 20px #000; display: grid; place-items: center; overflow: hidden; position: relative; z-index: 1; }
#mplayer { position: absolute; left: 10px; bottom: 10px; }
#btnwrap { display: block; fill: #ccc; cursor: pointer; }
#btnwrap:hover { fill: orange; }
#tmsg { fill: snow; stroke: gray; stroke-width: 1px; font: bold 1em sans-serif; }
#lrc { position: absolute; bottom: 10px; right: 100px; font: bold 2em sans-serif; color: transparent; letter-spacing: 2px; background: linear-gradient(-90deg, purple, orange) 100% 100% / 200% 200%; background-clip: text; -webkit-background-clip: text; }
#feather {position: absolute; left: 0; top: 0; width: 50px;offset-distance: 0;offset-path: path("M500 -60 Q300 80, 600 200 T900 640");animation: move 8s linear infinite;}
@keyframes bgMove1 { from { background-position: 0 0; } to { background-position: -100% 0; } }
@keyframes bgMove2 { from { background-position: 0 0; } to { background-position: -100% 0; } }
@keyframes move { to { offset-distance: 100%;} }
</style>
<div id="papa">
<img id="feather" src="/data/attachment/forum/202209/19/072054nefdifokfiaonowf.png" alt="" />
<div id="lrc">花潮lrc在线</div>
<svg id="mplayer" width="120" height="120">
<g id="mama" transform="rotate(-90, 60, 60)" style="cursor: pointer;">
<circle id="track" cx="60" cy="60" r="50" fill="none" stroke-width="10" stroke="rgba(255,255,255,0.65)" />
<circle id="prog" cx="60" cy="60" r="50" fill="none" stroke-width="6" stroke="rgba(57,54,81,0.85)" />
</g>
<g id="btnwrap">
<path id="btnplay" d="M 50 50,50 70,70, 60 z"></path>
<path id="btnpause" d="M 52 50,52 70,57 70,57 50,52 50 z M 60 50,60 70,65 70,65 50,60 50 z"></path>
<path d="M 57 50,60 50,60 70,57 70 z" fill="transparent" />
</g>
<path id="curPath" d="M 20 70 Q 60 0 100 70" fill="none" stroke="none"/>
<path id="durPath" d="M 20 55 Q 60 110 100 55" fill="none" stroke="none"/>
<g id="tmsg">
<text x="34" y="0"><textPath id="curMsg" xlink:href="#curPath" dominant-baseline="text-after-edge">00:00</textPath></text>
<text x="29" y="0"><textPath id="durMsg" xlink:href="#durPath" dominant-baseline="text-before-edge">00:00</textPath></text>
</g>
</svg>
</div>
<script>
let lrcAr = [
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
,
];
let mKey = 0, mSeek = false, mFlag = true;
let aud = new Audio();
let cc = {
x: 1*track.getAttribute('cx'),
y: 1*track.getAttribute('cy'),
r: 1*track.getAttribute('r'),
sw: 1*track.getAttribute('stroke-width'),
len: track.getTotalLength(),
};
prog.style.strokeDasharray = prog.style.strokeDashoffset =cc.len;
aud.src = 'https://music.163.com/song/media/outer/url?id=1809278238.mp3';
aud.autoplay = true;
aud.loop = true;
mama.onclick = (e) => {
let deg = Math.atan2(e.offsetY - cc.y, e.offsetX - cc.x) * 180 / Math.PI;
deg += (e.offsetX < cc.x && e.offsetY < cc.y) ? 450 : 90;
aud.currentTime = aud.duration * deg / 360;
};
btnwrap.onclick = () => aud.paused ? aud.play() : aud.pause();
aud.addEventListener('pause', () => mState());
aud.addEventListener('play', () => mState());
aud.addEventListener('seeked', () => calcKey());
aud.addEventListener('timeupdate', () => {
prog.style.strokeDashoffset = cc.len - cc.len * aud.currentTime / aud.duration;
curMsg.textContent = toMin(aud.currentTime);
durMsg.textContent = toMin(aud.duration);
for(j=0; j<lrcAr.length; j++) {
if(aud.currentTime >= lrcAr) {
if(mKey === j) showLrc(lrcAr);
else continue;
}
}
});
let mState = () => aud.paused ? (btnplay.style.display = 'block', btnpause.style.display = 'none', lrc.style.animationPlayState = 'paused') : (btnplay.style.display = 'none', btnpause.style.display = 'block', lrc.style.animationPlayState = 'running');
let showLrc = (time) => {
lrc.style.animation = (mFlag ? 'bgMove1 ' : 'bgMove2 ') + time + 's linear forwards';
lrc.innerHTML = lrcAr;
mKey += 1;
mFlag = !mFlag;
}
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 mtime = lrcAr - (aud.currentTime - lrcAr);
showLrc(mtime);
}
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>
本帖最后由 马黑黑 于 2022-9-19 07:34 编辑
本帖:
① 将 svg 播放器(之一)整合到新歌词同步机制的模板上来;
② 修复一个bug,在 JS 的 calcKey 函数:
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 mtime = lrcAr - (aud.currentTime - lrcAr);
showLrc(mtime);
}
之前的模板,请加上红色那句。较早前的测试模板,mKey 变量是另外的名称,如果手头持有,建议换成变量名已经是 mKey 的新模板。 帖子中的背景图,虽能体现那个年头上海繁华的一面,但我们应该能从表象看出中华民族在那个特定的历史时代为此而被迫付出的屈辱。 生活之路,多有艰辛。当下,或许很多人无法理解居无定所的窘境。看看那片羽毛,它随风飘落,身不由己,这就是写照。 我看画面中飘动的羽毛,就像文章中的点睛之笔,道出了这件作品的主题。
想当初,不知有多少人因为偷听周旋的《天涯歌女》而备受责难。 马黑黑 发表于 2022-9-19 07:42
生活之路,多有艰辛。当下,或许很多人无法理解居无定所的窘境。看看那片羽毛,它随风飘落,身不由己,这就 ...
原来羽毛的设计还有这样的寓意,很棒的构思{:4_199:} 黑黑又换了前面那个进度条上来,而且还修复了一个bug,辛苦了{:4_187:} 老上海的气息,欣赏点赞!{:4_185:} 马黑黑 发表于 2022-9-19 07:27
代码
感谢分享好代码,问好!{:4_187:} 醉美水芙蓉 发表于 2022-9-19 11:45
欣赏学习老师新作品!
这个是旧的,旧上海{:4_173:} 梦油 发表于 2022-9-19 09:22
我看画面中飘动的羽毛,就像文章中的点睛之笔,道出了这件作品的主题。
想当初,不知有多少人因为偷听周 ...
当时被定性为靡靡之音,不是俺提议的{:4_170:} 红影 发表于 2022-9-19 10:29
原来羽毛的设计还有这样的寓意,很棒的构思
但如果不说出来能有多少人可以理解呢 梦缘 发表于 2022-9-19 11:17
感谢分享好代码,问好!
代码好不好不知道,尝试吧 红影 发表于 2022-9-19 10:33
黑黑又换了前面那个进度条上来,而且还修复了一个bug,辛苦了
这个bug也是我在调试加餐歌词时发现的。进度调整,总会存在调整到比较后面的甚至就是最后面的,这时发现了报警{:4_173:} 梦缘 发表于 2022-9-19 11:16
老上海的气息,欣赏点赞!
这条街是我小时候玩耍的地方之一 黑黑这个播放器我也是喜欢的,现在更新了前面的,那我以后以这个为准,这个播放器我收藏在我的喜欢的播放器文件夹里面的{:4_173:} 就是路径我还得学习一下 黑黑每天有这么多的现场指导还每天一个帖,佩服的不要不要的{:4_178:}