2

我有一个扩展按钮的类:

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 并改变音高?

4

0 回答 0