android 歌詞同步實現

來源:互聯網
上載者:User
相信很多朋友都有做過android音樂播放器吧,但只是播放歌曲會不會很單調呢?很多朋友想過要做歌詞同步吧,那麼我就和大家分享一下我的個人經驗吧;
其實歌詞同步的步驟很簡單:
1.解析LRC歌詞檔案
2.LRC 歌詞顯示
3. 歌詞與播放音樂同步

一、讀取歌詞檔案:
/**
* 讀取檔案
* */
public String read(String path){
TreeMap lrc_read = new TreeMap();
String data = "";

try {
File saveFile = new File(path);
FileInputStream stream = new FileInputStream(saveFile);
BufferedReader br = new BufferedReader(new InputStreamReader(
stream, "GB2312"));

int i = 0;
while ((data = br.readLine()) != null) {
data = data.replace("[", "");
data = data.replace("]", "@");

String splistdata[] = data.split("@");
String lrcContenet = splistdata[splistdata.length - 1];
for (int j = 0; j iterator = lrc_read.keySet().iterator();
lrcObject oldval = null;
int i = 0;
StringBuffer sb = new StringBuffer();
while (iterator.hasNext()) {
Object ob = iterator.next();
lrcObject val = (lrcObject) lrc_read.get(ob);
if (oldval == null)
oldval = val;
else {
lrcObject item1 = new lrcObject();
item1 = oldval;
item1.timeline = val.begintime - oldval.begintime;
lrc_map.put(new Integer(i), item1);
sb.append(String.format("[%04d]-[%04d]-%s/n", item1.begintime,
item1.timeline, item1.lrc));
i++;
oldval = val;
}
}
data = sb.toString();
String da = data;

return data;
}

  /**

  * 得到當前現正播放的那一句的下標 不可能找不到,因為最開頭要加一句 自己的句子 ,所以加了以後就不可能找不到了

  *

  * @return 下標

  */

  private int getNowSentenceIndex(long t) {

  for (int i = 0; i

  • 上一篇:AsyncTask
  • 下一篇:Android讀寫Txt文字檔
  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.