如何使用ToggleButton来改变所有声音的音高?

时间:2012-11-14 06:53:28

标签: android touch togglebutton soundpool

我有一个扩展按钮的类:

package dubpad.brendan;

import android.content.Context;
import android.media.AudioManager;
import android.media.SoundPool;
import android.util.AttributeSet;

import android.view.MotionEvent;
import android.widget.Button;



public class TestButton extends Button {.

   SoundPool soundPool = new SoundPool(1, AudioManager.STREAM_MUSIC, 0);
   int soundID = soundPool.load(getContext(), R.raw.bass, 0);
   Sound sound = new Sound(soundPool, soundID);
   int streamid;

public TestButton(final Context context, final AttributeSet attrs) {
    super(context, attrs);
    // TODO Auto-generated constructor stub
}

@Override
public boolean onTouchEvent(final MotionEvent event) {
if (event.getAction() == MotionEvent.ACTION_DOWN||event.getAction()==MotionEvent.ACTION_POINTER_DOWN||event.getAction()==MotionEvent.ACTION_POINTER_1_DOWN||event.getAction()==MotionEvent.ACTION_POINTER_2_DOWN||event.getAction()==MotionEvent.ACTION_POINTER_3_DOWN) {
            streamid = sound.play(1);           
   }

if (event.getAction()==MotionEvent.ACTION_UP||event.getAction()==MotionEvent.ACTION_POINTER_UP||event.getAction()==MotionEvent.ACTION_POINTER_1_UP||event.getAction()==MotionEvent.ACTION_POINTER_2_UP||event.getAction()==MotionEvent.ACTION_POINTER_3_UP){
sound.stop(streamid);
     }  
    return super.onTouchEvent(event);
}

 }

我想实现一个ToggleButton并检查它是否被选中,如果它是我想增加音高,如果不是,我想减少音高。在ACTION_DOWN上声明ToggleButton对象并检查它不起作用。我有许多其他类扩展按钮,如何捕获streamID并改变音高?

0 个答案:

没有答案