当前位置: 移动技术网 > 移动技术>移动开发>Android > 比较完整的android MP3 LRC歌词滚动高亮显示(附源码)

比较完整的android MP3 LRC歌词滚动高亮显示(附源码)

2019年07月24日  | 移动技术网移动技术  | 我要评论

1.以前的滚动只是安行来刷新,现在不是按行来滚动了,其实就是在一定时间内整体往上移动,比如说在1s内刷新10次,由于认得肉眼看起来像是滚动。

关键代码如下:

复制代码 代码如下:

        float plus = currentdunringtime == 0 ? 30
                : 30
                        + (((float) currenttime - (float) sentencttime) / (float) currentdunringtime)
                        * (float) 30;
        // 向上滚动 这个是根据歌词的时间长短来滚动,整体上移
        canvas.translate(0, -plus);

plus就是每次移动的大小,它就是根据歌词所持续的时间来计算的,时间越长,plus的值就越小。具体的看代码了。

下面就是获取歌词的信息:

复制代码 代码如下:

 public void updateindex(long time) {
  this.currenttime = time;
  // 歌词序号
  index = mlyric.getnowsentenceindex(time);
  if (index != -1) {
   sentence sen = sentencelist.get(index);
   sentencttime = sen.getfromtime();
   currentdunringtime = sen.getduring();
  }
 }

以下就是跟新线程:
复制代码 代码如下:

 class uiupdatethread implements runnable {
  long time = 100; // 滚动速度
  public void run() {
   while (mp.isplaying()) {
    lyricview.updateindex(mp.getcurrentposition());
    mhandler.post(mupdateresults);
    try {
     thread.sleep(time);
    } catch (interruptedexception e) {
     // todo auto-generated catch block
     e.printstacktrace();
    }
   }
  }
 }

project链接:

如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网