0

I'm building a camera app like vine, where you record a video as long as you hold your finger on the screen.

My problem: If someone taps quickly and continuously on the screen the camera logic receives too many events. It constantly tries to write files, close the recorder, open a new connection and so on.

The camera seems very fragile when it has to start and stop recording too often in a too short timeframe.

I tried setting a flag that prevents new motion events from accessing the camera while it is still busy working on a previous operation. It's ugly but it works. The main problem is, that the motion events seem to cue up and get fired after one another causing way too many events.

I'm using the motion events ACTION_UP and ACTION_DOWN to detect if a user placed the finger on the screen or releases it.

Is there a good way to disable caputuring motion events during the time the camera processes its preparation and release?

j7nn7k
  • 17,995
  • 19
  • 78
  • 88
  • did you try giving a 500 ms to 1000 ms timer once you click as in someone does just tap so it would'nt start the recording and on `ACTION_UP` you can reset the timer – BackStabber Oct 28 '14 at 14:42
  • After the initial 'MotionEvent.ACTION_DOWN' event, all of the subsequent touch events(user keeps finger on the screen) will be 'MotionEvent.ACTION_MOVE' events until the user lifts their finger off of the screen which will register as an 'MotionEvent.ACTION_UP' event. So Check if 'MotionEvent.ACTION_MOVE' is initial and start record. – Al-3sli Oct 28 '14 at 14:44
  • Ugly, but that could be an option. It's seems like a lot of things around the camera only work with ugly workarounds like timers and the misuse of try{} catch{} :-/ – j7nn7k Oct 28 '14 at 14:45
  • Yup its what you have to control ill just post a code for that – BackStabber Oct 28 '14 at 14:46
  • @Al-3sli that doesn't prevent having too many up and down events fired. – j7nn7k Oct 28 '14 at 14:47
  • 1
    but it's give you that he's really holding his finger not just clicking. – Al-3sli Oct 28 '14 at 14:49
  • if he is holding and `ACTION_UP` is not being called then anyways he has to record. Look at my answer below and mark and upvote it, if useful. :) – BackStabber Oct 28 '14 at 14:56
  • You can also add an invisible view on `ACTION_DOWN` and remove that on `ACTION_UP` but i dont think that might work u can handle the clicks differently according to that view maybe . Jus a thought – BackStabber Oct 28 '14 at 16:34

1 Answers1

1

Try This:

//Class Variable
Timer timer;

 public boolean onTouch(View view, MotionEvent event) {
        // Check event type

        switch (event.getAction()) {

        // Finger down
        case MotionEvent.ACTION_DOWN:
              timer = new Timer();
              timer.schedule(recordingfunc(),1000);
                break;
        case MotionEvent.ACTION_UP:
           if(timer!=null){  
                  timer.cancel();
}
                      break;
     }
}
BackStabber
  • 227
  • 1
  • 13