马黑黑 发表于 2022-2-16 20:51

星辰如眸(单曲播放器+歌词同步)

本帖最后由 加林森 于 2022-2-17 14:20 编辑 <br /><br /><style>
#bigPa { position: relative; width: 1000px; left:-203px; height: 569px; background:#333 url('/data/attachment/forum/202202/16/205041jgtngnddt1xnxpvg.jpg') no-repeat center/cover; box-shadow: 0 0 0 2px #111;}
#gcDiv { width: 300px; float: right; }
#paDiv { position: relative; top: 10px; width: 220px; display: flex; align-items: center; border: 1px solid olive; border-radius: 8px 0px 8px 0px; background: rgba(0,0,0,.8); box-shadow: 1px 1px 2px #000; }
#jindu { position: relative; width: 200px; height: 8px; line-height: 8px; font-size: 10px; color: #eee; text-align: center; background: linear-gradient(90deg, olive, green) no-repeat; background-size: 8px 0px; cursor: pointer; }
#btn-ro { width: 20px; height: 20px; line-height: 20px; font-size: 12px; background: linear-gradient(blue, silver, red); outline:none; color: white; border-radius: 50%; text-align: center; cursor: pointer; animation: rol linear 2s infinite; }
#lrcDiv { position: relative; top: 20px; color: #A4D1D7; font-size: 1em; text-shadow: 1px 1px 2px #000; }
#btn-ro:hover { opacity: 0.8; }
#btn-ro:active { opacity: 1; }
@keyframes rol { to { transform:rotate(360deg); } }
</style>

<div id="bigPa">
        <div id="gcDiv">
                <!-- 播放器开始 -->
                <div id="paDiv">
                        <div id="btn-ro">·</div><!-- 播放按钮 -->
                        <div id="jindu"><div id="jd-go"></div></div>
                </div>
                <!-- 播放器结束 -->
                <div id="lrcDiv">歌词同步显示</div>
        </div>
</div>

<script language="javascript">

var lrcAr=[
["00:00.00","星辰如眸 (《一见倾心》电视剧片头曲) - 司南"],
["00:02.15","词:浅紫"],
["00:02.49","曲:浅紫"],
["00:02.83","编曲:王德隆"],
["00:03.40","和声:司南"],
["00:03.85","和声编写:涂忆"],
["00:04.55","吉他:陈麒元"],
["00:05.15","混音:陈秋洁"],
["00:05.73","制作人:江潮"],
["00:06.27","监制:浅紫"],
["00:06.75","歌曲制作公司:众匠(北京)文化传媒有限公司"],
["00:16.41","清晨 烟雨 黄昏 倾世温柔"],
["00:23.97","少年 戎装 驰骋 星辰如眸"],
["00:31.47","眼神 温暖 坚定 漫笑浮生"],
["00:38.18","是一段风华 一指流砂 蓦然回首"],
["00:46.33","冬天 雪花飘落的季节"],
["00:52.20","你怀中却似春天 花香布满了世间"],
["00:59.60","良辰好景入夏天 树荫遮住了眷恋"],
["01:07.16","沁心于你在秋天 情深绵绵散落"],
["01:14.72","叶翩翩 情渐渐"],
["01:24.05","清晨 烟雨 黄昏 倾世温柔"],
["01:31.50","少年 戎装 驰骋 星辰如眸"],
["01:38.84","眼神 温暖 坚定 漫笑浮生"],
["01:45.66","是一段风华 一指流砂 蓦然回首"],
["01:54.01","冬天 雪花飘落的季节"],
["01:59.66","你怀中却似春天 花香布满了世间"],
["02:07.13","良辰好景入夏天 树荫遮住了眷恋"],
["02:14.60","沁心于你在秋天 情深绵绵散落"],
["02:22.09","叶翩翩 情渐渐"],
["02:27.86","冬天 雪花飘落的季节"],
["02:33.34","你怀中却似春天 花香布满了世间"],
["02:40.87","良辰好景入夏天 树荫遮住了眷恋"],
["02:48.37","沁心于你在秋天 情深绵绵散落"],
["02:55.89","叶翩翩 情渐渐"],
];

