Compare commits
5
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
b208a1853a | ||
|
|
12697ab05a | ||
|
|
c2ad9c6847 | ||
|
|
a111765677 | ||
|
|
4c0c4416fc |
@@ -2,13 +2,6 @@
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
package="com.example.greenwatch">
|
||||
|
||||
<uses-permission android:name="android.permission.INTERNET" />
|
||||
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
|
||||
<uses-permission android:name="android.permission.READ_MEDIA_AUDIO" />
|
||||
<uses-permission android:name="android.permission.READ_MEDIA_VIDEO" />
|
||||
<uses-permission android:name="android.permission.RECORD_AUDIO" />
|
||||
<uses-permission android:name="android.permission.CAMERA" />
|
||||
|
||||
<application
|
||||
android:allowBackup="true"
|
||||
android:icon="@mipmap/ic_launcher"
|
||||
@@ -16,6 +9,9 @@
|
||||
android:roundIcon="@mipmap/ic_launcher_round"
|
||||
android:supportsRtl="true"
|
||||
android:theme="@style/Theme.GreenWatch">
|
||||
<activity
|
||||
android:name=".Beschleunigungssensor"
|
||||
android:exported="false" />
|
||||
<activity
|
||||
android:name=".MainActivity"
|
||||
android:exported="true">
|
||||
|
||||
@@ -1,225 +0,0 @@
|
||||
package com.example.greenwatch;
|
||||
|
||||
import android.graphics.SurfaceTexture;
|
||||
import android.media.MediaCodec;
|
||||
import android.media.MediaExtractor;
|
||||
import android.media.MediaFormat;
|
||||
import android.media.MediaMuxer;
|
||||
import android.media.MediaRecorder;
|
||||
import android.os.Environment;
|
||||
import android.view.Surface;
|
||||
import android.view.SurfaceHolder;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.nio.ByteBuffer;
|
||||
|
||||
public class AlarmRecorder {
|
||||
private String videoPath;
|
||||
private String audioPath;
|
||||
private MediaFormat videoFormat;
|
||||
private MediaFormat audioFormat;
|
||||
private MediaExtractor videoExtractor;
|
||||
private MediaExtractor audioExtractor;
|
||||
private Runnable audioRecorderRunnable;
|
||||
private Runnable videoRecorderRunnable;
|
||||
private MediaRecorder videoRecorder;
|
||||
private MediaRecorder audioRecorder;
|
||||
//private SurfaceHolder previewHolder;
|
||||
private Surface surface;
|
||||
private Thread videoThread; // Video-Thread als Instanzvariable
|
||||
private Thread audioThread; // Audio-Thread als Instanzvariable
|
||||
|
||||
public AlarmRecorder(SurfaceTexture surfaceTexture) {
|
||||
audioRecorder = new MediaRecorder();
|
||||
videoRecorder = new MediaRecorder();
|
||||
videoExtractor = new MediaExtractor();
|
||||
audioExtractor = new MediaExtractor();
|
||||
this.surface = new Surface(surfaceTexture);
|
||||
}
|
||||
|
||||
public void startRecording() {
|
||||
createStoragePaths(); //Speicherort und -namen für Audio- und Video-Datei
|
||||
|
||||
audioRecorderRunnable = new AudioRecorder(audioRecorder, audioPath);
|
||||
videoRecorderRunnable = new VideoRecorder(videoRecorder, videoPath, surface);
|
||||
audioThread = new Thread(audioRecorderRunnable);
|
||||
videoThread = new Thread(videoRecorderRunnable);
|
||||
|
||||
//Threads starten
|
||||
videoThread.start();
|
||||
audioThread.start();
|
||||
}
|
||||
|
||||
public void stopRecording() {
|
||||
try {
|
||||
stopVideoRecording();
|
||||
stopAudioRecording();
|
||||
|
||||
waitTillThreadsStopped();
|
||||
File videoFile = new File(videoPath); //Speichere das aufgenommene Video
|
||||
File audioFile = new File(audioPath); //Speichere die aufgenommene Audio
|
||||
|
||||
if (videoFile.exists() && audioFile.exists()) {
|
||||
//Wenn Video- und Audioaufzeichnung gestoppt und abgespeichert sind, beginne mit dem Mergeprozess der beiden
|
||||
mergeVideoWithAudio();
|
||||
}
|
||||
} catch (RuntimeException stopException) {
|
||||
stopException.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
private void createStoragePaths(){
|
||||
//Pfade zum Zwischenspeichern der aufgenommenen Audio und Video-Datei
|
||||
String externalStorageDirectory = Environment.getExternalStorageDirectory().getAbsolutePath();
|
||||
String dcimDirectory = externalStorageDirectory + "/DCIM";
|
||||
videoPath = dcimDirectory + "/video.mp4";
|
||||
audioPath = dcimDirectory + "/audio.mp3";
|
||||
}
|
||||
|
||||
private void stopVideoRecording(){
|
||||
if (videoRecorder != null) {
|
||||
videoRecorder.stop();
|
||||
videoRecorder.release();
|
||||
videoRecorder = null;
|
||||
}
|
||||
}
|
||||
|
||||
private void stopAudioRecording(){
|
||||
if (audioRecorder != null) {
|
||||
audioRecorder.stop();
|
||||
audioRecorder.release();
|
||||
audioRecorder = null;
|
||||
}
|
||||
}
|
||||
|
||||
private void waitTillThreadsStopped(){
|
||||
try {
|
||||
videoThread.join();
|
||||
audioThread.join();
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
private void mergeVideoWithAudio() {
|
||||
try {
|
||||
setVideoExtractorDataSource(); //extrahieren der Video Datei, die zuvor zwischengespeichert wurde
|
||||
setAudioExtractorDataSource(); //extrahieren der Audio Datei, die zuvor zwischengespeichert wurde
|
||||
|
||||
//Speicherort der später zusammengeführten Datei
|
||||
String outputFilePath = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_MOVIES).getAbsolutePath() + "/merged_video.mp4";
|
||||
//MediaMuxer zum Zusammenführen einer Audio- und einer Videodatei
|
||||
MediaMuxer muxer = new MediaMuxer(outputFilePath, MediaMuxer.OutputFormat.MUXER_OUTPUT_MPEG_4);
|
||||
int videoTrack = muxer.addTrack(videoFormat);
|
||||
int audioTrack = muxer.addTrack(audioFormat);
|
||||
muxer.start();
|
||||
|
||||
ByteBuffer buffer = ByteBuffer.allocate(1024 * 1024);
|
||||
MediaCodec.BufferInfo bufferInfo = new MediaCodec.BufferInfo();
|
||||
|
||||
videoExtraction(buffer, videoTrack, bufferInfo, muxer);
|
||||
audioExtraction(buffer, audioTrack, bufferInfo, muxer);
|
||||
|
||||
muxer.stop();
|
||||
muxer.release();
|
||||
|
||||
// Löschen der separaten Video- und Audio-Dateien
|
||||
deleteVideoFile();
|
||||
deleteAudioFile();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
private void setVideoExtractorDataSource() {
|
||||
try {
|
||||
videoExtractor.setDataSource(videoPath);
|
||||
int videoTrackIndex = getTrackIndex(videoExtractor, "video/");
|
||||
if (videoTrackIndex < 0) {
|
||||
// Video-Track nicht gefunden
|
||||
return;
|
||||
}
|
||||
videoExtractor.selectTrack(videoTrackIndex);
|
||||
videoFormat = videoExtractor.getTrackFormat(videoTrackIndex);
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
private void setAudioExtractorDataSource() {
|
||||
try {
|
||||
audioExtractor.setDataSource(audioPath);
|
||||
int audioTrackIndex = getTrackIndex(audioExtractor, "audio/");
|
||||
if (audioTrackIndex < 0) {
|
||||
// Audio-Track nicht gefunden
|
||||
return;
|
||||
}
|
||||
audioExtractor.selectTrack(audioTrackIndex);
|
||||
audioFormat = audioExtractor.getTrackFormat(audioTrackIndex);
|
||||
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
private int getTrackIndex(MediaExtractor extractor, String mimeType) {
|
||||
int trackCount = extractor.getTrackCount();
|
||||
for (int i = 0; i < trackCount; i++) {
|
||||
MediaFormat format = extractor.getTrackFormat(i);
|
||||
String trackMimeType = format.getString(MediaFormat.KEY_MIME);
|
||||
if (trackMimeType.startsWith(mimeType)) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
private void videoExtraction(ByteBuffer buffer, int videoTrack, MediaCodec.BufferInfo bufferInfo, MediaMuxer muxer) {
|
||||
videoExtractor.seekTo(0, MediaExtractor.SEEK_TO_CLOSEST_SYNC);
|
||||
while (true) {
|
||||
int sampleSize = videoExtractor.readSampleData(buffer, 0);
|
||||
if (sampleSize < 0) {
|
||||
break;
|
||||
}
|
||||
long presentationTimeUs = videoExtractor.getSampleTime();
|
||||
bufferInfo.offset = 0;
|
||||
bufferInfo.size = sampleSize;
|
||||
bufferInfo.flags = MediaCodec.BUFFER_FLAG_KEY_FRAME;
|
||||
bufferInfo.presentationTimeUs = presentationTimeUs;
|
||||
muxer.writeSampleData(videoTrack, buffer, bufferInfo);
|
||||
videoExtractor.advance();
|
||||
}
|
||||
}
|
||||
|
||||
private void audioExtraction(ByteBuffer buffer, int audioTrack, MediaCodec.BufferInfo bufferInfo, MediaMuxer muxer) {
|
||||
audioExtractor.seekTo(0, MediaExtractor.SEEK_TO_CLOSEST_SYNC);
|
||||
while (true) {
|
||||
int sampleSize = audioExtractor.readSampleData(buffer, 0);
|
||||
if (sampleSize < 0) {
|
||||
break;
|
||||
}
|
||||
long presentationTimeUs = audioExtractor.getSampleTime();
|
||||
bufferInfo.offset = 0;
|
||||
bufferInfo.size = sampleSize;
|
||||
bufferInfo.flags = 0; // or MediaCodec.BUFFER_FLAG_KEY_FRAME
|
||||
bufferInfo.presentationTimeUs = presentationTimeUs;
|
||||
muxer.writeSampleData(audioTrack, buffer, bufferInfo);
|
||||
audioExtractor.advance();
|
||||
}
|
||||
}
|
||||
|
||||
private void deleteVideoFile(){
|
||||
File videoFile = new File(videoPath);
|
||||
if (videoFile.exists()) {
|
||||
videoFile.delete();
|
||||
}
|
||||
}
|
||||
|
||||
private void deleteAudioFile(){
|
||||
File audioFile = new File(audioPath);
|
||||
if (audioFile.exists()) {
|
||||
audioFile.delete();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,30 +0,0 @@
|
||||
package com.example.greenwatch;
|
||||
|
||||
import android.media.MediaRecorder;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
public class AudioRecorder implements Runnable {
|
||||
|
||||
private final MediaRecorder audioRecorder;
|
||||
private final String audioPath;
|
||||
public AudioRecorder(MediaRecorder audioRecorder, String audioPath) {
|
||||
this.audioRecorder = audioRecorder;
|
||||
this.audioPath = audioPath;
|
||||
}
|
||||
@Override
|
||||
public void run() {
|
||||
audioRecorder.setAudioSource(MediaRecorder.AudioSource.DEFAULT);
|
||||
audioRecorder.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4);
|
||||
audioRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AAC);
|
||||
audioRecorder.setOutputFile(audioPath);
|
||||
|
||||
try {
|
||||
audioRecorder.prepare();
|
||||
audioRecorder.start();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,188 @@
|
||||
package com.example.greenwatch;
|
||||
|
||||
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.SharedPreferences;
|
||||
import android.hardware.Sensor;
|
||||
import android.hardware.SensorEvent;
|
||||
import android.hardware.SensorEventListener;
|
||||
import android.hardware.SensorManager;
|
||||
import android.os.Bundle;
|
||||
import android.widget.TextView;
|
||||
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
|
||||
public class Beschleunigungssensor extends AppCompatActivity implements SensorEventListener{
|
||||
|
||||
private SensorManager bsmanager;
|
||||
private ArrayList<Float> Gesamt_be;
|
||||
private int sensorType = Sensor.TYPE_GYROSCOPE, zaehler_runde =0, listen_groesse = 500, kalibrieren, Offset_shared = 0, shared_merk, mittelwertsumme_shared;
|
||||
private Sensor sens, sensor_l;
|
||||
private float x_value = 0, y_value, z_value, Vorbesetzung = 0, gesamt_runde =0;
|
||||
private double Schwellwert = 0.15, mittelwertsumme = 0.0, Offset = 0.1;
|
||||
String Daten, Warnung, Zeitstempel, Array_shared;
|
||||
private final static String KEY_kalibirieren = "KEY_KALIBRIEREN_"+Beschleunigungssensor.class.getSimpleName();
|
||||
private final static String KEY_Gesamt_be = "KEY_GESAMT_BE_"+Beschleunigungssensor.class.getSimpleName();
|
||||
private final static String KEY_Offset = "KEY_OFFSET_"+Beschleunigungssensor.class.getSimpleName();
|
||||
private final static String KEY_Mittelwertsumme = "KEY_MITTELWERTSUMME_"+Beschleunigungssensor.class.getSimpleName();
|
||||
TextView Daten_Bsensor, Warnung_Bsensor, test;
|
||||
private boolean toggle = true, ts_setzen = true, start_messen;
|
||||
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_beschleunigungssensor);
|
||||
|
||||
Daten_Bsensor = (TextView) findViewById(R.id.DatenBsensor);
|
||||
Warnung_Bsensor = (TextView) findViewById(R.id.WarnungBsensor);
|
||||
test = (TextView) findViewById(R.id.test);
|
||||
|
||||
bsmanager = (SensorManager) getSystemService(SENSOR_SERVICE);
|
||||
if (bsmanager.getSensorList(Sensor.TYPE_GYROSCOPE).size() == 0) {
|
||||
sens = null;
|
||||
Daten = "kein B Sensor voranden";
|
||||
} else {
|
||||
sens = bsmanager.getSensorList(sensorType).get(0);
|
||||
}
|
||||
Gesamt_be = new ArrayList<Float>();
|
||||
for (int i = 0; i < listen_groesse ; i++){
|
||||
Gesamt_be.add(Vorbesetzung);
|
||||
}
|
||||
kalibrieren = 0;
|
||||
start_messen = false;
|
||||
}
|
||||
|
||||
public static String getTimestamp(){
|
||||
Long tslong = System.currentTimeMillis();
|
||||
SimpleDateFormat sdf = new SimpleDateFormat("HH:mm:ss");
|
||||
Date date = new Date(tslong);
|
||||
String result = sdf.format(date);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSensorChanged(SensorEvent event) {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append("x=").append(event.values[0])//.append(event.timestamp)
|
||||
.append("\ny=").append(event.values[1])
|
||||
.append("\nz=").append(event.values[2]);
|
||||
Daten = sb.toString();
|
||||
Daten_Bsensor.setText(Daten);
|
||||
gesamt_runde = event.values[0] + event.values[1] + event.values[2];
|
||||
Gesamt_be.remove(zaehler_runde);
|
||||
Gesamt_be.add(zaehler_runde, gesamt_runde);
|
||||
mittelwertsumme = 0.0;
|
||||
|
||||
//Mittelwert des Arrays berechnen
|
||||
for (int i = 0; i < listen_groesse; i++){
|
||||
if (Gesamt_be.get(i) < 0){
|
||||
mittelwertsumme += (Gesamt_be.get(i) * (-1));
|
||||
}else {
|
||||
mittelwertsumme += Gesamt_be.get(i);
|
||||
}
|
||||
}
|
||||
mittelwertsumme = mittelwertsumme/listen_groesse;
|
||||
if (kalibrieren < listen_groesse){
|
||||
Offset = mittelwertsumme;
|
||||
kalibrieren++;
|
||||
}else {
|
||||
start_messen = true;
|
||||
}
|
||||
StringBuilder testsb = new StringBuilder();
|
||||
testsb.append(mittelwertsumme);
|
||||
String tests = testsb.toString();
|
||||
test.setText(tests);
|
||||
|
||||
if((mittelwertsumme > (Schwellwert+Offset) ) & (ts_setzen == true) &(start_messen == true)){
|
||||
Zeitstempel = getTimestamp();
|
||||
StringBuilder ts = new StringBuilder();
|
||||
ts.append(Zeitstempel)
|
||||
.append(", Gruppe3")
|
||||
.append(", An")
|
||||
.append(", Bewegung, ")
|
||||
.append(mittelwertsumme);
|
||||
Warnung = ts.toString();
|
||||
Warnung_Bsensor.setText(Warnung);
|
||||
ts_setzen = false;
|
||||
}else if((mittelwertsumme > (Schwellwert+Offset)) & (ts_setzen == false)){
|
||||
} else if ((mittelwertsumme < (Schwellwert+Offset)) & (ts_setzen == false)) {
|
||||
Warnung_Bsensor.setText("");
|
||||
ts_setzen = true;
|
||||
}
|
||||
|
||||
if (zaehler_runde < (listen_groesse -1)){
|
||||
zaehler_runde++;
|
||||
}else {
|
||||
zaehler_runde = 0;
|
||||
}
|
||||
}
|
||||
//mittelwertsumme ist kein int in diesem programm
|
||||
//shared prefenrences: bei Kippen speichern -> nochmal neu klalibrieren? -> eig ja, weil neuer Standort
|
||||
//Vorbelegung nicht nochmal neu vornehmen -> aus onCreate Funktion raus -> hilfsvariablen auch in shared preferences speichern
|
||||
@Override
|
||||
public void onAccuracyChanged(Sensor sensor, int accuracy) {}
|
||||
|
||||
@Override
|
||||
protected void onResume() {
|
||||
super.onResume();
|
||||
if (sens != null) {
|
||||
if (bsmanager.registerListener(this, sens, SensorManager.SENSOR_DELAY_GAME)) {
|
||||
Daten = "Wir haben uns beim Sensor angemeldet";
|
||||
} else {
|
||||
Daten = "Das anmelden hat nicht geklappt";
|
||||
}
|
||||
}
|
||||
//SharedPreferences p = getPreferences(Context.MODE_PRIVATE);
|
||||
//mittelwertsumme_shared = p.getInt(KEY_Mittelwertsumme, 0);
|
||||
//kalibrieren = p.getInt(KEY_kalibirieren, 0);
|
||||
//Offset_shared = p.getInt(KEY_Offset, 0 );
|
||||
//Array_shared = p.getString(KEY_Gesamt_be, "");
|
||||
|
||||
//mittelwertsumme = (double) mittelwertsumme_shared;
|
||||
//mittelwertsumme /= 1000000.0;
|
||||
|
||||
//Offset = (double) Offset_shared;
|
||||
//Offset /= 1000000.0;
|
||||
|
||||
//String zw[] = Array_shared.split(";", listen_groesse);
|
||||
|
||||
//if(shared_merk == 2){
|
||||
//for (int i=0; i<listen_groesse; i++){
|
||||
//float wert = Float.valueOf(zw[i]);
|
||||
//Gesamt_be.add(i, wert);
|
||||
//}}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected void onPause () {
|
||||
super.onPause();
|
||||
if (sens != null) {
|
||||
bsmanager.unregisterListener(this, sens);
|
||||
}
|
||||
//shared_merk = 2;
|
||||
// Offset_shared = (int) (Offset * 1000000.0);
|
||||
//mittelwertsumme_shared = (int) (mittelwertsumme * 1000000.0);
|
||||
|
||||
//StringBuilder ar = new StringBuilder();
|
||||
//for (int z=0; z < listen_groesse; z++){
|
||||
//ar.append(Gesamt_be.get(z)).append(";");
|
||||
//}
|
||||
//Array_shared = ar.toString();
|
||||
|
||||
//SharedPreferences p = getPreferences(Context.MODE_PRIVATE);
|
||||
//SharedPreferences.Editor editor = p.edit();
|
||||
//editor.putInt(KEY_Mittelwertsumme, mittelwertsumme_shared);
|
||||
//editor.putInt(KEY_kalibirieren, kalibrieren);
|
||||
//editor.putInt(KEY_Offset, Offset_shared);
|
||||
//editor.putString(KEY_Gesamt_be, Array_shared);
|
||||
//editor.commit();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
package com.example.greenwatch;
|
||||
|
||||
public class Kamera {
|
||||
}
|
||||
@@ -1,101 +1,41 @@
|
||||
package com.example.greenwatch;
|
||||
|
||||
import android.Manifest;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.graphics.SurfaceTexture;
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
|
||||
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.view.TextureView;
|
||||
import android.view.View;
|
||||
import android.widget.Button;
|
||||
import android.widget.Toast;
|
||||
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
import androidx.core.app.ActivityCompat;
|
||||
import androidx.core.content.ContextCompat;
|
||||
|
||||
public class MainActivity extends AppCompatActivity implements TextureView.SurfaceTextureListener{
|
||||
public class MainActivity extends AppCompatActivity {
|
||||
|
||||
private boolean isRecording = false;
|
||||
private static final int REQUEST_PERMISSION = 200;
|
||||
private Button button;
|
||||
private TextureView textureView;
|
||||
private AlarmRecorder alarmRecorder;
|
||||
private Button Beschleunigungssensor;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_main);
|
||||
|
||||
button = findViewById(R.id.button);
|
||||
textureView = findViewById(R.id.textureView);
|
||||
textureView.setSurfaceTextureListener(this);
|
||||
|
||||
button.setOnClickListener(new View.OnClickListener() {
|
||||
final Button Beschleunigungssensor = (Button) findViewById(R.id.beschleunigungssensor);
|
||||
Beschleunigungssensor.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
if (!isRecording) {
|
||||
if (ContextCompat.checkSelfPermission(MainActivity.this, Manifest.permission.CAMERA)
|
||||
!= PackageManager.PERMISSION_GRANTED
|
||||
|| ContextCompat.checkSelfPermission(MainActivity.this, Manifest.permission.WRITE_EXTERNAL_STORAGE)
|
||||
!= PackageManager.PERMISSION_GRANTED
|
||||
|| ContextCompat.checkSelfPermission(MainActivity.this, Manifest.permission.RECORD_AUDIO)
|
||||
!= PackageManager.PERMISSION_GRANTED) {
|
||||
ActivityCompat.requestPermissions(MainActivity.this,
|
||||
new String[]{Manifest.permission.CAMERA, Manifest.permission.WRITE_EXTERNAL_STORAGE, Manifest.permission.RECORD_AUDIO},
|
||||
REQUEST_PERMISSION);
|
||||
} else {
|
||||
isRecording = true;
|
||||
alarmRecorder.startRecording();
|
||||
}
|
||||
} else {
|
||||
isRecording = false;
|
||||
alarmRecorder.stopRecording();
|
||||
}
|
||||
Intent intent = new Intent(MainActivity.this, Beschleunigungssensor.class);
|
||||
startActivity(intent);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSurfaceTextureAvailable(SurfaceTexture surfaceTexture, int width, int height) {
|
||||
alarmRecorder = new AlarmRecorder(surfaceTexture);
|
||||
protected void onResume() {
|
||||
super.onResume();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void onSurfaceTextureSizeChanged(SurfaceTexture surface, int width, int height) {
|
||||
// Die Größe der SurfaceTexture hat sich geändert
|
||||
// Hier können entsprechende Anpassungen vorgenommen werden
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onSurfaceTextureDestroyed(SurfaceTexture surface) {
|
||||
// SurfaceTexture wurde zerstört
|
||||
// Hier können entsprechende Bereinigungen durchgeführt werden
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSurfaceTextureUpdated(SurfaceTexture surface) {
|
||||
// SurfaceTexture wurde aktualisiert
|
||||
// Hier können entsprechende Aktionen ausgeführt werden, wenn gewünscht
|
||||
}
|
||||
|
||||
private SurfaceTexture getSurfaceTexture() {
|
||||
return textureView.getSurfaceTexture();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) {
|
||||
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
|
||||
if (requestCode == REQUEST_PERMISSION) {
|
||||
if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
|
||||
// Berechtigungen wurden gewährt
|
||||
Toast.makeText(this, "Berechtigungen gewährt", Toast.LENGTH_SHORT).show();
|
||||
isRecording = true;
|
||||
alarmRecorder.startRecording();
|
||||
} else {
|
||||
// Berechtigungen wurden nicht gewährt
|
||||
Toast.makeText(this, "Berechtigungen nicht gewährt", Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
}
|
||||
protected void onPause() {
|
||||
super.onPause();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
package com.example.greenwatch;
|
||||
|
||||
public class Mikrofon {
|
||||
}
|
||||
@@ -1,39 +0,0 @@
|
||||
package com.example.greenwatch;
|
||||
|
||||
import android.media.MediaRecorder;
|
||||
import android.view.Surface;
|
||||
import android.view.SurfaceHolder;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
public class VideoRecorder implements Runnable{
|
||||
private final MediaRecorder videoRecorder;
|
||||
private final String videoPath;
|
||||
//private SurfaceHolder previewHolder;
|
||||
private Surface surface;
|
||||
|
||||
|
||||
public VideoRecorder(MediaRecorder videoRecorder, String videoPath, Surface surface) {
|
||||
this.videoRecorder = videoRecorder;
|
||||
this.videoPath = videoPath;
|
||||
this.surface = surface;
|
||||
}
|
||||
@Override
|
||||
public void run() {
|
||||
videoRecorder.setVideoSource(MediaRecorder.VideoSource.CAMERA);
|
||||
videoRecorder.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4);
|
||||
videoRecorder.setVideoEncoder(MediaRecorder.VideoEncoder.DEFAULT);
|
||||
videoRecorder.setOutputFile(videoPath);
|
||||
videoRecorder.setOrientationHint(90);
|
||||
videoRecorder.setPreviewDisplay(surface);
|
||||
|
||||
try {
|
||||
videoRecorder.prepare();
|
||||
videoRecorder.start();
|
||||
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,32 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<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"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
tools:context=".Beschleunigungssensor">
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:orientation="vertical">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/DatenBsensor"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/WarnungBsensor"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/test"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="" />
|
||||
</LinearLayout>
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
@@ -6,26 +6,42 @@
|
||||
android:layout_height="match_parent"
|
||||
tools:context=".MainActivity">
|
||||
|
||||
<TextureView
|
||||
android:id="@+id/textureView"
|
||||
android:layout_width="1sp"
|
||||
android:layout_height="1sp"
|
||||
android:visibility="visible"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintHorizontal_bias="1.0"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@id/button"
|
||||
app:layout_constraintVertical_bias="0.0" />
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:orientation="vertical">
|
||||
|
||||
<Button
|
||||
android:id="@+id/button"
|
||||
<TextView
|
||||
android:id="@+id/textView"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginEnd="339dp"
|
||||
android:text="Record Video"
|
||||
app:layout_constraintHorizontal_bias="0.5"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent"/>
|
||||
android:text="TextView"
|
||||
tools:layout_editor_absoluteX="171dp"
|
||||
tools:layout_editor_absoluteY="186dp" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/textView2"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="TextView" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/beschleunigungssensor"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="Beschleunigungssensor" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/aufnahme"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="Aufnahme Start" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/wiedergabe"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="Wiedergabe" />
|
||||
</LinearLayout>
|
||||
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
Reference in New Issue
Block a user