一个算是比较完整的android MP3 LRC歌词滚动高亮显示

前面的几篇文章应该说是差不多完成了,现在主要做一些更新,修改一些东西。

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链接http://download.csdn.net/source/3214201

 

你可能感兴趣的:(android,Class,float)