The problem is this: case R.id.b1: I chose animation + music, I choose case R.id.b2: the player and animation stopped and I need to click a second time to play case R.id.b2: how can I avoid a second click? I know that in the method I check and stop the player, but that is if I re-press case R.id.b1:, i.e. I need a check on the playing player
@Override public void onClick(View v) { stopAnimation(); switch (v.getId()) { //imageview1 case R.id.b1: { v.startAnimation(anim); playSample(soundsRawResIds[0]); break; } //imageview2 case R.id.b2: { v.startAnimation(anim); playSample(soundsRawResIds[1]); break; } //imageview3 case R.id.b3: { v.startAnimation(anim); playSample(soundsRawResIds[2]); break; } case R.id.b4: { v.startAnimation(anim); playSample(soundsRawResIds[3]); break; } case R.id.b5: { v.startAnimation(anim); playSample(soundsRawResIds[4]); break; } case R.id.b6: { v.startAnimation(anim); playSample(soundsRawResIds[5]); break; } case R.id.b7: { v.startAnimation(anim); playSample(soundsRawResIds[6]); break; } } }} //метод через,который пытаюсь воспроизводить мелодии private void playSample(int resid) { AssetFileDescriptor afd = getContext().getResources().openRawResourceFd(resid); if (mediaPlayer.isPlaying()) { mediaPlayer.stop(); } else { try { mediaPlayer.reset(); mediaPlayer.setDataSource(afd.getFileDescriptor(), afd.getStartOffset(), afd.getDeclaredLength()); mediaPlayer.prepareAsync(); afd.close(); } catch (IllegalArgumentException e) { Log.e(TAG, "Unable to play audio queue do to exception: " + e.getMessage(), e); } catch (IllegalStateException e) { Log.e(TAG, "Unable to play audio queue do to exception: " + e.getMessage(), e); } catch (IOException e) { Log.e(TAG, "Unable to play audio queue do to exception: " + e.getMessage(), e); } } }