1

これが私の主な活動であり、誰かが私を助けることができるかどうかを確認するために必要なのはそれだけだと思います。

package com.art.drumdrum;

import android.app.Activity;
import android.media.AudioManager;
import android.media.SoundPool;
import android.os.Bundle;
import android.view.MotionEvent;
import android.view.View;
import android.widget.Button;

public class MainActivity extends Activity {
SoundPool soundPool = null;
int kickId = 0;
int snareId = 0;
int crashhId = 0;
int crashlId = 0;
int muteId = 0;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    Button kick = (Button) findViewById(R.id.kick);
    Button snare = (Button) findViewById(R.id.snare);
    Button crashh = (Button) findViewById(R.id.crashh);
    Button crashl = (Button) findViewById(R.id.crashl);

    kick.setOnTouchListener(new View.OnTouchListener() {

        @Override
        public boolean onTouch(View v, MotionEvent event) {
            if (event.getAction() == MotionEvent.ACTION_DOWN
                    || event.getAction() == MotionEvent.ACTION_POINTER_DOWN)
                soundPool.play(kickId, 1, 1, 0, 0, 1);
            return false;
        }
    });
    snare.setOnTouchListener(new View.OnTouchListener() {

        @Override
        public boolean onTouch(View v, MotionEvent event) {
            if (event.getAction() == MotionEvent.ACTION_DOWN
                    || event.getAction() == MotionEvent.ACTION_POINTER_DOWN)
                soundPool.play(snareId, 1, 1, 0, 0, 1);
            return false;
        }
    });
    crashh.setOnTouchListener(new View.OnTouchListener() {

        @Override
        public boolean onTouch(View v, MotionEvent event) {
            if (event.getAction() == MotionEvent.ACTION_DOWN
                    || event.getAction() == MotionEvent.ACTION_POINTER_DOWN)
                soundPool.play(crashhId, 1, 1, 0, 0, 1);
            return false;
        }
    });
    crashl.setOnTouchListener(new View.OnTouchListener() {

        @Override
        public boolean onTouch(View v, MotionEvent event) {
            if (event.getAction() == MotionEvent.ACTION_DOWN
                    || event.getAction() == MotionEvent.ACTION_POINTER_DOWN)
                soundPool.play(crashlId, 1, 1, 0, 0, 1);
            return false;
        }
    });

}

protected void onResume() {
    super.onResume();
    if (soundPool == null) {
        soundPool = new SoundPool(20, AudioManager.STREAM_MUSIC, 0);
        kickId = soundPool.load(this, R.raw.kick, 1);
        snareId = soundPool.load(this, R.raw.snare, 1);
        crashhId = soundPool.load(this, R.raw.crashh, 1);
        crashlId = soundPool.load(this, R.raw.crashl, 1);
    }
}

protected void onPause() {
    super.onPause();
    if (soundPool != null) {
        soundPool.release();
        soundPool = null;
    }
}

}

私がやろうとしていることの場合、JetPlayerを使用する方がsoundPoolよりもうまくいくかどうか疑問に思いました。マルチボタンを押すと同時に音が鳴り、すべてがうまくいくように見えますが、ボタンを押してから音が鳴るまでに少し時間がかかり、音が不自然に変化します。何日も情報を調べてきましたが、助けが見つかりませんでした。簡単な答えはありますか、それとももっと多くのコードとおそらくいくつかのc ++を必要とするものですか?

4

1 に答える 1

4

私の知る限り、JetPlayer は MIDI オーディオ同期を目的としているため、ここでは適していません。Jet オーディオ エンジンでは、( JetPlayer#clearQueue()によって) 再生中のすべてのサウンドを停止しない限り、ボタンを押したときにすぐにサウンドを再生することはできません。

また、Android の音声遅延の問題に対する簡単な答えはありません。おそらく、C++ (OpenSL ES) でより良いレイテンシーを得ることができますが、私はそれについてあまり知りません。関連する回答をご覧ください: https://stackoverflow.com/a/12309643

于 2013-03-05T20:25:12.317 に答える