Recording working but only on camera detection

This commit is contained in:
Bastian Kohler 2023-06-22 00:29:16 +02:00
parent b976e9ae32
commit bd8371d96d
5 changed files with 42 additions and 4 deletions

View File

@ -73,7 +73,20 @@ public class DetectorService extends LifecycleService {
@Override @Override
public void onDetection(@NonNull DetectionReport detectionReport) { public void onDetection(@NonNull DetectionReport detectionReport) {
//passToServiceListener(detectionReport); //passToServiceListener(detectionReport);
if(detectionReport.detectionState){
detectedVideo = true;
videoDetector.startRecording();
} else {
detectedVideo = false;
if(!(detectedVideo || detectedAudio || detectedMotion)) {
videoDetector.stopRecording();
}
}
wifiCommunication.sendTrue(detectionReport.toMessage()); wifiCommunication.sendTrue(detectionReport.toMessage());
} }
}); });
/** Motion Detection**/ /** Motion Detection**/

View File

@ -134,7 +134,7 @@ public class VideoDetector extends Detector {
if (isRecording){ if (isRecording){
return; return;
} }
Toast.makeText(context, "video recording started", Toast.LENGTH_SHORT).show();
videoCapture = setupVideoCapture(); videoCapture = setupVideoCapture();
final ListenableFuture<ProcessCameraProvider> cameraProviderFuture = ProcessCameraProvider.getInstance(context); final ListenableFuture<ProcessCameraProvider> cameraProviderFuture = ProcessCameraProvider.getInstance(context);

View File

@ -9,6 +9,7 @@ import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.widget.AdapterView; import android.widget.AdapterView;
import android.widget.ArrayAdapter; import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.ListView; import android.widget.ListView;
import android.widget.PopupWindow; import android.widget.PopupWindow;
import android.widget.Toast; import android.widget.Toast;
@ -25,12 +26,28 @@ import java.util.List;
public class VideoListFragment extends Fragment { public class VideoListFragment extends Fragment {
private ListView listView; private ListView listView;
private Button button;
private ArrayAdapter<String> adapter; private ArrayAdapter<String> adapter;
@Override @Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.videolist_fragment, container, false); View rootView = inflater.inflate(R.layout.videolist_fragment, container, false);
button = rootView.findViewById(R.id.button);
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
File dir = getContext().getFilesDir();
File[] files = dir.listFiles();
for (File file: files) {
file.delete();
}
}
});
listView = rootView.findViewById(R.id.listView); listView = rootView.findViewById(R.id.listView);
adapter = new ArrayAdapter<>(requireContext(), android.R.layout.simple_list_item_1, getFileNames()); adapter = new ArrayAdapter<>(requireContext(), android.R.layout.simple_list_item_1, getFileNames());
listView.setAdapter(adapter); listView.setAdapter(adapter);

View File

@ -1,5 +1,6 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" <androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools" xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
@ -13,4 +14,12 @@
android:layout_height = "wrap_content" android:layout_height = "wrap_content"
tools:ignore="MissingConstraints" /> tools:ignore="MissingConstraints" />
<Button
android:id="@+id/button"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Aufnahmen Löschen"
app:layout_constraintBottom_toBottomOf="parent"
tools:ignore="MissingConstraints" />
</androidx.constraintlayout.widget.ConstraintLayout> </androidx.constraintlayout.widget.ConstraintLayout>

View File

@ -1,13 +1,12 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent">
android:paddingVertical="100dp">
<VideoView <VideoView
android:id="@+id/videoView" android:id="@+id/videoView"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:layout_gravity="center_vertical"/> android:layout_gravity="center"/>
</FrameLayout> </FrameLayout>