下载手机软件的时候,随意的下了个天天动听,觉得喜欢,就仿照着他的UI做了个简单的音乐播放器,还不完善,只是在工作之余随便做做,贴图:

本文来自CSDN丹丹博库,转载请必须注明出处:

http://blog.csdn.net/dany1202/archive/2011/06/07/6529030.aspx

说明:

存储在SD卡中的歌曲,会自动被扫描到MediaStore.java中,通过

cur = getContentResolver().query(MediaStore.Audio.Media.EXTERNAL_CONTENT_URI,
new String[]{MediaStore.Audio.Media.TITLE,
MediaStore.Audio.Media.DURATION,
MediaStore.Audio.Media.ARTIST,
MediaStore.Audio.Media._ID},
null, null, null);

查询出自己想要的字段值。再用Listview加载cur,就可以检索出对应歌曲列表信息。

将时间的值转换为时间格式的字符串,从源码中代码:

public static String makeTimeString(Context context, long secs) { String durationformat = context.getString( secs < 3600 ? R.string.durationformatshort : R.string.durationformatlong); /* Provide multiple arguments so the format can be changed easily * by modifying the xml. */ sFormatBuilder.setLength(0); final Object[] timeArgs = sTimeArgs; timeArgs[0] = secs / 3600; timeArgs[1] = secs / 60; timeArgs[2] = (secs / 60) % 60; timeArgs[3] = secs; timeArgs[4] = secs % 60; return sFormatter.format(durationformat, timeArgs).toString(); }

至于歌词文件的解析,请参考之前的一篇文章,介绍 android音乐播放器之歌词解析的。

至于歌词内容的刷新显示界面,主要用到一个TextView类,不断的OnDraw,贴该类代码:

