un

您所在的位置:网站首页 网易云如何设置动态歌词 un

un

2024-07-17 15:12:00| 来源: 网络整理| 查看: 265

uni-app歌词滚动效果实现 在这里插入图片描述

这个就是我实现的效果,有兴趣的话就继续往下了解叭~

我是用的网易云的api请求的歌曲

网易云网址:网易云音乐API

为了以防大家复制报错,我用的图片是远程图片

{{item.words}}

接下来就是js中的内容

export default { data() { return { playbool: false, url: "", lyric: "", maxTime: "", arr: "", nowtimes: 0, ok: true, seconds: 0, play: true, nowlirics: '', top: '10px', scrollTop: 0, height: "" } }, onLoad() { var that = this var http = "https://tree.xingyuncm.cn/" // 请求歌词 uni.request({ url: http + '/lyric', method: "GET", data: { id: "1297802566" }, success: (tik) => { var left = tik.data.lrc.lyric.split("\n"); // console.log(left) that.lyric = tik.data.lrc.lyric; // 声明一个空数组 var arr = [] left.forEach((val, i) => { var words = val.split("]") //分割歌词 var time = words[0].slice(1, 10) //选择从下标为1到下标为10的字符串 // 向arr数组添加内容(时间和歌词) arr.push({ // 歌词时间转换 time: ((time.slice(0, 2) - 0) * 60) + (time.slice(3, 5) - 0) + ((time.slice(6, 9) - 0) / 1000), //歌词时间转换为秒 words: words[1] ? words[1] : "" }) }) that.arr = arr // console.log(that.arr); that.maxTime = arr[arr.length - 2].time; // 请求歌曲链接 wx.request({ url: http + '/song/url', method: "GET", data: { id: "1297802566" }, success: (res) => { // console.log(res.data.data[0].url) var that = this; const bgAudioMannager = uni.getBackgroundAudioManager(); bgAudioMannager.title = "lll"; bgAudioMannager.singer = "lll"; bgAudioMannager.src = res.data.data[0].url; // 当前进度除以总时长 bgAudioMannager.onTimeUpdate(function() { // console.log(bgAudioMannager.duration, "总时间") // console.log(bgAudioMannager.currentTime, "当前时间"); that.nowtimes = Number(bgAudioMannager.currentTime); var realtime = Number(bgAudioMannager.currentTime) for (var i = 1; i var newi = i - 1; that.nowlirics = newi; that.top = (newi * -30) + 250 + "px"; // console.log(that.top) var height = 250 - newi * 30 // console.log(height); that.height = height break; } } }) bgAudioMannager.onEnded(() => { bgAudioMannager.play() }); } }) } }) }, methods: { // 播放 onBegin() { this.playbool = false; // 获取背景音频管理器播放 const bgAudioMannager = uni.getBackgroundAudioManager(); bgAudioMannager.play() }, // 暂停 onStop() { // 获取背景音频管理器暂停 this.playbool = true; const bgAudioMannager = uni.getBackgroundAudioManager(); bgAudioMannager.pause() }, moved(e) { // 拖动进度条跳转到指定时间 const bgAudioMannager = uni.getBackgroundAudioManager(); bgAudioMannager.seek(e.detail.value) this.nowtimes = e.detail.value; }, } }

最后就是样式了

.other-big { height: 700rpx; overflow: hidden; overflow-y: scroll; line-height: 60rpx; padding-bottom: 300rpx; } .wrap { width: 80%; } .other-width { display: flex; justify-content: center; margin-top: 10%; } .other-img image { width: 5vh; height: 5vh; margin: 1%; } .other-img { background-color: #DBF1E1; width: 50%; border-radius: 50rpx; display: flex; justify-content: center; padding: 2%; } .other-flex { display: flex; justify-content: center; } .other { transform: translateY(150px); height: 30px; }

这些就是歌词滚动的全过程,代码里面有注释哦,快去试试吧!



【本文地址】

公司简介

联系我们

今日新闻


点击排行

实验室常用的仪器、试剂和
说到实验室常用到的东西,主要就分为仪器、试剂和耗
不用再找了,全球10大实验
01、赛默飞世尔科技(热电)Thermo Fisher Scientif
三代水柜的量产巅峰T-72坦
作者:寞寒最近,西边闹腾挺大,本来小寞以为忙完这
通风柜跟实验室通风系统有
说到通风柜跟实验室通风,不少人都纠结二者到底是不
集消毒杀菌、烘干收纳为一
厨房是家里细菌较多的地方,潮湿的环境、没有完全密
实验室设备之全钢实验台如
全钢实验台是实验室家具中较为重要的家具之一,很多

推荐新闻


    图片新闻

    实验室药品柜的特性有哪些
    实验室药品柜是实验室家具的重要组成部分之一,主要
    小学科学实验中有哪些教学
    计算机 计算器 一般 打孔器 打气筒 仪器车 显微镜
    实验室各种仪器原理动图讲
    1.紫外分光光谱UV分析原理:吸收紫外光能量,引起分
    高中化学常见仪器及实验装
    1、可加热仪器:2、计量仪器:(1)仪器A的名称:量
    微生物操作主要设备和器具
    今天盘点一下微生物操作主要设备和器具,别嫌我啰嗦
    浅谈通风柜使用基本常识
     众所周知,通风柜功能中最主要的就是排气功能。在

    专题文章

      CopyRight 2018-2019 实验室设备网 版权所有 win10的实时保护怎么永久关闭