Android平台中关于音频的播放有两种方式,一种是SoundPool,一种是MediaPlayer.SoundPool适合短促但反映速度要求高的情况
(如按键声),而MediaPlayer则适合较长但对时间要求不高的情况。
SoundPool只能用于播放音效,因为超过大约5.6秒的声音便播放不出来,而且加载超过大约5.6秒的音效还会导致其它声音播放的问题
在res目录下新建raw文件夹把音频文件加入其中
修改布局文件main.xml的代码,修改后完整代码如下:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<TextView
android:id="@+id/textView"
android:layout_width="fill_parent"
android:layout_height&#