var lrcDiv = document.getElementById('lrcDiv');
var btn = document.getElementById('btn-ro');
var jindu = document.getElementById('jindu');
var aud = document.createElement('audio');
// 音乐地址放在下行引号内
aud.src = "http://www.kumeiwp.com/sub/filestores/2022/02/15/cb5d2b49bf5b7fa52e682ce6c6b0c405.mp3";
aud.loop = true;
aud.autoplay = true;
aud.addEventListener('ended', function() { btn.style.animationPlayState="paused"; }, true);
aud.addEventListener('timeupdate', tmMsg, true);

function tmMsg(){ //进度条
        let auT = Math.floor(aud.duration - aud.currentTime);
        let auM = auT / 60;
        let auMs = parseInt(auM);
        if (auMs <10) auMs = "0" + auMs;
        let auS = auT % 60;
        let auSs = Math.round(auS);
        if (auSs < 10) auSs = "0" + auSs;
        jindu.innerHTML = "- " + auMs +":" + auSs;
        let jd = (100*aud.currentTime)/aud.duration;
        jindu.style.backgroundSize = jd+ "% 8px";
}

jindu.onclick = function(){ //进度控制
        let w = offset(jindu,"left");
        let x = (event.clientX - w) * aud.duration / jindu.clientWidth;
        aud.currentTime = x;
}

function offset(obj,direction){//获取父级元素偏移总量
        let offsetDir = "offset" + direction.toUpperCase()+direction.substring(1);
        let realNum = obj;
        let positionParent = obj.offsetParent;
        while(positionParent != null){
                realNum += positionParent;
                positionParent = positionParent.offsetParent;
        }
        return realNum;
}

btn.onclick = function(){ // 暂停&播放
        aud.paused ? (aud.play(), btn.style.animationPlayState="running") : (aud.pause(), btn.style.animationPlayState="paused");
}

//处理lrc歌词数组:时间转换成秒
for(j=0; j<lrcAr.length; j++){
        lrcAr = toSec(lrcAr);
}

//lrc时间信息转为秒
function toSec(lrcTime) {
        let tmpAr = lrcTime.split(':');
        lrcTime = tmpAr * 60 + parseInt(tmpAr);
        return lrcTime;
}

//同步显示歌词
aud.ontimeupdate = function() {
        let tt = this.currentTime;
        for(j=0; j<lrcAr.length; j++){
                if(tt > lrcAr) lrcDiv.innerHTML = lrcAr;
        }
}

</script>

大猫咪 发表于 2022-9-28 20:43

马黑黑 发表于 2022-9-28 20:41
黑黑更健康

https://gimg2.baidu.com/image_search/src=http%3A%2F%2F5b0988e595225.cdn.sohucs.com%2Fimages%2F20191228%2F0f19a9f28b574af8b8838ab3dc881535.jpeg&refer=http%3A%2F%2F5b0988e595225.cdn.sohucs.com&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=auto?sec=1666960977&t=a5bf226c2eddaff99278fd0ba5163931

非常同意{:5_117:}

加林森 发表于 2022-2-16 20:55

有点扯字呢?

加林森 发表于 2022-2-16 20:57

结果是我的电脑用久了,浏览器累了吧。

加林森 发表于 2022-2-16 20:58

老黑这个制作好科幻哦。

马黑黑 发表于 2022-2-16 21:02

加林森 发表于 2022-2-16 20:57
结果是我的电脑用久了,浏览器累了吧。

刷新一下,或退出浏览器再进,必要时重新启动电脑。这个帖子,不消耗什么资源,我专门看过的。

马黑黑 发表于 2022-2-16 21:02

加林森 发表于 2022-2-16 20:58
老黑这个制作好科幻哦。

就是歌词同步吧,中午做好的

马黑黑 发表于 2022-2-16 21:05

全帖代码分享:

