Sportronics.MauiMediaRecorderVideoLib
3.2.0
dotnet add package Sportronics.MauiMediaRecorderVideoLib --version 3.2.0
NuGet\Install-Package Sportronics.MauiMediaRecorderVideoLib -Version 3.2.0
<PackageReference Include="Sportronics.MauiMediaRecorderVideoLib" Version="3.2.0" />
<PackageVersion Include="Sportronics.MauiMediaRecorderVideoLib" Version="3.2.0" />
<PackageReference Include="Sportronics.MauiMediaRecorderVideoLib" />
paket add Sportronics.MauiMediaRecorderVideoLib --version 3.2.0
#r "nuget: Sportronics.MauiMediaRecorderVideoLib, 3.2.0"
#:package Sportronics.MauiMediaRecorderVideoLib@3.2.0
#addin nuget:?package=Sportronics.MauiMediaRecorderVideoLib&version=3.2.0
#tool nuget:?package=Sportronics.MauiMediaRecorderVideoLib&version=3.2.0
MauiMediaRecorderVideoLib
A .NET MAUI library for Android video recording plus Audio using MediaRecorder with camera preview and stabilization features.
TNb: HIS README NEEDS AN UPDATE.
Now waits for the user to accept Camera before starting the camera preview.
Both Release and Debug versions of test app work.
Nb: The solution of test app plus this lib as one solution is a private repository.
Test App Repository
About
This library is being developed to target a sporting Photo Timing/Finish app. See djaus2/AthsVideoRecording
Features
- Full-screen camera preview
- Video recording with MediaRecorder
- Now includes audio recording
- Image stabilization options (Standard or Locked)
- Camera rotation support (0, 90, 180, 270 degrees)
- Configurable video FPS (30, 60, or default)
- Support for pausing and resuming recording
- Proper handling of Android permissions
- Screen dimensions detection for optimal preview
- Added: Gun Button Functuionality to append start time to video filename.
- Added: Crosshairs overlay for aiming assistance
- Added: TimeFromMode property to indicate to Stitching app the method to use to determine guntime. (Appends text to video filename)
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 Peview.
Basic Setup
See the sample app for details. The following is a summary of the steps to get started:
- Add the required permissions to your
Android/Manifest.xaml
:
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.RECORD_AUDIO"/>
- Add call to activate permsssions in
Android/MainActivity.cs
:
public class MainActivity : MauiAppCompatActivity
{
protected override void OnCreate(Bundle? savedInstanceState)
{
base.OnCreate(savedInstanceState); // Ensure base initialization always occurs
VideoKapture.RequestPermissionsStatic();
}
}
This is the point at which the app requests permissions. The method actually iterates through the permissions in the Android/Manifest file and requests them.
- In MauiProgram.cs, add the following line to register the library:
using MauiMediaRecorderVideoLib;
Include the Toolkit:
builder
.UseMauiApp<App>()
.UseMauiCommunityToolkitCamera() <- Add this
...
In the Builder setup, add the following lines to register the camera preview handler and configure camera services:
builder.ConfigureMauiHandlers(handlers =>
{
handlers.AddHandler(typeof(CameraPreviewView), typeof(MauiAndroidCameraViewLib.Platforms.Android.CameraPreviewHandler));
});
MauiAndroidCameraViewLib.MauiCameraServicesSetup.ConfigureCameraServices(builder);
The following is in MainPage.cs
:
- Initialize the video recorder service:
using MauiMediaRecorderVideoLib;
// Initialize the service
_VideoKapture = new VideoKapture(this, CameraPreview);
- Submit the video filenamme to the service:
_VideoKapture.OnFilenameCompleted(filename);
- Start Preview:
var activity = Platform.CurrentActivity;
await _VideoKapture.OnButton_GetReady4Recording(activity);
- Start Recording:
await _VideoKapture.OnButton_StartRecording_Clicked();
- Pause Recording:
await _VideoKapture.OnButton_PauseRecording_Clicked();
- Continue Recording:
await _VideoKapture.OnButton_ContinueRecording_Clicked();
- Stop Recording:
await _VideoKapture.OnButton_StopRecording_Clicked();
- A button can be added to toggle visibility of the crosshairs.
The button is added to the XAML file and the code behind is as follows:
_VideoKapture.ViewModel.EnableCrossHairs = !_VideoKapture.ViewModel.EnableCrossHairs;
There is also code to set the framerate at 30 or 60 FPS and to enable image stabilisaztion. See the sample app.
Requirements
- .NET MAUI project targeting Android
- Android API level 21 or higher
- Requires Android device with camera
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net9.0-android35.0 is compatible. net10.0-android was computed. |
-
net9.0-android35.0
- CommunityToolkit.Maui.Camera (>= 2.0.3)
- Microsoft.Extensions.Logging.Debug (>= 9.0.4)
- Microsoft.Maui.Controls (>= 9.0.100)
- Microsoft.Maui.Controls.Compatibility (>= 9.0.60)
- Sportronics.VideoEnums (>= 3.2.0)
- Xamarin.AndroidX.Camera.Camera2 (>= 1.4.2.1)
- Xamarin.AndroidX.Camera.Core (>= 1.4.2.1)
- Xamarin.AndroidX.Camera.Lifecycle (>= 1.4.2.1)
- Xamarin.AndroidX.Camera.Video (>= 1.4.2.1)
- Xamarin.AndroidX.Camera.View (>= 1.4.2.1)
- Xamarin.AndroidX.Core (>= 1.16.0.1)
- Xamarin.AndroidX.Lifecycle.ViewModel.Ktx (>= 2.8.7.3)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last Updated |
---|---|---|
3.2.0 | 107 | 10/7/2025 |
Added Autostart Countdown mode: V3.0.2