Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/178.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 当听众停止播放时_Android_Android Imageview_Android Mediaplayer_Onclicklistener - Fatal编程技术网

Android 当听众停止播放时

Android 当听众停止播放时,android,android-imageview,android-mediaplayer,onclicklistener,Android,Android Imageview,Android Mediaplayer,Onclicklistener,我尝试在图像(ImageView)上播放点击声音,听起来很完美,但点击几下后,什么声音都没有,程序仍然在运行,没有问题。我尝试使用release(),但从来都不适合我 公共类MainActivity扩展ActionBarActivity实现OnClickListener{ private MediaPlayer mp; @Override public boolean onCreateOptionsMenu(Menu menu) { getMenuInflater().inflate

我尝试在图像(ImageView)上播放点击声音,听起来很完美,但点击几下后,什么声音都没有,程序仍然在运行,没有问题。我尝试使用release(),但从来都不适合我

公共类MainActivity扩展ActionBarActivity实现OnClickListener{

private MediaPlayer mp;

@Override
public boolean onCreateOptionsMenu(Menu menu) {

    getMenuInflater().inflate(R.menu.main, menu);
    return true;
}

public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
        case R.id.MnuOpc1:
            System.exit(0);
            return true;
        default:
            return super.onOptionsItemSelected(item);
    }
}


@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
    setContentView(R.layout.main);
    View boton1 = findViewById(R.id.imageView1);
    boton1.setOnClickListener(this);
    View boton2 = findViewById(R.id.imageView4);
    boton2.setOnClickListener(this); 
    View boton3 = findViewById(R.id.imageView3);
    boton3.setOnClickListener(this); 
    View boton4 = findViewById(R.id.imageView2);
    boton4.setOnClickListener(this); 
    View boton5 = findViewById(R.id.imageView7);
    boton5.setOnClickListener(this); 
    View boton6 = findViewById(R.id.imageView9);
    boton6.setOnClickListener(this); 
    View boton7 = findViewById(R.id.imageView11);
    boton7.setOnClickListener(this); 
    View boton8 = findViewById(R.id.imageView13);
    boton8.setOnClickListener(this); 
    View boton9 = findViewById(R.id.imageView15);
    boton9.setOnClickListener(this); 
    View boton10 = findViewById(R.id.imageView17);
    boton10.setOnClickListener(this); 
    View boton11 = findViewById(R.id.imageView19);
    boton11.setOnClickListener(this); 
    View boton12 = findViewById(R.id.imageView21);
    boton12.setOnClickListener(this); 
}

public void onClick(View v) {



    if(v.getId()==findViewById(R.id.imageView1).getId())
    {


         mp = MediaPlayer.create(this,R.raw.sound1);  
         mp.start();


    }
    if(v.getId()==findViewById(R.id.imageView4).getId())
    {

        mp = MediaPlayer.create(this,R.raw.sound2);  
        mp.start();
    } 
    if(v.getId()==findViewById(R.id.imageView3).getId())
    {

        mp = MediaPlayer.create(this,R.raw.sound3);  
          mp.start();
    }
    if(v.getId()==findViewById(R.id.imageView2).getId())
    {

        mp = MediaPlayer.create(this,R.raw.sound4);  
          mp.start();
    }
    if(v.getId()==findViewById(R.id.imageView7).getId())
    {

        mp = MediaPlayer.create(this,R.raw.sound5);  
          mp.start();
    }
    if(v.getId()==findViewById(R.id.imageView9).getId())
    {

        mp = MediaPlayer.create(this,R.raw.sound6);  
          mp.start();
    }
    if(v.getId()==findViewById(R.id.imageView11).getId())
    {

        mp = MediaPlayer.create(this,R.raw.sound7);  
          mp.start();
    }
    if(v.getId()==findViewById(R.id.imageView13).getId())
    {

        mp = MediaPlayer.create(this,R.raw.sound8);  
          mp.start();
    }
    if(v.getId()==findViewById(R.id.imageView15).getId())
    {

        mp = MediaPlayer.create(this,R.raw.sound9);  
          mp.start();
    }
    if(v.getId()==findViewById(R.id.imageView17).getId())
    {

        mp = MediaPlayer.create(this,R.raw.sound10);  
          mp.start();
    }
    if(v.getId()==findViewById(R.id.imageView19).getId())
    {

        mp = MediaPlayer.create(this,R.raw.sound11);  
          mp.start();
    }
    if(v.getId()==findViewById(R.id.imageView21).getId())
    {

        mp = MediaPlayer.create(this,R.raw.sound12);  
          mp.start();
    }
}   
}

我想我需要将release()放在某个地方或更改代码结构,但我现在不知道该怎么做。谢谢