<style>
#bigPa { position: relative; left:-203px; width: 1000px; height: 569px; background:#333 url('/data/attachment/forum/202202/16/205041jgtngnddt1xnxpvg.jpg') no-repeat center/cover; box-shadow: 0 0 0 2px #111;}
#gcDiv { width: 300px; float: right; }
#paDiv { position: relative; top: 10px; width: 220px; display: flex; align-items: center; border: 1px solid olive; border-radius: 8px 0px 8px 0px; background: rgba(0,0,0,.8); box-shadow: 1px 1px 2px #000; }
#jindu { position: relative; width: 200px; height: 8px; line-height: 8px; font-size: 10px; color: #eee; text-align: center; background: linear-gradient(90deg, olive, green) no-repeat; background-size: 8px 0px; cursor: pointer; }
#btn-ro { width: 20px; height: 20px; line-height: 20px; font-size: 12px; background: linear-gradient(blue, silver, red); outline:none; color: white; border-radius: 50%; text-align: center; cursor: pointer; animation: rol linear 2s infinite; }
#lrcDiv { position: relative; top: 20px; color: #A4D1D7; font-size: 1em; text-shadow: 1px 1px 2px #000; }
#btn-ro:hover { opacity: 0.8; }
#btn-ro:active { opacity: 1; }
@keyframes rol { to { transform:rotate(360deg); } }
</style>

<div id="bigPa">
        <div id="gcDiv">
                <!-- 播放器开始 -->
                <div id="paDiv">
                        <div id="btn-ro">·</div><!-- 播放按钮 -->
                        <div id="jindu"><div id="jd-go"></div></div>
                </div>
                <!-- 播放器结束 -->
                <div id="lrcDiv">歌词同步显示</div>
        </div>
</div>

<script language="javascript">

var lrcAr=[
["00:00.00","星辰如眸 (《一见倾心》电视剧片头曲) - 司南"],
["00:02.15","词:浅紫"],
["00:02.49","曲:浅紫"],
["00:02.83","编曲:王德隆"],
["00:03.40","和声:司南"],
["00:03.85","和声编写:涂忆"],
["00:04.55","吉他:陈麒元"],
["00:05.15","混音:陈秋洁"],
["00:05.73","制作人:江潮"],
["00:06.27","监制:浅紫"],
["00:06.75","歌曲制作公司:众匠(北京)文化传媒有限公司"],
["00:16.41","清晨 烟雨 黄昏 倾世温柔"],
["00:23.97","少年 戎装 驰骋 星辰如眸"],
["00:31.47","眼神 温暖 坚定 漫笑浮生"],
["00:38.18","是一段风华 一指流砂 蓦然回首"],
["00:46.33","冬天 雪花飘落的季节"],
["00:52.20","你怀中却似春天 花香布满了世间"],
["00:59.60","良辰好景入夏天 树荫遮住了眷恋"],
["01:07.16","沁心于你在秋天 情深绵绵散落"],
["01:14.72","叶翩翩 情渐渐"],
["01:24.05","清晨 烟雨 黄昏 倾世温柔"],
["01:31.50","少年 戎装 驰骋 星辰如眸"],
["01:38.84","眼神 温暖 坚定 漫笑浮生"],
["01:45.66","是一段风华 一指流砂 蓦然回首"],
["01:54.01","冬天 雪花飘落的季节"],
["01:59.66","你怀中却似春天 花香布满了世间"],
["02:07.13","良辰好景入夏天 树荫遮住了眷恋"],
["02:14.60","沁心于你在秋天 情深绵绵散落"],
["02:22.09","叶翩翩 情渐渐"],
["02:27.86","冬天 雪花飘落的季节"],
["02:33.34","你怀中却似春天 花香布满了世间"],
["02:40.87","良辰好景入夏天 树荫遮住了眷恋"],
["02:48.37","沁心于你在秋天 情深绵绵散落"],
["02:55.89","叶翩翩 情渐渐"],
];

var lrcDiv = document.getElementById('lrcDiv');
var btn = document.getElementById('btn-ro');
var jindu = document.getElementById('jindu');
var aud = document.createElement('audio');
// 音乐地址放在下行引号内
aud.src = "http://www.kumeiwp.com/sub/filestores/2022/02/15/cb5d2b49bf5b7fa52e682ce6c6b0c405.mp3";
aud.loop = true;
aud.autoplay = true;
aud.addEventListener('ended', function() { btn.style.animationPlayState="paused"; }, true);
aud.addEventListener('timeupdate', tmMsg, true);

