国产一级a片免费看高清,亚洲熟女中文字幕在线视频,黄三级高清在线播放,免费黄色视频在线看

打開APP
userphoto
未登錄

開通VIP,暢享免費電子書等14項超值服

開通VIP
android 音樂播放器-------歌詞同步 lrc
android 音樂播放器-------歌詞同步 lrc
分類: android高階篇2011-05-24 12:02 671人閱讀 評論(9) 收藏 舉報
lrc格式 :
[al:這首歌所在的唱片集 ]
[ar:歌詞作者 ]
[by:本LRC文件的創(chuàng)建者 ]
[offset:+/- 以毫秒為單位整體時間戳調(diào)整,+增加,-減小 ]
[re:創(chuàng)建此LRC文件的播放器或編輯器 ]
[ti:歌詞(歌曲)的標(biāo)題 ]
[ve:程序的版本 ]
時間標(biāo)記的格式為[mm:ss.xx] 其中mm 為分鐘數(shù),ss 為秒數(shù)并且xx 為百分之一秒
例子:
[ti:愛]
[ar:小虎隊]
[al:華納國語情濃13首]
[by:愛上你了音樂網(wǎng)]
百度百科關(guān)于lrc的解釋:
http://baike.baidu.com/view/80650.htm
[ti:青花瓷]
[ar:周杰倫]
[al:我很忙]
[by:張琪]
[00:00.00]發(fā)送短信18到291199下載該歌曲到手機
[00:01.11]青花瓷
[03:36.49]
[00:21.39]素眉勾勒秋千話北風(fēng)龍轉(zhuǎn)丹
[00:26.08]屏層鳥繪的牡丹一如你梳妝
[00:30.46]黯然騰香透過窗心事我了然
[00:34.93]宣紙上皺邊直尺各一半
[00:39.49]油色渲染侍女圖因為被失藏
[00:43.83]而你嫣然的一笑如含苞待放
[00:48.30]你的美一縷飄散
[00:50.77]去到我去不了的地方
[02:23.97][00:55.77]
[03:01.92][02:25.63][00:56.90]天正在等煙雨
[03:03.57][02:27.91][00:58.99]而我在等你
[03:05.92][02:30.44][01:00.93]炊煙裊裊升起
[03:07.76][02:32.25][01:03.49]隔江千萬里
[03:10.36][02:34.85][01:05.84]在平地書刻你房間上的飄影
[03:14.67][02:38.73][01:09.87]就當(dāng)我為遇見你伏筆
[03:18.83][02:43.35][01:14.34]天正在等煙雨
[03:21.20][02:45.60][01:16.68]而我在等你
[03:23.71][02:48.01][01:18.99]月色被打撈起
[03:25.74][02:50.10][01:21.18]掩蓋了結(jié)局
[03:28.33][02:52.54][01:23.72]如傳世的青花瓷在獨自美麗
[03:32.30][02:56.67][01:27.65]你眼的笑意
[01:50.25]色白花青的景已躍然于碗底
[01:54.69]臨摹宋體落款時卻惦記著你
[01:59.22]你隱藏在藥效里一千年的秘密
[02:03.75]急溪里猶如羞花沾落地
[02:08.32]林外芭蕉 惹咒語
[02:10.57]夢幻的銅綠
[02:12.84]而我路過那江南小鎮(zhèn)的等你
[02:17.19]在潑墨山水畫里
[02:19.75]你從墨色深處被隱去
前面“[ ]”中的數(shù)字表示其后歌詞的開始時間。例如,“[01:50.25]色白花青的景已躍然于碗底”表示在1分50.25秒時,歌詞內(nèi)容是“色白花青的景已躍 然于碗底”。
還有一種形式是“[03:01.92][02:25.63][00:56.90]天正在等煙雨”這種形式常用于賦格部分(俗稱:歌曲的高潮部分),它表示 在 03:01.92, 02:25.63, 00:56.90 時的歌詞都是“天正在等煙雨”。
代碼實現(xiàn),歌詞類
view plain
package com.android.music;
import java.io.BufferedInputStream;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.Collections;
import java.util.Comparator;
import java.util.Vector;
import android.util.Log;
public class LRCUtils {
private static final String TAG = "LRCUtils";
MediaPlayActivity mediaPlay;
private static Vector<timelrc> lrclist;
private boolean IsLyricExist = false;
private int lastLine = 0;
public LRCUtils(MediaPlayActivity mediaPlayActivity) {
mediaPlay = mediaPlayActivity;
}
public void RefreshLRC(int current)
{
if (IsLyricExist){
for(int i = 0; i < lrclist.size(); i++)
{
if(current < lrclist.get(i).getTimePoint())
if(i == 0 || current >= lrclist.get(i-1).getTimePoint())
{
Log.d(TAG,"string = "+lrclist.get(i-1).getLrcString());
mediaPlay.setLRCText(lrclist.get(i-1).getLrcString(),lastLine!=(i-1));
lastLine = i-1;
//                      playlrcText.setText(lrclist.get(i-1).getLrcString());
}
}
}
}
public void ReadLRC(File f)
{
try
{
if (!f.exists())
{
Log.d(TAG,"not exit the lrc file");
IsLyricExist = false;
//              strLRC = main.getResources().getString(R.string.lrcservice_no_lyric_found);
}
else
{
lrclist = new Vector<timelrc>();
IsLyricExist = true;
InputStream is = new BufferedInputStream(new FileInputStream(f));
BufferedReader br = new BufferedReader(new InputStreamReader(is, GetCharset(f)));
String strTemp = "";
while ((strTemp = br.readLine()) != null)
{
//                  Log.d(TAG,"strTemp = "+strTemp);
strTemp = AnalyzeLRC(strTemp); // ???з??? LRC
}
br.close();
is.close();
Collections.sort(lrclist, new Sort());
for(int i=0;i<lrclist.size();i++){
Log.d(TAG,"time = "+lrclist.get(i).getTimePoint()+"   string = "+lrclist.get(i).getLrcString());
}
}
}
catch (Exception e)
{
e.printStackTrace();
}
}
private String AnalyzeLRC(String LRCText)
{
try
{
int pos1 = LRCText.indexOf("["); // ????????????
int pos2 = LRCText.indexOf("]"); // ????????????
// ????????????????????λ?????????[????
if (pos1 == 0 && pos2 != -1)
{// ???
Long time[] = new Long[GetPossiblyTagCount(LRCText)];
time[0] = TimeToLong(LRCText.substring(pos1 + 1, pos2)); // ???????ε????
if (time[0] == -1) // ??????????
return ""; // LRCText
String strLineRemaining = LRCText;
int i = 1;
while (pos1 == 0 && pos2 != -1)
{
strLineRemaining = strLineRemaining.substring(pos2 + 1); // ??μ?????
pos1 = strLineRemaining.indexOf("[");
pos2 = strLineRemaining.indexOf("]");
if (pos2 != -1)
{
time[i] = TimeToLong(strLineRemaining.substring(pos1 + 1, pos2));
if (time[i] == -1) // ??????????
return ""; // LRCText
i++;
}
}
timelrc tl = new timelrc();
for (int j = 0; j < time.length; j++)
{
if (time[j] != null)
{
//                      Log.d(TAG,"time["+j+"] = "+time[j].intValue()+"    strLineRemaining = "+strLineRemaining);
tl.setTimePoint(time[j].intValue());
tl.setLrcString(strLineRemaining);
lrclist.add(tl);
tl = new timelrc();
//                      map.put(time[j], strLineRemaining);
//                      lstTimeStamp.add(time[j]);
}
}
return strLineRemaining;
}
else
return "";
}
catch (Exception e)
{
return "";
}
}
private int GetPossiblyTagCount(String Line)
{
String strCount1[] = Line.split("http://[");
String strCount2[] = Line.split("http://]");
if (strCount1.length == 0 && strCount2.length == 0)
return 1;
else if (strCount1.length > strCount2.length)
return strCount1.length;
else
return strCount2.length;
}
public long TimeToLong(String Time)
{
try
{
String[] s1 = Time.split(":");
int min = Integer.parseInt(s1[0]);
String[] s2 = s1[1].split("http://.");
int sec = Integer.parseInt(s2[0]);
int mill = 0;
if (s2.length > 1)
mill = Integer.parseInt(s2[1]);
return min * 60 * 1000 + sec * 1000 + mill * 10;
}
catch (Exception e)
{
return -1;
}
}
public String GetCharset(File file){
String charset = "GBK";
byte[] first3Bytes = new byte[3];
try
{
boolean checked = false;
BufferedInputStream bis = new BufferedInputStream(new FileInputStream(file));
bis.mark(0);
int read = bis.read(first3Bytes, 0, 3);
if (read == -1)
return charset;
if (first3Bytes[0] == (byte) 0xFF && first3Bytes[1] == (byte) 0xFE)
{
charset = "UTF-16LE";
checked = true;
}
else if (first3Bytes[0] == (byte) 0xFE && first3Bytes[1] == (byte) 0xFF)
{
charset = "UTF-16BE";
checked = true;
}
else if (first3Bytes[0] == (byte) 0xEF && first3Bytes[1] == (byte) 0xBB && first3Bytes[2] == (byte) 0xBF)
{
charset = "UTF-8";
checked = true;
}
bis.reset();
if (!checked)
{
int loc = 0;
while ((read = bis.read()) != -1)
{
loc++;
if (read >= 0xF0)
break;
if (0x80 <= read && read <= 0xBF) // ????????BF???μ???????GBK
break;
if (0xC0 <= read && read <= 0xDF)
{
read = bis.read();
if (0x80 <= read && read <= 0xBF) // ????(0xC0-0xDF),(0x80-xBF)???????GB??????
continue;
else
break;
}
else if (0xE0 <= read && read <= 0xEF)
{// ??п??????????????С
read = bis.read();
if (0x80 <= read && read <= 0xBF)
{
read = bis.read();
if (0x80 <= read && read <= 0xBF)
{
charset = "UTF-8";
break;
}
else
break;
}
else
break;
}
}
}
bis.close();
}
catch (Exception e)
{
e.printStackTrace();
}
return charset;
}
private class Sort implements Comparator<timelrc> {
public Sort() {
}
public int compare(timelrc tl1, timelrc tl2) {
return sortUp(tl1, tl2);
}
private int sortUp(timelrc tl1, timelrc tl2) {
if (tl1.getTimePoint() < tl2.getTimePoint())
return -1;
else if (tl1.getTimePoint() > tl2.getTimePoint())
return 1;
else
return 0;
}
}
public static class timelrc {
private String lrcString;
private int sleepTime;
private int timePoint;
timelrc() {
lrcString = null;
sleepTime = 0;
timePoint = 0;
}
public void setLrcString(String lrc) {
lrcString = lrc;
}
public void setSleepTime(int time) {
sleepTime = time;
}
public void setTimePoint(int tPoint) {
timePoint = tPoint;
}
public String getLrcString() {
return lrcString;
}
public int getSleepTime() {
return sleepTime;
}
public int getTimePoint() {
return timePoint;
}
};
}
實現(xiàn)思路:
定義一個類,timelrc,用來存放每一句歌詞的內(nèi)容和時間,每當(dāng)播放的歌曲的時間改變時,即顯示播放的seekbar改變時,刷新歌詞RefreshLRC(int),并將取得的歌詞的getLrcString()顯示到應(yīng)用程序中。
使用方法:
在音樂播放的activity界面,獲取當(dāng)前播放歌曲的path,歌詞路徑。
view plain
private void getLrcPath(String path) {
Log.d(TAG,"path = "+path);
if (path != null) {
path = path.substring(0, path.lastIndexOf(".")).concat(".lrc");
File file = new File(path);
lrcService.ReadLRC(file);
}
}
通過該函數(shù)的調(diào)用,如上類會將歌詞存儲起來。
當(dāng)播放時間改變時,調(diào)用lrcService.RefreshLRC(current);  刷新
在播放界面顯示正在播放的歌詞內(nèi)容
public void setLRCText(String lrcString,boolean changeLine) {
if(changeLine){
flipperLrc.showNext();
}
playlrcText.setText(lrcString);
}
(未完待續(xù)。。。)
分享到:
上一篇:android天氣預(yù)報----google開源天氣API,SAX解析
下一篇:android音樂播放器之----天天動聽
本站僅提供存儲服務(wù),所有內(nèi)容均由用戶發(fā)布,如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請點擊舉報
打開APP,閱讀全文并永久保存 查看更多類似文章
猜你喜歡
類似文章
青花瓷歌詞賞析
青花瓷(視頻歌詞)
詩朗誦:《 青花瓷》(歌詞改編)
周杰倫的《青花瓷》
周杰倫演唱歌曲《青花瓷》簡譜
天青色等煙雨,而我在等你
更多類似文章 >>
生活服務(wù)
分享 收藏 導(dǎo)長圖 關(guān)注 下載文章
綁定賬號成功
后續(xù)可登錄賬號暢享VIP特權(quán)!
如果VIP功能使用有故障,
可點擊這里聯(lián)系客服!

聯(lián)系客服