import android.media.AudioManager;
import android.media.SoundPool;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import androidx.appcompat.app.AppCompatActivity;
public class MainActivity extends AppCompatActivity {
private final int sim_sound = 7;
private final float lft_vol = 1.0f;
private final float rgt_vol = 1.0f;
private final int loop = 0;
private final int prty = 0;
private final float NORMAL_PLAY_RATE = 1.0f;
private SoundPool mSoundPool;
private int mCSoundId1;
private int mDSoundId2;
private int mESoundId3;
private int mFSoundId4;
private int mGSoundId5;
private int mASoundId6;
private int mBSoundId7;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mSoundPool = new SoundPool(sim_sound, AudioManager.STREAM_MUSIC, 0);
mCSoundId1 = mSoundPool.load(getApplicationContext(), R.raw.note1_c, 1);
mDSoundId2 = mSoundPool.load(getApplicationContext(), R.raw.note2_d, 1);
mESoundId3 = mSoundPool.load(getApplicationContext(), R.raw.note3_e, 1);
mFSoundId4 = mSoundPool.load(getApplicationContext(), R.raw.note4_f, 1);
mGSoundId5 = mSoundPool.load(getApplicationContext(), R.raw.note5_g, 1);
mASoundId6 = mSoundPool.load(getApplicationContext(), R.raw.note6_a, 1);
mBSoundId7 = mSoundPool.load(getApplicationContext(), R.raw.note7_b, 1);
}
public void c (View v){
mSoundPool.play(mCSoundId1, lft_vol, rgt_vol, prty,loop,NORMAL_PLAY_RATE);
}
public void d (View v){
mSoundPool.play(mDSoundId2, lft_vol, rgt_vol, prty,loop,NORMAL_PLAY_RATE);
}
public void e (View v){
mSoundPool.play(mESoundId3, lft_vol, rgt_vol, prty,loop,NORMAL_PLAY_RATE);
}
public void f (View v){
mSoundPool.play(mFSoundId4, lft_vol, rgt_vol, prty,loop,NORMAL_PLAY_RATE);
}
public void g (View v){
mSoundPool.play(mGSoundId5, lft_vol, rgt_vol, prty,loop,NORMAL_PLAY_RATE);
}
public void a (View v){
mSoundPool.play(mASoundId6, lft_vol, rgt_vol, prty,loop,NORMAL_PLAY_RATE);
}
public void b (View v){
mSoundPool.play(mBSoundId7, lft_vol, rgt_vol, prty,loop,NORMAL_PLAY_RATE);
}
}