我的其中一个按钮单击时没有任何声音

时间:2018-07-19 14:20:04

标签: java android audio android-mediaplayer android-mediarecorder

我正在尝试在android中制作一个drumpad应用。

我的屏幕上有15个按钮。顺便说一下,我在cardview中使用相对布局作为按钮。

我为每个按钮添加声音。用户按下时,每个按钮都应发出声音。

问题是我按下的最后一个按钮不起作用。例如,我随机按下14个按钮。这14个按钮工作正常,但最后一个按钮没有声音。

我尝试添加一个几乎无法推动的按钮(透明和1dp高度),然后运行了该应用程序。结果仍然是14个按钮可以正常工作。剩下两个按钮。他们没有工作。

当我第一次按下最后一个按钮时,我的 logcat 是---->

E/MediaPlayer: error (1, -19)
E/MediaPlayer: Error (1,-19)

当我第二次按下最后一个按钮而其他时候我的logcat是---->

E/MediaPlayer: start called in state 0, mPlayer(0x768b6d0580)
E/MediaPlayer: error (-38, 0)
E/MediaPlayer: Error (-38,0)

我的onClick方法是--->

public void onClick(View v) {
        switch (v.getId()){
            case R.id.rvKick1:
                if (kick1MP.isPlaying()){
                    kick1MP.seekTo(0);
                }
                kick1MP.start();

                break;

            case R.id.rvKick2:
                if (kick2MP.isPlaying()){
                    kick2MP.seekTo(0);
                }
                kick2MP.start();
                break;

            case R.id.rvKick3:
                if (kick3MP.isPlaying()){
                    kick3MP.seekTo(0);
                }
                kick3MP.start();
                break;

            case R.id.rvKick4:
                if (kick4MP.isPlaying()){
                    kick4MP.seekTo(0);
                }
                kick4MP.start();
                break;

            case R.id.rvKick5:
                if (kick5MP.isPlaying()){
                    kick5MP.seekTo(0);
                }
                kick5MP.start();
                break;

            case R.id.rvSnare1:
                if (snare1MP.isPlaying()){
                    snare1MP.seekTo(0);
                }
                snare1MP.start();
                break;

            case R.id.rvSnare2:
                if (snare2MP.isPlaying()){
                    snare2MP.seekTo(0);
                }
                snare2MP.start();
                break;

            case R.id.rvSnare3:
                if (snare3MP.isPlaying()){
                    snare3MP.seekTo(0);
                }
                snare3MP.start();
                break;

            case R.id.rvSnare4:
                if (snare4MP.isPlaying()){
                    snare4MP.seekTo(0);
                }
                snare4MP.start();
                break;

            case R.id.rvSnare5:
                if (snare5MP.isPlaying()){
                    snare5MP.seekTo(0);
                }
                snare5MP.start();
                break;


            case R.id.rvHat1:
                if (hat1MP.isPlaying()){
                    hat1MP.seekTo(0);
                }
                hat1MP.start();
                break;

            case R.id.rvHat2:
                if (hat2MP.isPlaying()){
                    hat2MP.seekTo(0);
                }
                hat2MP.start();
                break;

            case R.id.rvHat3:
                if (hat3MP.isPlaying()){
                    hat3MP.seekTo(0);
                }
                hat3MP.start();
                break;

            case R.id.rvHat4:
                if (hat4MP.isPlaying()){
                    hat4MP.seekTo(0);
                }
                hat4MP.start();
                break;

            case R.id.rvHat5:
                if (hat5MP.isPlaying()){
                    hat5MP.seekTo(0);
                }
                hat5MP.start();
                break;

            case R.id.rvFixButton:
                if (fixSound.isPlaying()){
                    fixSound.seekTo(0);
                }
                fixSound.start();
                break;

            default:
                break;
        }

我叫这样的方法--->

playKick1 = (RelativeLayout) this.findViewById(R.id.rvKick1);
playKick1.setOnClickListener(this);
playKick2 = (RelativeLayout) this.findViewById(R.id.rvKick2);
playKick2.setOnClickListener(this);
playKick3 = (RelativeLayout) this.findViewById(R.id.rvKick3);
playKick3.setOnClickListener(this);
playKick4 = (RelativeLayout) this.findViewById(R.id.rvKick4);
playKick4.setOnClickListener(this);
playKick5 = (RelativeLayout) this.findViewById(R.id.rvKick5);
playKick5.setOnClickListener(this);

playSnare1 = (RelativeLayout) this.findViewById(R.id.rvSnare1);
playSnare1.setOnClickListener(this);
playSnare2 = (RelativeLayout) this.findViewById(R.id.rvSnare2);
playSnare2.setOnClickListener(this);
playSnare3 = (RelativeLayout) this.findViewById(R.id.rvSnare3);
playSnare3.setOnClickListener(this);
playSnare4 = (RelativeLayout) this.findViewById(R.id.rvSnare4);
playSnare4.setOnClickListener(this);
playSnare5 = (RelativeLayout) this.findViewById(R.id.rvSnare5);
playSnare5.setOnClickListener(this);

playHat1 = (RelativeLayout) this.findViewById(R.id.rvHat1);
playHat1.setOnClickListener(this);
playHat2 = (RelativeLayout) this.findViewById(R.id.rvHat2);
playHat2.setOnClickListener(this);
playHat3 = (RelativeLayout) this.findViewById(R.id.rvHat3);
playHat3.setOnClickListener(this);
playHat4 = (RelativeLayout) this.findViewById(R.id.rvHat4);
playHat4.setOnClickListener(this);
playHat5 = (RelativeLayout) this.findViewById(R.id.rvHat5);
playHat5.setOnClickListener(this);

btnFixSound = (RelativeLayout) this.findViewById(R.id.rvFixButton);
btnFixSound.setOnClickListener(this);

有什么主意吗?

0 个答案:

没有答案