我已经输入了所有声音(wav文件),但是我在运行项目时无法加载声音,仅加载了窥视声音。我检查了所有声音是否都在res文件中。 请帮助
这是我的代码:
import android.media.AudioManager;
import android.media.SoundPool;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
public class MainActivity extends AppCompatActivity {
private SoundPool sp;
private int c;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
sp = new SoundPool(2,
AudioManager.STREAM_MUSIC,5);
c = sp.load(getApplicationContext(), R.raw.c,1);
}
public void playsound1 (View v) {
sp.play(c,1.0F,1.0F,0,0,1.0F);
}
}
和xml文件:
<LinearLayout 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:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity"
android:background="@color/colorPrimary"
android:padding="10dp"
android:gravity="center"
android:orientation="vertical">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="50dp"
android:orientation="horizontal">
<Button
android:layout_width="50dp"
android:layout_height="50dp"
android:background="@drawable/c_button"/>
下面还有更多按钮。...