Android Studio 学习(三)
服务与广播
学习目标:
1、掌握服务的基本概念,能编写服务过程并进行调用;
2、掌握广播的基本概念,能实现广播通信。
3、需实现的具体功能为:
短信到来时自动产生的系统广播→激活音乐播放服务程序→活动组件程序使得停止按钮可用。
项目功能说明:
1、音乐播放界面能显示歌曲封面、歌曲名、作者、播放进度、当前时间、歌曲总时间
2、能实现上一首、下一首、暂停、播放、停止,并且封面随之改变
3、拖动进度条可以对应的改变歌曲的播放进度
4、页面布局清晰,运行流畅
核心代码:
音乐播放页面由基本信息界面、控制界面两个界面组成,分别对应两个LinearLayout
基本信息界面包含一个ImageView(歌曲封面)、两个LinearLayout
基本信息界面中的第一个LinearLayout中有两个TextView分别对应歌曲名、作者
基本信息界面中的第二个LinearLayout中包含两个TextView和一个SeeBar分别对应当前时间、歌曲总时间、进度条
控制界面包含四个ImageButton分别对应上一首、播放(暂停)、停止、下一首
基本信息界面:歌曲名、作者
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal">
<TextView
android:id="@+id/title"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="#ffffff"
android:text="Title"
android:textSize="20dp" />
<TextView
android:id="@+id/author"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="#ffffff"
android:text="Author"
android:textSize="20dp" />
</LinearLayout>
基本信息界面:当前时间、进度条、歌曲总时间
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal">
<TextView
android:id="@+id/curTime"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:background="#ffffff"
android:text="00:00" />
<SeekBar
android:id="@+id/seekBar"
android:layout_width="310dp"
android:layout_height="wrap_content"
android:background="#ffffff"