Record audio equal to Whatsapp

Asked

Viewed 282 times

0

Does anyone know how to record an audio while the button is pressed and stop when releasing the button equals Whatsapp?

1 answer

5


You can use the method setOnTouchListener on the button to redeem the tap. The MotionEvent.ACTION_DOWN is the event that captures the moment you clicked on the button. Already the MotionEvent.ACTION_UP is when you remove your finger from the button. See an example below:

class MyActivity extends Activity {

     public void onCreate(Bundle savedInstanceState) {
         super.onCreate(savedInstanceState);
         setContentView(R.layout.your_layout);

         Button myBtn = (Button) findViewById(R.id.mybutton);
         myBtn.setOnTouchListener(new View.OnTouchListener() {
             @Override
             public boolean onTouch(View v, MotionEvent event) {
                 switch (event.getAction()) {
                     case MotionEvent.ACTION_DOWN:
                         // aqui código de iniciar a gravação que é o momento
                         // em que pressionou o botão para baixo
                         return true; 

                     case MotionEvent.ACTION_UP:
                         // aqui código de pausar a gravação que é o momento
                         // em que soltou o botão
                         return true; 
                 }
                 return false;
             }
         });
     }

 }
  • 1

    Very good, thanks again Ack..

  • @Wallaceroberto for nothing bro! Need, only appeal here! = D

Browser other questions tagged

You are not signed in. Login or sign up in order to post.