Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Motion detector callback working only in debug mode #7

Open
davide136 opened this issue Jan 23, 2020 · 0 comments
Open

Motion detector callback working only in debug mode #7

davide136 opened this issue Jan 23, 2020 · 0 comments

Comments

@davide136
Copy link

davide136 commented Jan 23, 2020

Hi, need some help... i need to capture video recording on every motion detected, this is my relevant code:

void motionDetectorCallback(){
        motionDetector.setMotionDetectorCallback(new MotionDetectorCallback() {
            @RequiresApi(api = Build.VERSION_CODES.KITKAT)
            @Override    public void onMotionDetected() {
                try {
                    initRoutine();
                }catch(NullPointerException ignored){}   Log.w(TAG,"Motion detected");
            }
            @Override
            public void onTooDark() {    Log.w(TAG,"Too dark here"    ); }  })  ;}


    @RequiresApi(api = Build.VERSION_CODES.KITKAT)
    void initRoutine() {
        if (!firstRun) {
            enoughTimeHasPassed = false;
            long now = System.currentTimeMillis();
            if ( (now -lastRecordingTime) > 500 )
                enoughTimeHasPassed = true;
        }
        if (smbConnection.isConnected() & !recording & serviceRunning & enoughTimeHasPassed)
{            textRecordingStatus.setText("RECORDING");
            textRecordingStatus.setTextColor(Color.GREEN);
            firstRun = false;
            Log.w(TAG,"RECORD STARTED");
            record();  }}


    @RequiresApi(api = Build.VERSION_CODES.KITKAT)
    private void record() {
        if (!recording) {
            recording = true;
            prepareVideoRecorder();
            recorder.start();
            Handler handler = new Handler();
            handler.postDelayed(new Runnable() {
                @Override
                public void run() { stopRecorder(); }  }, time*1000);  }   }

What is happening is that if i run the app normally the first cycle the app uses the callback correctly and record is launched, after x time the recording autostops trough stopRecorder() function. Here the motion detector callback is not running anymore, while if i'm testing the app in debug mode everything works perfectly.
I have the same problem if i start the app in debug mode and then disconnect the phone
What is the problem? O.o

edit: testing the problem i implemented a callback to log the callback, and i can see that the service is running, the only problem is that nextData is always null on MotionDetector after the first run, maybe is MediaRecorder overwriting access to the camera? why is it working in debug mode then? I even tried disabling proguard

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant