In this video it shows the steps to develop a CCTV kind of video recording App to continuously record the videos using the Android device camera. It splits the recording into different files.
In this video it refers the code from our below page:
https://programmerworld.co/android/how-to-develop-a-video-recorder-android-app-android-14-api-34/
I hope you like this video. For any questions, suggestions or appreciation please contact us at: https://programmerworld.co/contact/ or email at: programmerworld1990@gmail.com
Complete source code and other details:
package com.programmerworld.videorecoerdingcctvapp;
import static android.Manifest.permission.CAMERA;
import static android.Manifest.permission.READ_MEDIA_AUDIO;
import static android.Manifest.permission.READ_MEDIA_IMAGES;
import static android.Manifest.permission.READ_MEDIA_VIDEO;
import static android.Manifest.permission.RECORD_AUDIO;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.app.ActivityCompat;
import android.content.pm.PackageManager;
import android.media.MediaRecorder;
import android.os.Bundle;
import android.os.storage.StorageManager;
import android.os.storage.StorageVolume;
import android.view.SurfaceView;
import android.view.View;
import android.widget.Toast;
import java.io.File;
import java.io.IOException;
public class MainActivity extends AppCompatActivity {
private SurfaceView surfaceView;
private MediaRecorder mediaRecorder;
private StorageManager storageManager;
private StorageVolume storageVolume;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ActivityCompat.requestPermissions(this,
new String[]{CAMERA,
READ_MEDIA_VIDEO,
READ_MEDIA_IMAGES,
READ_MEDIA_AUDIO,
RECORD_AUDIO},
PackageManager.PERMISSION_GRANTED);
surfaceView = findViewById(R.id.surfaceView);
storageManager = (StorageManager) getSystemService(STORAGE_SERVICE);
storageVolume = storageManager.getStorageVolumes().get(0); // 0 for internal storage
}
private void startVideoRecording(){
File fileVideo = new File(storageVolume.getDirectory().getPath() +
"/Download/" +
System.currentTimeMillis()+".mp4");
mediaRecorder = new MediaRecorder(this);
mediaRecorder.setVideoSource(MediaRecorder.VideoSource.CAMERA);
mediaRecorder.setAudioSource(MediaRecorder.AudioSource.MIC);
mediaRecorder.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4);
mediaRecorder.setVideoEncoder(MediaRecorder.VideoEncoder.DEFAULT);
mediaRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.DEFAULT);
mediaRecorder.setOutputFile(fileVideo.getPath());
mediaRecorder.setMaxDuration(5000); // 5 seconds of max recording
mediaRecorder.setMaxFileSize(5000000); // Max 5 MB
mediaRecorder.setPreviewDisplay(surfaceView.getHolder().getSurface());
try {
mediaRecorder.prepare();
} catch (IOException e) {
Toast.makeText(this, e.toString(), Toast.LENGTH_LONG).show();
}
mediaRecorder.start();
mediaRecorder.setOnInfoListener(new MediaRecorder.OnInfoListener() {
@Override
public void onInfo(MediaRecorder mediaRecorder, int i, int i1) {
if (i == MediaRecorder.MEDIA_RECORDER_INFO_MAX_DURATION_REACHED){
mediaRecorder.stop();
mediaRecorder.release();
startVideoRecording();
}
}
});
}
public void buttonStartVideoRecording(View view){
startVideoRecording();
}
public void buttonStopVideoRecording(View view){
mediaRecorder.stop();
mediaRecorder.release();
}
}
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">
<uses-feature
android:name="android.hardware.camera"
android:required="false" />
<uses-permission android:name="android.permission.READ_MEDIA_VIDEO"/>
<uses-permission android:name="android.permission.READ_MEDIA_IMAGES"/>
<uses-permission android:name="android.permission.READ_MEDIA_AUDIO"/>
<uses-permission android:name="android.permission.CAMERA"/>
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.RECORD_AUDIO"/>
<application
android:allowBackup="true"
android:dataExtractionRules="@xml/data_extraction_rules"
android:fullBackupContent="@xml/backup_rules"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/Theme.VideoRecoerdingCCTVApp"
tools:targetApi="31">
<activity
android:name=".MainActivity"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
<?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=".MainActivity">
<Button
android:id="@+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="18dp"
android:layout_marginTop="41dp"
android:onClick="buttonStartVideoRecording"
android:text="Start Recording"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<Button
android:id="@+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="44dp"
android:layout_marginTop="41dp"
android:onClick="buttonStopVideoRecording"
android:text="Stop Recording"
app:layout_constraintStart_toEndOf="@+id/button"
app:layout_constraintTop_toTopOf="parent" />
<SurfaceView
android:id="@+id/surfaceView"
android:layout_width="337dp"
android:layout_height="384dp"
android:layout_marginStart="37dp"
android:layout_marginTop="93dp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/button" />
</androidx.constraintlayout.widget.ConstraintLayout>
Screenshots:
Project Folder:
Complete project folder can be accessed from the below link on Payment of USD 9.
https://drive.google.com/file/d/160kyFiGJDYKFdmI3xEko45hWVJxWmZC2/view?usp=drive_link
Excerpt:
This video demonstrates how to develop a CCTV-style video recording app for Android using the device’s camera. The tutorial includes code references and provides a link to the source code. The app splits recordings into separate files and includes features like setting a maximum recording duration and file size. The project folder is available for download upon payment of $10, with access details provided upon confirmation. For questions and access, contact the developer via the provided email or website.