Skip to content

An Android phone app that uses a .NET MAUI library for Android video recording library (available on Nuget) using MediaRecorder with Camera Preview and Stabilization features

License

Notifications You must be signed in to change notification settings

djaus2/MauiMediaRecorderVideoAndroidApp

Repository files navigation

MauiMediaRecorderVideoAndroidApp

A test app for the following NuGet package. V2.2.1

NB 2025-05-29

  • See note wrt FPS below

Latest Update 2025-05-22

  • NuGet package update only for it documentation.

Updates 2025-05-21

  • Fixed runtime audio permissions issue using task delays.

Latest Updates 2025-05-15

  • Added Audio (Microphone) Recording
    • First time run get audio errors.
    • Restart app, works then.
  • Added optional CrossHairs to Camera Preview. Button at bottom left to toggle.

Update: 2025-05-14

  • Found that it works in Release mode if AOT is disabled!
    Both Bundle AND APK builds

    Bundle-No AOT config here for Release config.

Uses Nuget Package

NuGet: MauiMediaRecorderVideoLib , a .NET MAUI library for Android video recording using MediaRecorder with Camera Preview and Stabilization features.


About MauiMediaRecorderVideoLib

Nb: Video is stored /Movies folder. Filename is juxtaposed with date.

A .NET MAUI library for Android video recording using MediaRecorder with camera preview and stabilization features.

Latest Version: 2.0.1

Nb This is a work in progress. The library is functional but the test app is not yet fully working in Release mode. (Debug works).

The Test App (here)

Clone this repository, build and deploy to an Android phone.
(Was tested on a Pixel 6 phone)

Change the UI as you wish.


About the library

The library is being developed to target a sporting Photoiming app. See djaus2/PhotoTimingDjaus

Features

  • Full-screen camera preview
  • Video recording with MediaRecorder
    • No audio recording
  • Image stabilization options (Standard or Locked)
  • Camera rotation support (0, 90, 180, 270 degrees)
  • Configurable video FPS (30, 60, or default)
    • Note for 60 FPS with Google Pixel phone need to:
      • Camera Settings
      • Advanced
      • Turn off Store videos efficiently
      • Probably best to do that for 30 FPS as well otherwise get dynamic FPS
  • Support for pausing and resuming recording
  • Proper handling of Android permissions
  • Screen dimensions detection for optimal preview

Usage with a MAUI Android Phone App

Installation

Start by creating a new .NET MAUI project or using an existing one.

Install the package via NuGet:

dotnet add package MauiMediaRecorderVideoLib

Also need to install the following NuGet package:

dotnet add package CommunityToolkit.Maui.Camera

Nb: CommunityToolkit.Maui.Camera is in the library but needs a reference in the App as it uses the Toolkit Preview.

Basic Setup

  1. Add the required permissions to your Android Manifest:
<uses-permission android:name="android.permission.CAMERA" />

Note: In app Android//MainActivity calls permissions setup via static method in library that iterates through in-app Android/Manifest permissions.

The following needs updating (2Do).

  1. Initialize the video recorder service:
using MauiMediaRecorderVideoLib;

// Initialize the service
var videoRecorderService = new AndroidVideoRecorderService();
await videoRecorderService.InitializeAsync();
  1. Start the camera preview:
// Assuming you have a GraphicsView named 'cameraPreview' in your XAML
videoRecorderService.SetPreviewSurface(cameraPreview);
  1. Start recording:
// Configure recording options
videoRecorderService.SetVideoFPS(30); // Optional: Set FPS
videoRecorderService.SetImageStabilization(StabilizationMode.Locked); // Optional: Set stabilization

// Start recording

string outputFilePath = Path.Combine(FileSystem.CacheDirectory, "myVideo.mp4");
await videoRecorderService.StartRecordingAsync(outputFilePath);
  1. Control recording:
// Pause recording
await videoRecorderService.PauseRecordingAsync();

// Resume recording
await videoRecorderService.ResumeRecordingAsync();

// Stop recording
await videoRecorderService.StopRecordingAsync();
  1. Clean up resources:
// Release resources when done
await videoRecorderService.CleanupAsync();

Requirements

  • .NET MAUI project targeting Android
  • Android API level 21 or higher
  • Requires Android device with camera

About

An Android phone app that uses a .NET MAUI library for Android video recording library (available on Nuget) using MediaRecorder with Camera Preview and Stabilization features

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages