私は自分の携帯電話のための簡単なドラムパッドを開発していて、一度に2つのサウンドを再生する場合(つまり、ユーザーが2つ以上のドラムサウンドを押したときのマルチタッチイベント同時に)。Androidデバイスのコンカレントサウンド
私はSoundPoolクラスを使用していました。私はポイントをサウンドにハッシュするHashMapを持っています。だから私の考えは、あるポイントを押すと、それに対応するサウンドが再生されるということでした。
私は、一度に2つのサウンドを再生するには、新しいスレッドをフォークしたり作成したりすることが必要だと思っていますが、試した方法ではうまくいかず、それぞれの "for each"ループポイントを押す。
ありがとうございます! -Aneem
EDIT:
SoundPool database = new SoundPool(6,AudioManager.STREAM_MUSIC,100);
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
width = MeasureSpec.getSize(widthMeasureSpec); //switched for convenience
height = MeasureSpec.getSize(heightMeasureSpec);
screenFactor = (int)((height*width)/6);
//have to add all points to the hash map
widthIncrement = (int)(width/3);
heightIncrement = (int)(height/2);
pointMap.put(new Point(0,0), database.load(getContext(),R.raw.clv,1));
pointMap.put(new Point(widthIncrement,0), database.load(getContext(),R.raw.pedalhh,1));
pointMap.put(new Point((widthIncrement*2),0), database.load(getContext(),R.raw.shake,1));
pointMap.put(new Point(0,heightIncrement), database.load(getContext(),R.raw.analoghat,1));
pointMap.put(new Point(widthIncrement,heightIncrement), database.load(getContext(),R.raw.kick,1));
pointMap.put(new Point((widthIncrement*2),heightIncrement), database.load(getContext(),R.raw.snare,1));
}
パブリックブールonTouchEvent(MotionEventのEV){
if(ev.getAction()==ev.ACTION_DOWN){
AudioManager mgr = (AudioManager) getContext().getSystemService(Context.AUDIO_SERVICE);
int streamVolume = mgr.getStreamVolume(AudioManager.STREAM_MUSIC);
PointF[] touchPoints = new PointF[ev.getPointerCount()];
for(int i = 0; i < ev.getPointerCount(); i++){
if(ev.getPointerId(i)==ev.ACTION_DOWN){
touchPoints[i] = new PointF(ev.getX(i),ev.getY(i));
}
}
int i = 1;
for(final PointF point : touchPoints){
new Thread(new Runnable(){
public void run(){
forkSound(point);
}
}).start();
}
return true;
}
return true;
}
これらの編集については本当に残念ですが、これは初めての投稿です。 – Aneem
問題ありません。 6ストリームで作成しているので、一度に6つのサウンドを再生できるはずです。あなたがプレイしている場所でコードを投稿できますか?一度に複数のゲームをプレイしようとすると、それは何をしますか?それは順番にそれらを再生するか、それらのうちの1つだけを再生するか? – FoamyGuy
私はもう少しアプリを使いこなしていますが、問題は実際にはSoundPoolではないと私は思います。だから、基本的に私が複数のゲームをプレイしようとすると、そのうちの1つだけがプレイされます。タッチイベントを処理するためのコードを投稿します。 – Aneem