一,需要知识点:
1,Drawerlayout侧滑菜单实现。
2,ListView的使用及其点击事件的监听。
3,如何打开文件管理器选择特定文件,并获取被选文件的路径。
4,Service服务的使用。
5,如何使用新线程动态给UI线程发送消息更新Seekbar进度。
6,MediaPlayer的使用。
二,写代码时遇到的坑。
1,在新开的线程中是不能修改UI组件的,否则程序会崩溃,写的时候因为这个程序一直崩溃我也很绝望。
2,找如何打开系统浏览器找了半天。
布局文件(线性布局):
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/drawerlayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/bg3"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:gravity="center"
>
<TextView
android:id="@+id/imageview"
android:layout_width="match_parent"
android:layout_height="300dp"
/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="当前正在播放:无歌曲"
android:textSize="25sp"
android:id="@+id/nowplayText"
android:lines="2"
/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="40dp"
android:orientation="horizontal"
android:layout_marginTop="10dp"
>
<TextView
android:id="@+id/leftText"
android:text="00:00"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:gravity="center"
android:layout_marginLeft="5dp"
/>
<SeekBar
android:id="@+id/seekbar"
android:layout_width="272dp"
android:layout_height="match_parent"
/>
<TextView
android:id="@+id/rightText"
android:text="99:99"
android:gravity="center"
android:layout_width="wrap_content"
android:layout_height="match_parent" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="50dp"
android:orientation="horizontal"
android:gravity="center"
>
<Button
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:id="@+id/open_btn"
android:text="打开"
/>
<Button
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:id="@+id/stop_btn"
android:text="停止"
/>
<ImageButton
android:id="@+id/imagebutton_exit"
android:layout_width="50dp"
android:layout_height="match_parent"
android:background="@drawable/exit_btn"
/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:orientation="horizontal"
>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/pre_btn"
android:text="上一曲"
/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/start_btn"
android:text="播放"
/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/next_btn"
android:text="下一曲"
/>
<Button
android:id="@+id/menu_btn"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:text="菜单" />
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="200dp"