Lyric LRC格式檔案解析
LRC格式沒有多少複雜,是以希望找一個簡單易用的程式。不過網上找到的代碼不是捆綁了其它的邏輯,封裝太差,就是容錯太少,是以萌生了自己寫一個的念頭。
沒有找到标準,隻有一個 維基簡介
項目在 https://github.com/authorfu/LrcParser
1. From a lyric file content to all readable lyric
String lyricString="[00:12.00]Line 1 lyrics\n"+
"[00:17.20]Line 2 lyrics\n"+
"[00:21.10]Line 3 lyrics";
BufferedReader reader =new BufferedReader(new StringReader(lyricString));
Lyric lyric;
try{
lyric=LrcParser.create(reader);
String[] contents=lyric.findAllContents();
System.out.println(Arrays.toString(contents));
}catch(IOException e){
e.printStackTrace();
}
result:
[Line 1 lyrics, Line 2 lyrics, Line 3 lyrics]
2.More info
ArrayList<Sentence> sentences=lyric.findAllSentences(-1,-1);
System.out.println(sentences);
result:
[{index:0|12000(Line 1 lyrics)17199}, {index:1|17200(Line 2 lyrics)21099}, {index:2|21100(Line 3 lyrics)-1}]
Sentence
private long fromTime=-1;// 開始時間
private long toTime=-1;// 結束時間
private String content="";// 歌詞
private int index=-1;//第幾句歌詞
3.ID Tags
ID Tags info can be found by a
HashTable<String,String> tags= lyric.getTags();
4. more useful methods
see
com.github.authorfu.lrcparser.Lyric