function tmMsg(){ //进度条
        let auT = Math.floor(aud.duration - aud.currentTime);
        let auM = auT / 60;
        let auMs = parseInt(auM);
        if (auMs <10) auMs = "0" + auMs;
        let auS = auT % 60;
        let auSs = Math.round(auS);
        if (auSs < 10) auSs = "0" + auSs;
        jindu.innerHTML = "- " + auMs +":" + auSs;
        let jd = (100*aud.currentTime)/aud.duration;
        jindu.style.backgroundSize = jd+ "% 8px";
}

jindu.onclick = function(){ //进度控制
        let w = offset(jindu,"left");
        let x = (event.clientX - w) * aud.duration / jindu.clientWidth;
        aud.currentTime = x;
}

function offset(obj,direction){//获取父级元素偏移总量
        let offsetDir = "offset" + direction.toUpperCase()+direction.substring(1);
        let realNum = obj;
        let positionParent = obj.offsetParent;
        while(positionParent != null){
                realNum += positionParent;
                positionParent = positionParent.offsetParent;
        }
        return realNum;
}

btn.onclick = function(){ // 暂停&播放
        aud.paused ? (aud.play(), btn.style.animationPlayState="running") : (aud.pause(), btn.style.animationPlayState="paused");
}

//处理lrc歌词数组:时间转换成秒
for(j=0; j<lrcAr.length; j++){
        lrcAr = toSec(lrcAr);
}

//lrc时间信息转为秒
function toSec(lrcTime) {
        let tmpAr = lrcTime.split(':');
        lrcTime = tmpAr * 60 + parseInt(tmpAr);
        return lrcTime;
}

//同步显示歌词
aud.ontimeupdate = function() {
        let tt = this.currentTime;
        for(j=0; j<lrcAr.length; j++){
                if(tt > lrcAr) lrcDiv.innerHTML = lrcAr;
        }
}

</script>

加林森 发表于 2022-2-16 21:12

马黑黑 发表于 2022-2-16 21:02
就是歌词同步吧,中午做好的

我得慢慢学了。

加林森 发表于 2022-2-16 21:14

马黑黑 发表于 2022-2-16 21:02
刷新一下,或退出浏览器再进,必要时重新启动电脑。这个帖子,不消耗什么资源,我专门看过的。

嗯嗯,我知道的。

马黑黑 发表于 2022-2-16 21:33

加林森 发表于 2022-2-16 21:14
嗯嗯,我知道的。

挺好的

马黑黑 发表于 2022-2-16 21:34

加林森 发表于 2022-2-16 21:12
我得慢慢学了。

这个,会用就好

加林森 发表于 2022-2-16 21:36

马黑黑 发表于 2022-2-16 21:33
挺好的

谢谢!

加林森 发表于 2022-2-16 21:37

马黑黑 发表于 2022-2-16 21:34
这个,会用就好

一定要制作出来给你看看。{:5_154:}

马黑黑 发表于 2022-2-16 21:40

加林森 发表于 2022-2-16 21:37
一定要制作出来给你看看。

应该没什么问题,找到好的lrc歌词并制作好JS数组

加林森 发表于 2022-2-16 21:47

马黑黑 发表于 2022-2-16 21:40
应该没什么问题,找到好的lrc歌词并制作好JS数组

嗯嗯,明白的。

小辣椒 发表于 2022-2-16 22:38

啊···这个是歌词同步啊{:4_178:}

马黑黑 发表于 2022-2-16 22:40

小辣椒 发表于 2022-2-16 22:38
啊···这个是歌词同步啊

你才发现?在我的地儿有说明

小辣椒 发表于 2022-2-16 22:40

我起码得星期五晚上做了

小辣椒 发表于 2022-2-16 22:43

马黑黑 发表于 2022-2-16 22:40
你才发现?在我的地儿有说明

我去看看

红影 发表于 2022-2-17 09:35

加林森 发表于 2022-2-16 20:55
有点扯字呢?

评分后会这样,估计和评分系统存在的问题有关,我这里也是。刷新就好了。
页: [1] 2 3
查看完整版本: 星辰如眸(单曲播放器+歌词同步)