Unity UGUI简单的音频播放+读歌词(实现类似 QQ音乐,网易云音乐歌词滚动)

  • 效果图 (demo下载地址 demo下载地址
    在这里插入图片描述

  • 简单代码

     /// <summary>
    /// 解析数据歌词
    /// </summary>
    /// <param name="dataList">数据</param>
    /// <returns></returns>
    void ProcessingData(List<string> dataList)
    {
        // 所有数据
        for (int i = 0; i < dataList.Count; i++)
        {
            string[] strarry = dataList[i].Split(new char[] { '[', ']' });
    
            if (strarry != null && strarry.Length > 0)
            {
                for (int j = 1; j < strarry.Length; j++)
                {
                    string tempstr = strarry[j];
                    //这是标题 --- 创作者
                    if (tempstr.StartsWith("ti") || tempstr.StartsWith("ar") || tempstr.StartsWith("al") || tempstr.StartsWith("by") || tempstr.StartsWith("offset"))
                    {
                        string[] strarry1 = tempstr.Split(':');
                        //valuePairs.Add(strarry1[0], strarry1[1]);
                    }
                    else
                    {
                        //这是内容
                        if (tempstr.Contains(":"))
                        {
                            string[] strarry1 = tempstr.Split(':');
    
                            float m = float.Parse(strarry1[0]) * 60;
                            float s = float.Parse(strarry1[1]);
                            //ms ms = (m + s).ToString();
                            //Debug.Log(ms);
                            //时间
                            floattimelist.Add(m + s);
                        }
                        else
                        {
                            //句子
                            stringlyriclist.Add(tempstr);
                        }
                    }
                }
            }
        }
    }
    
      /// <summary>
        /// 显示移动lyric位置
        /// </summary>
        /// <param name="index"></param>
        void ShowLrc(int index)
        {
            if (index >= stringlyriclist.Count / 4)
            {
                temp -= offest;
                if (temp >= 0)
                {
                    ScrollRect.verticalNormalizedPosition = temp;
                    Debug.Log(temp);
                }
            }
            texts[index].color = Color.green;
            if (index > 0 && index < stringlyriclist.Count)
            {
                texts[index - 1].color = Color.gray;
            }
    
        }
    
  • 文章最后附上(demo下载地址 demo下载地址
    在这里插入图片描述

Logo

魔乐社区(Modelers.cn) 是一个中立、公益的人工智能社区,提供人工智能工具、模型、数据的托管、展示与应用协同服务,为人工智能开发及爱好者搭建开放的学习交流平台。社区通过理事会方式运作,由全产业链共同建设、共同运营、共同享有,推动国产AI生态繁荣发展。

更多推荐