开发步骤
【1】显示软件界面
1)设计布局:包括 activity_main.xml 和 ListView 的模板
a)先设计底部按钮区域
b)设计中间歌曲信息显示区域
c)添加ListView控件
2)读取数据(完成 MusicDao 相关类)
a)先设计实体类 Music
b)设计 IDao 接口
c)创建 MusicDao 实现 IDao 接口,并重写抽象方法
d)创建 MusicDaoFactory,提供静态方法返回 MusicDao 的对象
3)实现 Adapter(完成 MusicAdapter 相关类)
4)显示 ListView
【2】开发 Service
1)创建并注册 Service
2)在 Service 内部完成播放控制相关方法,例如 play() 等
【3】实现基本控制
【4】实现播放信息显示
【5】实现细节,修复 bug
展示音乐列表
布局文件
activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ListView
android:id="@+id/lv_music_list"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="@+id/ll_music_info" />
<LinearLayout
android:id="@+id/ll_music_info"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="@+id/sk_progress"
android:padding="10dp">
<TextView
android:id="@+id/tv_music_info"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="请选择播放歌曲" />
</LinearLayout>
<SeekBar
android:id="@+id/sk_progress"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="@+id/ll_button_layout" />
<LinearLayout
android:id="@+id/ll_button_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:gravity="center">
<ImageButton
android:id="@+id/ib_previous"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@android:drawable/ic_media_previous" />
<ImageButton
android:id="@+id/ib_play"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@android:drawable/ic_media_play" />
<ImageButton
android:id="@+id/ib_next"
android:layout_width="wrap_content"
android:layout_height