新建一个moudle,命名为MediaPlayer_ServiceDemo
1.准备素材一首歌,将音乐资源放入res/raw 目录下,如果没有raw目录,就新建一个。
2.准备布局文件,一共5个功能,开始、停止、暂停、退出应用继续播放、退出应用停止播放。
activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" android:id="@+id/activity_main"
android:layout_width="match_parent" android:layout_height="match_parent"
android:orientation="vertical"
android:gravity="center"
tools:context="com.soft.qianyu.mediaplayerdemo.MainActivity">
<Button
android:id="@+id/kaishi"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="开始"
/>
<Button
android:id="@+id/tingzhi"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="停止"
/>
<Button
android:id="@+id/zanting"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="暂停"
/>
<Button
android:id="@+id/finish"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="退出程序并继续播放"
/>
<Button
android:id</