实验内容:
1. 播放、暂停、停止、退出功能
2. 后台播放功能
3. 进度条显示播放进度、拖动进度条改变进度功能
4. 播放时图片旋转,显示当前播放时间功能
一. 参考网站
https://zhidao.baidu.com/question/1770591672437913940.html android开发 mp3文件放在哪个文件夹
http://blog.youkuaiyun.com/kjunchen/article/details/50429694 Android应用开发按下返回键退向后台运行
http://www.cnblogs.com/menlsh/archive/2013/06/07/3125341.html Android使用Handler实时更新UI
http://blog.youkuaiyun.com/hahawhyha/article/details/12783643 Error: start called in state 64
http://www.oschina.net/question/54100_32914 Android MediaPlayer 播放prepareAsync called in state 8解决办法
http://stackoverflow.com/questions/17054000/cannot-resolve-symbol-r-in-android-studio “cannot resolve symbol R” in Android Studio
二. 实验步骤
实现播放器主页面。主要控件有ImageView, TextView, SeekBar和Button。实现思路是整体页面是一个RelativeLayout, 音乐背景图ImageView和显示文件路径和当前状态的TextView是RelativeLayout下的控件。
<ImageView android:id="@+id/imageView" android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@mipmap/cover" android:layout_centerHorizontal="true" android:layout_marginTop="25dp" android:scaleType="center"/> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/path" android:textColor="@color/colorBlack" android:layout_centerHorizontal="true" android:layout_marginTop="300dp" /> <TextView android:id="@+id/state" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/initial" android:layout_marginTop="320dp" android:layout_marginLeft="10dp" android:textSize="20sp" android:textColor="@color/colorBlack"/>
拖动条SeekBar和两边显示时间的TextView放在主布局下的一个LinearLayout里面
<LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginTop="360dp" android:layout_marginLeft="10dp" android:layout_marginRight="10dp" android:orientation="horizontal" android:gravity="center_vertical"> <TextView android:id="@+id/currentTime" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/begin" android:textColor="@color/colorBlack"/> <SeekBar android:id="@+id/seekBar" android:layout_width="0dp" android:layout_height=