首先,要下载对应的歌词Lrc文件。因为对应的lrc文件中有固定格式,如:[00:00.00]荷塘月色。前面是时间,可以通过字符串操作得到,进而转换为毫秒数或者其他格式。
我的想法:
1>先创建一个工具包类:
import java.awt.Color;
public class LrcDao {
private double time = 0.0f;
private String lyric = "";
/*
* 获取时间
*/
public double getTime(){
return time;
}
/*
* 设置时间
* tine :被设置成的时间
*/
public void setTime(double time){
this.time = time;
}
/*
* 设置时间
* time:被设置成的时间字符串,格式为毫秒数
*/
//str[0]为分钟,str[1]为秒钟,str[2]为小数点后的数字
public void setTime(String time ){
String str[] = time.split(":|\\.");
//this.time = Integer.parseInt(str[0])*60 + Integer.parseInt(str[1]) + Integer.parseInt(str[2])*0.01;
//将这个时间化为毫秒数
this.time = Integer.parseInt(str[0])*60*1000 + Integer.parseInt(str[1])*1000 + Integer.parseInt(str[2]);
}
/*
* 获取歌词
*/
public String getLyric(){
return lyric;
}
public void setLyric(String lyric){
this.lyric = lyric;
}
}
2>以上工具包类的作用是存储每一行歌词,每一行歌词创建一个以上的对象,每个对象中有两个属性:这一行显示的时间和这一行显示的字符串。
接下来就要读取Lrc文件,进而处理字符串,
import jav