0

私は複数のボタンが表示されているレイアウトを持っています.onclickボタンの1つのサウンドがそれぞれ再生されます.私のコードは次のようですが、機能しません:-

@Override
public void onClick(View view) {
    resetPlayer();
    int index = 0;
    if (view.equals(objbutton1))
        index = R.raw.sound1;

    while (true) {
        this.objplayer = MediaPlayer.create(this, index);
        this.objplayer.setLooping(false);
        this.objplayer.start();
        this.objplayer
                .setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
                    @Override
                    public void onCompletion(MediaPlayer mp) {
                        MainActivity.this.objplayer.release();
                        MainActivity.this.objplayer = null;

                    }
                }
                );
        if(view.equals(objbutton2))
        {
            index=R.raw.sound2;
            continue;

        }
        if(view.equals(objbutton3))
        {
            index=R.raw.sound3;
            continue;

        }
        if(view.equals(objbutton4))
        {
            index=R.raw.sound4;
            continue;

        }
        if(view.equals(objbutton5))
        {
            index=R.raw.sound5;
            continue;

        }
        break;
    }

}

private void resetPlayer() {
    if (this.objplayer != null) {
        if (this.objplayer.isPlaying())
            this.objplayer.stop();
        this.objplayer.release();
        this.objplayer = null;
    }

アプリは 1 つのサウンドのみを再生し、他のボタンをクリックしてもサウンドは変更されません

4

1 に答える 1