package com.android.music.play; import java.util.Vector; import android.content.Context; import android.graphics.Canvas; import android.graphics.Color; import android.graphics.Paint; import android.graphics.Typeface; import android.util.AttributeSet; import android.util.Log; import android.widget.TextView; public class LyricText extends TextView { private static final String TAG = "LyricView"; private Paint NotCurrentPaint; // 非当前歌词画笔 private Paint CurrentPaint; // 当前歌词画笔 private int notCurrentPaintColor = Color.WHITE;// 非当前歌词画笔 颜色 private int CurrentPaintColor = Color.RED; // 当前歌词画笔 颜色 private Typeface Texttypeface = Typeface.SERIF; private Typeface CurrentTexttypeface = Typeface.DEFAULT_BOLD; private float width; private int brackgroundcolor = 0xff00ff00; // 背景颜色 private float lrcTextSize = 22; // 歌词大小 private float CurrentTextSize = 24; // private Align = Paint.Align.CENTER; public float mTouchHistoryY; private int height; private long currentDunringTime; // 当前行歌词持续的时间,用该时间来sleep private int TextHeight = 50; // 每一行的间隔 private boolean lrcInitDone = false;// 是否初始化完毕了 public int index = 0; private static Vector<timelrc> lrclist; private long currentTime; private long sentenctTime; public void SetTimeLrc(Vector<timelrc> list){ lrclist = list; } public Paint getNotCurrentPaint() { return NotCurrentPaint; } public void setNotCurrentPaint(Paint notCurrentPaint) { NotCurrentPaint = notCurrentPaint; } public boolean isLrcInitDone() { return lrcInitDone; } public Typeface getCurrentTexttypeface() { return CurrentTexttypeface; } public void setCurrentTexttypeface(Typeface currrentTexttypeface) { CurrentTexttypeface = currrentTexttypeface; } public void setLrcInitDone(boolean lrcInitDone) { this.lrcInitDone = lrcInitDone; } public float getLrcTextSize() { return lrcTextSize; } public void setLrcTextSize(float lrcTextSize) { this.lrcTextSize = lrcTextSize; } public float getCurrentTextSize() { return CurrentTextSize; } public void setCurrentTextSize(float currentTextSize) { CurrentTextSize = currentTextSize; } public Paint getCurrentPaint() { return CurrentPaint; } public void setCurrentPaint(Paint currentPaint) { CurrentPaint = currentPaint; } public int getNotCurrentPaintColor() { return notCurrentPaintColor; } public void setNotCurrentPaintColor(int notCurrentPaintColor) { this.notCurrentPaintColor = notCurrentPaintColor; } public int getCurrentPaintColor() { return CurrentPaintColor; } public void setCurrentPaintColor(int currrentPaintColor) { CurrentPaintColor = currrentPaintColor; } public Typeface getTexttypeface() { return Texttypeface; } public void setTexttypeface(Typeface texttypeface) { Texttypeface = texttypeface; } public int getBrackgroundcolor() { return brackgroundcolor; } public void setBrackgroundcolor(int brackgroundcolor) { this.brackgroundcolor = brackgroundcolor; } public int getTextHeight() { return TextHeight; } public void setTextHeight(int textHeight) { TextHeight = textHeight; } public LyricText(Context context) { super(context); init(); } public LyricText(Context context, AttributeSet attr) { super(context, attr); init(); } public LyricText(Context context, AttributeSet attr, int i) { super(context, attr, i); init(); } private void init() { setFocusable(true); // 非高亮部分 NotCurrentPaint = new Paint(); NotCurrentPaint.setAntiAlias(true); NotCurrentPaint.setTextAlign(Paint.Align.CENTER); // 高亮部分 当前歌词 CurrentPaint = new Paint(); CurrentPaint.setAntiAlias(true); // CurrentPaint.setColor(CurrentPaintColor); CurrentPaint.setTextAlign(Paint.Align.CENTER); } protected void onDraw(Canvas canvas) { super.onDraw(canvas); canvas.drawColor(brackgroundcolor); NotCurrentPaint.setColor(notCurrentPaintColor); CurrentPaint.setColor(CurrentPaintColor); NotCurrentPaint.setTextSize(lrcTextSize); // NotCurrentPaint.setColor(notCurrentPaintColor); NotCurrentPaint.setTypeface(Texttypeface); CurrentPaint.setTextSize(lrcTextSize); CurrentPaint.setTypeface(CurrentTexttypeface); if (index == -1) return; // float plus = 5; float plus = currentDunringTime == 0 ? 20 : 20 + (((float) currentTime - (float) sentenctTime) / (float) currentDunringTime) * (float) 20; // 向上滚动 这个是根据歌词的时间长短来滚动,整体上移 canvas.translate(0, -plus); // 先画当前行,之后再画他的前面和后面,这样就保持当前行在中间的位置 try { canvas.drawText(lrclist.get(index).getLrcString(), width / 2, height / 2, CurrentPaint); // canvas.translate(0, plus); float tempY = height / 2; // 画出本句之前的句子 for (int i = index - 1; i >= 0; i--) { // Sentence sen = list.get(i); // 向上推移 tempY = tempY - TextHeight; if (tempY < 0) { break; } canvas.drawText(lrclist.get(i).getLrcString(), width / 2, tempY, NotCurrentPaint); // canvas.translate(0, TextHeight); } tempY = height / 2; // 画出本句之后的句子 for (int i = index + 1; i < lrclist.size(); i++) { // 往下推移 tempY = tempY + TextHeight; if (tempY > height) { break; } canvas.drawText(lrclist.get(i).getLrcString(), width / 2, tempY, NotCurrentPaint); // canvas.translate(0, TextHeight); } } catch (Exception ex) { ex.printStackTrace(); } } protected void onSizeChanged(int w, int h, int ow, int oh) { super.onSizeChanged(w, h, ow, oh); width = w; // remember the center of the screen height = h; // middleY = h * 0.5f; } // /** * @param time * 当前歌词的时间轴 * * @return null */ public void SetNowPlayIndex(int i,int time) { this.currentTime = time; // // 歌词序号 index = i; this.invalidate(); if (index != -1) { sentenctTime = lrclist.get(index).getTimePoint(); currentDunringTime = lrclist.get(index).getSleepTime(); // Log.d(TAG,"sentenctTime = "+sentenctTime+", currentDunringTime = "+currentDunringTime); } } }

android音乐播放器之----天天动听相关推荐

  1. android音乐播放器之歌词下载、处理、开始、同步

    android音乐播放器之歌词下载.处理.开始.同步 ** 程序源代码在底部 ** 先来看看效果 下载 /*** 自定义下载方法,调用系统DownloadManager下载* * @param myU ...

  2. android音乐播放器之在线播放功能的实现

    转发请注明出处:http://blog.csdn.net/qq_28055429/article/details/51327171 前言:由于最近在做一个音乐播放器,需实现在线播放功能的实现,故而找了 ...

  3. Android开源音乐播放器之播放器基本功能

    系列文章 Android开源在线音乐播放器--波尼音乐 Android开源音乐播放器之播放器基本功能 Android开源音乐播放器之高仿云音乐黑胶唱片 Android开源音乐播放器之自动滚动歌词 An ...

  4. 【android】音乐播放器之设计思路

    学习Android有一个多月,看完了<第一行代码>以及mars老师的第一期视频通过音乐播放器小项目加深对知识点的理解.从本文开始,将详细的介绍简单仿多米音乐播放器的实现,以及网络解析数据获 ...

  5. 【android】音乐播放器之数据存储总结

    学习Android有一个多月,看完了<第一行代码>以及mars老师的第一期视频通过音乐播放器小项目加深对知识点的理解.从本文开始,将详细的介绍简单仿多米音乐播放器的实现,以及网络解析数据获 ...

  6. 【android】音乐播放器之service服务设计

    学习Android有一个多月,看完了<第一行代码>以及mars老师的第一期视频通过音乐播放器小项目加深对知识点的理解.从本文开始,将详细的介绍简单仿多米音乐播放器的实现,以及网络解析数据获 ...

  7. 【android】音乐播放器之UI设计的点点滴滴

    学习Android有一个多月,看完了<第一行代码>以及mars老师的第一期视频通过音乐播放器小项目加深对知识点的理解.从本文开始,将详细的介绍简单仿多米音乐播放器的实现,以及网络解析数据获 ...

  8. android音乐播放器横评,14款Android平台音乐播放器横评

    最终结果与总体评价 综合实力奖推荐:天天动听 经过对14款Android音 乐播放器一个项目的主观评价和其他七个项目的数据测试的结果加总,国产优秀播放软件天天动听凭借在每轮测试中均表现出的不俗成绩最终 ...

  9. android七大主流Android音乐播放器横向评测

    随着智能手机和3G网络的普及,移动互联网日益成为人们生活娱乐的重心之一.在音乐领域,竞争也十分激烈,在PC之后,几大提供音乐服务的厂商正在加紧占据手机客户端. 本期我们在Android平台挑选了七家国 ...

最新文章

  1. php负载均衡原理_PHP超级负载均衡
  2. 这篇 LaTeX 简单介绍的文章艺术含量很高哒!
  3. 如何在企业内部实现云信私有化
  4. Django工具:Git简介与基本操作
  5. mysql mvc javascript_MVC中用Jquery、JS和Ajax 实现分页 存储过程是用mysql写的。
  6. matlab光伏最大功率,光伏系统最大功率点跟踪技术的比较
  7. 设计一个简单的权限管理系统
  8. Python学习笔记-循环语句
  9. word 引文 角标_如何自动向Microsoft Word添加引文和书目
  10. PYQT显示表格并绘制曲线图
  11. 修改CentOS默认yum源地址提高下载速度
  12. 解决U8库龄分析报表数量与实际结存数量不一致问题
  13. 内存测试拷机软件,烤机软件 OCCT 更新 9.0.0 版本,新增 CPU/内存跑分测试
  14. Qt5之图形视图框架(一)
  15. ubuntu 22端口不通
  16. YOLO多线程多模型运行模式的实施
  17. python strftime时分秒_python如何把秒换成时分秒
  18. 完美解决api-ms-win-crt-runtime-l1-1-0.dll详细步骤
  19. Qt 局域网聊天(功能完善,界面美观,免费下载)
  20. 电子商务新发展 海峡两岸智富惠论坛今日在厦召开

热门文章

  1. 共享打印机时,出现0x000006d9的解决方法
  2. 2021年安徽省大数据与人工智能竞赛人工智能网络赛赛2和3题
  3. python autocad显示_通过Python打开Autocad的新实例
  4. 访问学者在新加坡访学生活日常花销大吗?
  5. 原生js实现炫酷烟花效果
  6. 19类商标买卖需要注意啥呢
  7. 学校校园网联网计算机统计,xx学校校园网建设情况总结(简介或汇报)很有用
  8. 第一章 信息安全的基本元素
  9. 计算机毕业设计springboot+vue基本微信小程序的剧本杀游戏设计与实现
  10. RealVnc源码下载地址