MP3的时候ipod能显示歌词吗吗

Android实现歌曲播放时歌词同步显示具体思路
转载 & & 作者:
歌曲播放时歌词同步显示,我们需要读取以上歌词文件的每一行转换成成一个个歌词实体,可根据当前播放器的播放进度与每句歌词的开始时间,得到当前屏幕中央高亮显示的那句歌词
我们需要读取以上歌词文件的每一行转换成成一个个歌词实体:
代码如下: public class LyricObject {
// 开始时间
// 结束时间
// 单句歌词用时 public S // 单句歌词 }
可根据当前播放器的播放进度与每句歌词的开始时间,得到当前屏幕中央高亮显示的那句歌词。在UI线程中另起线程,通过回调函数 onDraw() 每隔100ms重新绘制屏幕,实现歌词平滑滚动的动画效果。MainActivity代码如下:
代码如下: import java.io.IOE import android.app.A import android.media.MediaP import android.net.U import android.os.B import android.os.E import android.os.H import android.view.V import android.view.View.OnClickL import android.widget.B import android.widget.SeekB import android.widget.SeekBar.OnSeekBarChangeL public class MainActivity extends Activity { /** Called when the activity is first created. */ private LyricView lyricV private MediaPlayer mediaP private B private SeekBar seekB private String mp3P private int INTERVAL=45;//歌词每行的间隔 @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // this.requestWindowFeature(Window.FEATURE_NO_TITLE); // getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN); setContentView(R.layout.main); mp3Path = Environment.getExternalStorageDirectory().getAbsolutePath() + "/LyricSync/1.mp3"; lyricView = (LyricView) findViewById(R.id.mylrc); mediaPlayer = new MediaPlayer(); // this.requestWindowFeature(Window.FEATURE_NO_TITLE); ResetMusic(mp3Path); SerchLrc(); lyricView.SetTextSize(); button = (Button) findViewById(R.id.button); button.setText("播放"); seekBar = (SeekBar) findViewById(R.id.seekbarmusic); seekBar.setOnSeekBarChangeListener(new OnSeekBarChangeListener() { @Override public void onStopTrackingTouch(SeekBar seekBar) { // TODO Auto-generated method stub } @Override public void onStartTrackingTouch(SeekBar seekBar) { // TODO Auto-generated method stub } @Override public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) { // TODO Auto-generated method stub if (fromUser) { mediaPlayer.seekTo(progress); lyricView.setOffsetY(220 - lyricView.SelectIndex(progress) * (lyricView.getSIZEWORD() + INTERVAL-1)); } } }); button.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { // TODO Auto-generated method stub if (mediaPlayer.isPlaying()) { button.setText("播放"); mediaPlayer.pause(); } else { button.setText("暂停"); mediaPlayer.start(); lyricView.setOffsetY(220 - lyricView.SelectIndex(mediaPlayer.getCurrentPosition()) * (lyricView.getSIZEWORD() + INTERVAL-1)); } } }); mediaPlayer.setOnCompletionListener(new MediaPlayer.OnCompletionListener() { @Override public void onCompletion(MediaPlayer mp) { ResetMusic(mp3Path); lyricView.SetTextSize(); lyricView.setOffsetY(200); mediaPlayer.start(); } }); seekBar.setMax(mediaPlayer.getDuration()); new Thread(new runable()).start(); } public void SerchLrc() { String lrc = mp3P lrc = lrc.substring(0, lrc.length() - 4).trim() + ".lrc".trim(); LyricView.read(lrc); lyricView.SetTextSize(); lyricView.setOffsetY(350); } public void ResetMusic(String path) { mediaPlayer.reset(); try { mediaPlayer.setDataSource(mp3Path); mediaPlayer.prepare(); } catch (IllegalArgumentException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IllegalStateException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } class runable implements Runnable { @Override public void run() { // TODO Auto-generated method stub while (true) { try { Thread.sleep(100); if (mediaPlayer.isPlaying()) { lyricView.setOffsetY(lyricView.getOffsetY() - lyricView.SpeedLrc()); lyricView.SelectIndex(mediaPlayer.getCurrentPosition()); seekBar.setProgress(mediaPlayer.getCurrentPosition()); mHandler.post(mUpdateResults); } } catch (InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); } } } } Handler mHandler = new Handler(); Runnable mUpdateResults = new Runnable() { public void run() { lyricView.invalidate(); // 更新视图 } }; }
歌词View的代码如下:
代码如下: import java.io.BufferedR import java.io.F import java.io.FileInputS import java.io.FileNotFoundE import java.io.IOE import java.io.InputStreamR import java.util.I import java.util.TreeM import java.util.regex.M import java.util.regex.P import android.content.C import android.graphics.C import android.graphics.C import android.graphics.P import android.util.AttributeS import android.util.L import android.view.MotionE import android.view.V public class LyricView extends View{ private static TreeMap&Integer, LyricObject& lrc_ private float mX; //屏幕X轴的中点,此值固定,保持歌词在X中间显示 private float offsetY; //歌词在Y轴上的偏移量,此值会根据歌词的滚动变小 private static boolean blLrc= private float touchY; //当触摸歌词View时,保存为当前触点的Y轴坐标 private float touchX; private boolean blScrollView= private int lrcIndex=0; //保存歌词TreeMap的下标 private int SIZEWORD=0;//显示歌词文字的大小值 private int INTERVAL=45;//歌词每行的间隔 Paint paint=new Paint();//画笔,用于画不是高亮的歌词 Paint paintHL=new Paint(); //画笔,用于画高亮的歌词,即当前唱到这句歌词 public LyricView(Context context){ super(context); init(); } public LyricView(Context context, AttributeSet attrs) { super(context, attrs); init(); } /* (non-Javadoc) * @see android.view.View#onDraw(android.graphics.Canvas) */ @Override protected void onDraw(Canvas canvas) { if(blLrc){ paintHL.setTextSize(SIZEWORD); paint.setTextSize(SIZEWORD); LyricObject temp=lrc_map.get(lrcIndex); canvas.drawText(temp.lrc, mX, offsetY+(SIZEWORD+INTERVAL)*lrcIndex, paintHL); // 画当前歌词之前的歌词 for(int i=lrcIndex-1;i&=0;i--){ temp=lrc_map.get(i); if(offsetY+(SIZEWORD+INTERVAL)*i&0){
} canvas.drawText(temp.lrc, mX, offsetY+(SIZEWORD+INTERVAL)*i, paint); } // 画当前歌词之后的歌词 for(int i=lrcIndex+1;i&lrc_map.size();i++){ temp=lrc_map.get(i); if(offsetY+(SIZEWORD+INTERVAL)*i&600){
} canvas.drawText(temp.lrc, mX, offsetY+(SIZEWORD+INTERVAL)*i, paint); } } else{ paint.setTextSize(25); canvas.drawText("找不到歌词", mX, 310, paint); } super.onDraw(canvas); } /* (non-Javadoc) * @see android.view.View#onTouchEvent(android.view.MotionEvent) */ @Override public boolean onTouchEvent(MotionEvent event) { // TODO Auto-generated method stub System.out.println("bllll==="+blScrollView); float tt=event.getY(); if(!blLrc){ //return super.onTouchEvent(event); return super.onTouchEvent(event); } switch(event.getAction()){ case MotionEvent.ACTION_DOWN: touchX=event.getX();
case MotionEvent.ACTION_MOVE: touchY=tt-touchY; offsetY=offsetY+touchY;
case MotionEvent.ACTION_UP: blScrollView=
} public void init(){ lrc_map = new TreeMap&Integer, LyricObject&(); offsetY=320; paint=new Paint(); paint.setTextAlign(Paint.Align.CENTER); paint.setColor(Color.GREEN); paint.setAntiAlias(true); paint.setDither(true); paint.setAlpha(180); paintHL=new Paint(); paintHL.setTextAlign(Paint.Align.CENTER); paintHL.setColor(Color.RED); paintHL.setAntiAlias(true); paintHL.setAlpha(255); } /** * 根据歌词里面最长的那句来确定歌词字体的大小 */ public void SetTextSize(){ if(!blLrc){
} int max=lrc_map.get(0).lrc.length(); for(int i=1;i&lrc_map.size();i++){ LyricObject lrcStrLength=lrc_map.get(i); if(max&lrcStrLength.lrc.length()){ max=lrcStrLength.lrc.length(); } } SIZEWORD=320/ } protected void onSizeChanged(int w, int h, int oldw, int oldh) { mX = w * 0.5f; super.onSizeChanged(w, h, oldw, oldh); } /** * 歌词滚动的速度 * * @return 返回歌词滚动的速度 */ public Float SpeedLrc(){ float speed=0; if(offsetY+(SIZEWORD+INTERVAL)*lrcIndex&220){ speed=((offsetY+(SIZEWORD+INTERVAL)*lrcIndex-220)/20); } else if(offsetY+(SIZEWORD+INTERVAL)*lrcIndex & 120){ Log.i("speed", "speed is too fast!!!"); speed = 0; } // if(speed&0.2){ // speed=0.2f; // }
} /** * 按当前的歌曲的播放时间,从歌词里面获得那一句 * @param time 当前歌曲的播放时间 * @return 返回当前歌词的索引值 */ public int SelectIndex(int time){ if(!blLrc){ return 0; } int index=0; for(int i=0;i&lrc_map.size();i++){ LyricObject temp=lrc_map.get(i); if(temp.begintime&time){ ++ } } lrcIndex=index-1; if(lrcIndex&0){ lrcIndex=0; } return lrcI } /** * 读取歌词文件 * @param file 歌词的路径 * */ public static void read(String file) { TreeMap&Integer, LyricObject& lrc_read =new TreeMap&Integer, LyricObject&(); String data = ""; try { File saveFile=new File(file); // System.out.println("是否有歌词文件"+saveFile.isFile()); if(!saveFile.isFile()){ blLrc=
} blLrc= //System.out.println("bllrc==="+blLrc); FileInputStream stream = new FileInputStream(saveFile);// context.openFileInput(file); BufferedReader br = new BufferedReader(new InputStreamReader(stream,"GB2312")); int i = 0; Pattern pattern = Pattern.compile("\\d{2}"); while ((data = br.readLine()) != null) { // System.out.println("++++++++++++&&"+data); data = data.replace("[","");//将前面的替换成后面的 data = data.replace("]","@"); String splitdata[] =data.split("@");//分隔 if(data.endsWith("@")){ for(int k=0;k&splitdata.k++){ String str=splitdata[k]; str = str.replace(":","."); str = str.replace(".","@"); String timedata[] =str.split("@"); Matcher matcher = pattern.matcher(timedata[0]); if(timedata.length==3 && matcher.matches()){ int m = Integer.parseInt(timedata[0]); //分 int s = Integer.parseInt(timedata[1]); //秒 int ms = Integer.parseInt(timedata[2]); //毫秒 int currTime = (m*60+s)*1000+ms*10; LyricObject item1= new LyricObject(); item1.begintime = currT item1.lrc = ""; lrc_read.put(currTime,item1); } } } else{ String lrcContenet = splitdata[splitdata.length-1]; for (int j=0;j&splitdata.length-1;j++) { String tmpstr = splitdata[j]; tmpstr = tmpstr.replace(":","."); tmpstr = tmpstr.replace(".","@"); String timedata[] =tmpstr.split("@"); Matcher matcher = pattern.matcher(timedata[0]); if(timedata.length==3 && matcher.matches()){ int m = Integer.parseInt(timedata[0]); //分 int s = Integer.parseInt(timedata[1]); //秒 int ms = Integer.parseInt(timedata[2]); //毫秒 int currTime = (m*60+s)*1000+ms*10; LyricObject item1= new LyricObject(); item1.begintime = currT item1.lrc = lrcC lrc_read.put(currTime,item1);// 将currTime当标签 item1当数据 插入TreeMap里 i++; } } } } stream.close(); } catch (FileNotFoundException e) { } catch (IOException e) { } /* * 遍历hashmap 计算每句歌词所需要的时间 */ lrc_map.clear(); data =""; Iterator&Integer& iterator = lrc_read.keySet().iterator(); LyricObject oldval = int i =0; while(iterator.hasNext()) { Object ob =iterator.next(); LyricObject val = (LyricObject)lrc_read.get(ob); if (oldval==null) oldval = else { LyricObject item1= new LyricObject(); item1 = item1.timeline = val.begintime-oldval. lrc_map.put(new Integer(i), item1); i++; oldval = } if (!iterator.hasNext()) { lrc_map.put(new Integer(i), val); } } } /** * @return the blLrc */ public static boolean isBlLrc() { return blL } /** * @return the offsetY */ public float getOffsetY() { return offsetY; } /** * @param offsetY the offsetY to set */ public void setOffsetY(float offsetY) { this.offsetY = offsetY; } /** * @return 返回歌词文字的大小 */ public int getSIZEWORD() { return SIZEWORD; } /** * 设置歌词文字的大小 * @param sIZEWORD the sIZEWORD to set */ public void setSIZEWORD(int sIZEWORD) { SIZEWORD = sIZEWORD; } }
xml布局文件如下:
代码如下: &SPAN style="FONT-SIZE: 18px"&&STRONG&&?xml version="1.0" encoding="utf-8"?& &RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:background="#FFFFFF" & &com.music.lyricsync.LyricView android:id="@+id/mylrc" android:layout_width="fill_parent" android:layout_height="fill_parent" android:layout_marginBottom="50dip" android:layout_marginTop="50dip" /& &LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentBottom="true" android:orientation="horizontal" & &Button android:id="@+id/button" android:layout_width="wrap_content" android:layout_height="wrap_content" /& &SeekBar android:id="@+id/seekbarmusic" android:layout_width="205px" android:layout_height="wrap_content" android:layout_gravity="center_vertical" android:layout_marginBottom="5px" android:progress="0" /& &/LinearLayout& &/RelativeLayout& &/STRONG&&/SPAN&
您可能感兴趣的文章:
大家感兴趣的内容
12345678910
最近更新的内容
常用在线小工具是不是MP3都可以显示歌词?那么歌词需要下载吗?_百度知道
是不是MP3都可以显示歌词?那么歌词需要下载吗?
我有更好的答案
并且把文件名改成一样的呵呵,一般是支持LRC格式的歌词,现在很多网站可以下载的,歌曲的是.mp3或者.wma一类的.lrc..-_-#不过主要还是看机子的说明上可不可以。如果可以的话://www.51lrcgc,一般现在的新款都应该支持了吧。当然前提是要有屏幕.,注意:是完全一样的文件名,包括标点空格一类的,唯一的不同就是扩展名部分,歌词是。然后听歌的时候就会自动显示歌词咯~呵呵,常用的比较全的是这里:歌词下载之后,放到MP3里面,一定要和歌曲放在同一个文件夹里面
采纳率:40%
不是 那要看你的MP3是否有这个功能一般来说 你把歌下载 歌词会一起下载的
是,如果你不会下载歌词,就下载个酷狗(直接托MP3里)或者千千静听(右击歌名,转移到磁盘就可以了)。
歌词文件的后缀名是.lrc带得有这个文件的就是歌词了
其他1条回答
为您推荐:
其他类似问题
歌词的相关知识
换一换
回答问题,赢新手礼包
个人、企业类
违法有害信息,请在下方选择后提交
色情、暴力
我们会通过消息、邮箱等方式尽快将举报结果通知您。查看: 回复:14
如何让mp3在车载导航里也能显示出歌词?[待解决]
rel="nofollow" href="http://my.pcauto.com.cn//fan/"
target="_blank" rel="nofollow" id="follow粉丝
rel="nofollow" href="http://my.pcauto.com.cn//pick/"
target="_blank" rel="nofollow" id="fan精华
最后修改IP: 59.50.40.100
您好,精华帖至少要有15张图片,文字不少200个字!并且是原创内容,布局合理。
楼主 电梯直达 楼
如何让mp3在车载导航里也能显示出歌词?&
如果你对以下车友回答满意,请设置一个推荐答案!
相关提问:
申请精华帖
您的申请已经提交,请耐心等待审核
1、审核通常是1-3个工作日 2、审核结果我们会通过系统消息给您答复
申请精华帖
您已经超过申请限制,不可再申请
您的申请连续三次被驳回,已经无法再申请精华帖,谢谢你对我们的支持!如有疑问,可以 投诉/建议&&
申请精华帖
您有发现精华的慧眼,赞一个!
1、我们会在1-3个工作日内完成审核
申请精华帖
此贴已经申请精华中,谢谢您的支持!
1、我们会在1-3个工作日内完成审核
申请精华帖
您好,该帖子经过审核后,发现内容不符合精华要求,无法申请成为精华,谢谢你的支持!
申请精华帖
抱歉,帖子还没达到精华标准
精华帖至少要有15张图片,文字不少于200个字!您的帖子未达到要求,不能申请精华。 查看精华帖标准
rel="nofollow" href="http://my.pcauto.com.cn//fan/"
target="_blank" rel="nofollow" id="follow粉丝
rel="nofollow" href="http://my.pcauto.com.cn//pick/"
target="_blank" rel="nofollow" id="fan0精华
最后修改IP: 192.168.238.242
rel="nofollow" href="http://my.pcauto.com.cn//fan/"
target="_blank" rel="nofollow" id="follow粉丝
rel="nofollow" href="http://my.pcauto.com.cn//pick/"
target="_blank" rel="nofollow" id="fan精华
最后修改IP: 59.50.40.100
rel="nofollow" href="http://my.pcauto.com.cn//fan/"
target="_blank" rel="nofollow" id="follow粉丝
rel="nofollow" href="http://my.pcauto.com.cn//pick/"
target="_blank" rel="nofollow" id="fan精华
最后修改IP: 59.50.40.100
rel="nofollow" href="http://my.pcauto.com.cn//fan/"
target="_blank" rel="nofollow" id="follow粉丝
rel="nofollow" href="http://my.pcauto.com.cn//pick/"
target="_blank" rel="nofollow" id="fan精华
最后修改IP: 59.50.40.100
rel="nofollow" href="http://my.pcauto.com.cn/7079862/fan/"
target="_blank" rel="nofollow" id="follow粉丝
rel="nofollow" href="http://my.pcauto.com.cn/7079862/pick/"
target="_blank" rel="nofollow" id="fan精华
最后修改IP: 124.133.113.251
rel="nofollow" href="http://my.pcauto.com.cn//fan/"
target="_blank" rel="nofollow" id="follow粉丝
rel="nofollow" href="http://my.pcauto.com.cn//pick/"
target="_blank" rel="nofollow" id="fan精华
最后修改IP: 192.168.238.242
rel="nofollow" href="http://my.pcauto.com.cn//fan/"
target="_blank" rel="nofollow" id="follow粉丝
rel="nofollow" href="http://my.pcauto.com.cn//pick/"
target="_blank" rel="nofollow" id="fan精华
最后修改IP: 192.168.31.144/14.23.152.198
楼主千万不要自夸我的车多宽多宽,再宽你能宽过奢侈宽体轿跑吗?
rel="nofollow" href="http://my.pcauto.com.cn//fan/"
target="_blank" rel="nofollow" id="follow粉丝
rel="nofollow" href="http://my.pcauto.com.cn//pick/"
target="_blank" rel="nofollow" id="fan精华
最后修改IP: 192.168.31.144/14.23.152.198
楼主千万不要自夸我的车多宽多宽,再宽你能宽过奢侈宽体轿跑吗?
rel="nofollow" href="http://my.pcauto.com.cn//fan/"
target="_blank" rel="nofollow" id="follow粉丝
rel="nofollow" href="http://my.pcauto.com.cn//pick/"
target="_blank" rel="nofollow" id="fan精华
最后修改IP: 192.168.237.43
我试过,没有成功
rel="nofollow" href="http://my.pcauto.com.cn//fan/"
target="_blank" rel="nofollow" id="follow粉丝
rel="nofollow" href="http://my.pcauto.com.cn//pick/"
target="_blank" rel="nofollow" id="fan精华
最后修改IP: 192.168.237.44
rel="nofollow" href="http://my.pcauto.com.cn//fan/"
target="_blank" rel="nofollow" id="follow粉丝
rel="nofollow" href="http://my.pcauto.com.cn//pick/"
target="_blank" rel="nofollow" id="fan精华
最后修改IP: 192.168.240.195
下载歌词就好了
rel="nofollow" href="http://my.pcauto.com.cn//fan/"
target="_blank" rel="nofollow" id="follow粉丝
rel="nofollow" href="http://my.pcauto.com.cn//pick/"
target="_blank" rel="nofollow" id="fan精华
最后修改IP: 192.168.240.192
&发表于&15:55&下载歌词就好了
我试过&不可以哎不管歌词放在哪个文件夹都不显示
rel="nofollow" href="http://my.pcauto.com.cn//fan/"
target="_blank" rel="nofollow" id="follow粉丝
rel="nofollow" href="http://my.pcauto.com.cn//pick/"
target="_blank" rel="nofollow" id="fan精华
最后修改IP: 223.247.34.81
这是WM系统,现在不热门了,应该有这样的软件,我最早的智能手机就是这系统。
rel="nofollow" href="http://my.pcauto.com.cn//fan/"
target="_blank" rel="nofollow" id="follow粉丝
rel="nofollow" href="http://my.pcauto.com.cn//pick/"
target="_blank" rel="nofollow" id="fan精华
最后修改IP: 116.229.199.13
冷车启动发动机声音有无哒哒哒的声音呢?站外面听的情况下
只可添加一张图片,多张图片请选高级模式
您需要登录后才可以发帖&&&&&&│&&&&│&&&&
新用户注册有机会领99元现金红包(限时活动)
锋驭更多相关问题正在加载验证码......
请先拖动验证码到相应位置

我要回帖

更多关于 vv7能显示歌词吗 的文章

 

随机推荐