Android_弹钢琴(多媒体应用)
所需文件
MainActivity
package com.example.a524_11_playpiano;
import android.media.AudioManager;
import android.media.SoundPool;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import androidx.appcompat.app.AppCompatActivity;
import java.util.HashMap;
public class MainActivity extends AppCompatActivity implements View.OnClickListener
{
private SoundPool soundpool;
private HashMap<Integer,Integer> map = new HashMap<>();
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
//初始化界面控件,并为控件添加点击事件的监听器
ImageView iv_do = findViewById(R.id.iv_do);
ImageView iv_re = findViewById(R.id.iv_re);
ImageView iv_mi = findViewById(R.id.iv_mi);
ImageView iv_fa = findViewById(R.id.iv_fa);
ImageView iv_so = findViewById(R.id.iv_so);
ImageView iv_la = findViewById(R.id.iv_la);
ImageView iv_si = findViewById(R.id.iv_si);
iv_do.setOnClickListener(this);
iv_re.setOnClickListener(this);
iv_mi.setOnClickListener(this);
iv_fa.setOnClickListener(this);
iv_so.setOnClickListener(this);
iv_la.setOnClickListener(this);
iv_si.setOnClickListener(this);
initSoundPool();//初