本人很爱玩音乐 看到ios平台很多音乐的模拟软件 吉他的~贝斯的 鼓的~~但是android平台却相当不给力 这些软件都很渣~~排名靠前的架子鼓的软件 竟然只能支持单指操作!就比如一个节奏咚次大次吧 kit(地鼓)和snare(踩镲)必须同时响起来 如果只支持单指操作的话 不能同时点击两个以上的鼓 这样模拟架子鼓的效果就太差了!!
.
.
.
出于严重不满android平台音乐类软件质量的差劲 我就想自己捣鼓一个架子鼓的软件出来 造福热爱音乐的朋友们 但是遇到问题了~~~自学了android应用的开发 但是对编程毕竟还很不了解 所以表述的当中可能有纰漏 愿谅解 但是我有热情和激情 希望在广大各路神仙指点迷津 能过有所进步!!
.
.
.
现在我的ui布局、界面设计、按钮元素等全部都已经实现了 架子鼓上的每个部件我都用一个button来显示 然后用button的setOnClickListener的方法来实现点击相应的按钮来发出声音
但是问题来了 这样一次只能点击一个button 不能同时点击多个button来发声 我就郁闷了
于是在网上查找了很多资料 都是关于重写onTouchEvent的做法来支持多指触控操作 最贴近我想要的效果的方法就是 getX()getY()得到点击的坐标然后调用该坐标的view(button)的方法这样就可以支持多指操作……
.
.但是我怎么都不知道该如何写 所以在此请教各路大神了 求可以同时点击两个以上的button并且button同时响应(同时发出声音)的方法和思路 谢谢各位了另外请教soundpool怎么会有延迟?感觉点击和发出声音总是不够同步?soundpool的播放优先已经最高了 音频文件也就只有100k 这么小android还吃不消? 这个怎么破??多指触控buttonandroidontouchevent多指操作
.
.
.
出于严重不满android平台音乐类软件质量的差劲 我就想自己捣鼓一个架子鼓的软件出来 造福热爱音乐的朋友们 但是遇到问题了~~~自学了android应用的开发 但是对编程毕竟还很不了解 所以表述的当中可能有纰漏 愿谅解 但是我有热情和激情 希望在广大各路神仙指点迷津 能过有所进步!!
.
.
.
现在我的ui布局、界面设计、按钮元素等全部都已经实现了 架子鼓上的每个部件我都用一个button来显示 然后用button的setOnClickListener的方法来实现点击相应的按钮来发出声音
但是问题来了 这样一次只能点击一个button 不能同时点击多个button来发声 我就郁闷了
于是在网上查找了很多资料 都是关于重写onTouchEvent的做法来支持多指触控操作 最贴近我想要的效果的方法就是 getX()getY()得到点击的坐标然后调用该坐标的view(button)的方法这样就可以支持多指操作……
.
.但是我怎么都不知道该如何写 所以在此请教各路大神了 求可以同时点击两个以上的button并且button同时响应(同时发出声音)的方法和思路 谢谢各位了另外请教soundpool怎么会有延迟?感觉点击和发出声音总是不够同步?soundpool的播放优先已经最高了 音频文件也就只有100k 这么小android还吃不消? 这个怎么破??多指触控buttonandroidontouchevent多指操作
解决方案 »
- 关于测试类Instrumentation!!!
- C#和android两个程序中如何生成同一个随机数序列?
- 怎样实现微信聊天一样的布局
- 如何在ANDROID SDK中调用ANDROID本身的浏览器测试HTML网页?比较着急,希望大家帮忙,谢谢!
- 有谁能告诉我,为什么google开发者网经常出现网页错误?
- locationManager.requestLocationUpdates 设置时间没用啊!
- ubuntu8.04 下 android 源码版本问题(恐怕只有高手知道)
- 怎么修改安卓软件,使其支持所有dpi
- Android_页面随输入法上移
- DELPHI XE 开发 ANDROID程序,怎么设置程序的名称?
- 如何将PopupWindow遮住的控件点击到!然后让这个控件响应点击事件??
- 求助,想找一个能做手机应用软件demo的工具
package com.powerdrum;
import java.util.HashMap;
import android.annotation.SuppressLint;
import android.app.Activity;
import android.media.AudioManager;
import android.media.SoundPool;
import android.os.Bundle;
import android.view.Menu;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnTouchListener;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.Button;public class LeftMainActivity extends Activity implements OnTouchListener {
Button kick ;
Button snare ;
Button hihat_close;
Button hihat_open;
Button hitom;
Button midtom;
Button lotom;
Button ride;
Button crash;
Button splash;
Animation shake;
SoundPool soundPool;
Object kit;
HashMap<Integer, Integer> soundPoolMap;
@SuppressLint("UseSparseArrays")
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_left_main);
shake = AnimationUtils.loadAnimation(this, R.anim.shake);//使鼓抖动的动画
soundPool = new SoundPool(11, AudioManager.STREAM_MUSIC, 5); //音频播放器初始化
soundPoolMap= new HashMap<Integer, Integer>();
RedySound();//加载音频
RedyButton();//初始化按钮
RedyButtonTouch();//添加按钮触摸监听
}
public void RedySound(){
soundPoolMap.put(1, soundPool.load(this, R.raw.r_kick, 1));
soundPoolMap.put(2, soundPool.load(this, R.raw.r_snare, 1));
soundPoolMap.put(3, soundPool.load(this, R.raw.r__hihat_closed, 1));
soundPoolMap.put(4, soundPool.load(this, R.raw.r_hihat_open, 1));
soundPoolMap.put(5, soundPool.load(this, R.raw.r_hitom, 1));
soundPoolMap.put(6, soundPool.load(this, R.raw.r_midtom, 1));
soundPoolMap.put(7, soundPool.load(this, R.raw.r_lotom, 1));
soundPoolMap.put(8, soundPool.load(this, R.raw.r_ride, 1));
soundPoolMap.put(9, soundPool.load(this, R.raw.r_crash, 1));
soundPoolMap.put(10, soundPool.load(this, R.raw.r_splash, 1));
soundPoolMap.put(11, soundPool.load(this, R.raw.r_ride_bell, 1));
}
public void RedyButton(){
kick = (Button) findViewById(R.id.kick_bt);
snare = (Button) findViewById(R.id.snare_bt);
hihat_close= (Button) findViewById(R.id.hihat_close_bt);
hihat_open= (Button) findViewById(R.id.hihat_open_bt);
hitom= (Button) findViewById(R.id.hitom_bt);
midtom= (Button) findViewById(R.id.midtom);
lotom= (Button) findViewById(R.id.lotom_bt);
ride= (Button) findViewById(R.id.ride_bt);
crash= (Button) findViewById(R.id.crash_bt);
splash= (Button) findViewById(R.id.splash_bt);
}
public void RedyButtonTouch(){
kick.setOnTouchListener(this);
snare.setOnTouchListener(this);
hihat_close.setOnTouchListener(this);
hihat_open.setOnTouchListener(this);
hitom.setOnTouchListener(this);
midtom.setOnTouchListener(this);
lotom.setOnTouchListener(this);
ride.setOnTouchListener(this);
crash.setOnTouchListener(this);
splash.setOnTouchListener(this);
}
@Override
public boolean onTouch(View v, MotionEvent event) {
switch(event.getAction()&MotionEvent.ACTION_MASK){
case MotionEvent.ACTION_DOWN:
if(v.getId()==R.id.kick_bt){
kick.startAnimation(shake);
soundPool.play(soundPoolMap.get(1), 1, 1, 1, 0, 1);
}
if(v.getId()==R.id.snare_bt){
snare.startAnimation(shake);
soundPool.play(soundPoolMap.get(2), 1, 1, 1, 0, 1);
}
if(v.getId()==R.id.hihat_close_bt){
hihat_close.startAnimation(shake);
soundPool.play(soundPoolMap.get(3), 1, 1, 1, 0, 1);
}
if(v.getId()==R.id.hihat_open_bt){
hihat_open.startAnimation(shake);
soundPool.play(soundPoolMap.get(4), 1, 1, 1, 0, 1);
}
if(v.getId()==R.id.hitom_bt){
hitom.startAnimation(shake);
soundPool.play(soundPoolMap.get(5), 1, 1, 1, 0, 1);
}
if(v.getId()==R.id.midtom){
midtom.startAnimation(shake);
soundPool.play(soundPoolMap.get(6), 1, 1, 1, 0, 1);
}
if(v.getId()==R.id.lotom_bt){
lotom.startAnimation(shake);
soundPool.play(soundPoolMap.get(7), 1, 1, 1, 0, 1);
}
if(v.getId()==R.id.ride_bt){
ride.startAnimation(shake);
soundPool.play(soundPoolMap.get(8), 1, 1, 1, 0, 1);
}
if(v.getId()==R.id.crash_bt){
crash.startAnimation(shake);
soundPool.play(soundPoolMap.get(9), 1, 1, 1, 0, 1);
}
if(v.getId()==R.id.splash_bt){
splash.startAnimation(shake);
soundPool.play(soundPoolMap.get(10), 1, 1, 1, 0, 1);
}
break;
case MotionEvent.ACTION_POINTER_DOWN:
if(v.getId()==R.id.kick_bt){
kick.startAnimation(shake);
soundPool.play(soundPoolMap.get(1), 1, 1, 1, 0, 1);
}
if(v.getId()==R.id.snare_bt){
snare.startAnimation(shake);
soundPool.play(soundPoolMap.get(2), 1, 1, 1, 0, 1);
}
if(v.getId()==R.id.hihat_close_bt){
hihat_close.startAnimation(shake);
soundPool.play(soundPoolMap.get(3), 1, 1, 1, 0, 1);
}
if(v.getId()==R.id.hihat_open_bt){
hihat_open.startAnimation(shake);
soundPool.play(soundPoolMap.get(4), 1, 1, 1, 0, 1);
}
if(v.getId()==R.id.hitom_bt){
hitom.startAnimation(shake);
soundPool.play(soundPoolMap.get(5), 1, 1, 1, 0, 1);
}
if(v.getId()==R.id.midtom){
midtom.startAnimation(shake);
soundPool.play(soundPoolMap.get(6), 1, 1, 1, 0, 1);
}
if(v.getId()==R.id.lotom_bt){
lotom.startAnimation(shake);
soundPool.play(soundPoolMap.get(7), 1, 1, 1, 0, 1);
}
if(v.getId()==R.id.ride_bt){
ride.startAnimation(shake);
soundPool.play(soundPoolMap.get(8), 1, 1, 1, 0, 1);
}
if(v.getId()==R.id.crash_bt){
crash.startAnimation(shake);
soundPool.play(soundPoolMap.get(9), 1, 1, 1, 0, 1);
}
if(v.getId()==R.id.splash_bt){
splash.startAnimation(shake);
soundPool.play(soundPoolMap.get(10), 1, 1, 1, 0, 1);
}
break;
}
return false;
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.left_main, menu);
return true;
}
}
int pointerCt = event.getPointerCount(); //获取多点触摸的数量,
if(pointerCt >= 2){ //假如2个以上都点击了。就响应你的鼓声。
}
}用多个按钮去控制较为麻烦。
你有空能写几段伪代码么 辛苦你了 谢谢 我学编程不久的