flutter_background_video_recorder 2.1.0
flutter_background_video_recorder: ^2.1.0 copied to clipboard
Record video or audio on Android from a foreground service, with camera and zoom selection, plus raw camera frames and microphone audio streams for your own processing.
2.1.0 #
Raw camera frames and microphone audio for apps that want to process the data themselves, a choice between the cameras of the device, and zoom. Nothing changes for apps that do not use them.
Added #
- Raw frame stream.
openFrameSessionopens a camera and delivers its frames to any number of listeners ofRawFrameSession.framesuntilclose(). Choose the pixel format withRawFrameSettings: YUV 4:2:0 (the default and cheapest), JPEG or RGBA. EachRawFramecarries its planes, a timestamp and the rotation that makes it upright. It runs from its own foreground service, so it continues in the background, and no recording is involved. - Frames are delivered through shared native memory (
dart:ffi), not copied over a platform channel: one native copy per frame, no serialization and no per-frame allocation in Dart. A frame is valid while the listeners run; useRawFrame.retain()/release()ortoOwned()to keep one.RawFrame.droppedFramesreports frames dropped because the app was too slow. This adds a small native library (C++, NDK) to the Android build. - Raw audio stream.
openAudioStreamdelivers the microphone as 16-bit or float PCM chunks to any number of listeners ofRawAudioSession.chunks. Sample rate, channels, source and chunk length are settings. If the app falls behind, sound is dropped andRecorderWarningCode.audioOverrunis reported. - Both streams do no work while nobody listens. They are exclusive with recording where they share
hardware: while a frame session is open, recording a video or showing a preview fails with
RecorderErrorCode.cameraBusy; while an audio stream is open, recording fails withRecorderErrorCode.microphoneBusy. They can run together. - Camera selection.
listCameras()returns the cameras of the device asCameraInfo(position, focal length, zoom range, alensTypeguess). An optionalcameraIdongetVideoCapabilities,startVideoRecording,openFrameSessionandRecorderPreviewpicks one;cameraFacingstill works as before. - Zoom.
setZoom(ratio)zooms the open camera, also while a recording is running, and aninitialZoomonVideoSettings,RawFrameSettingsandRecorderPreviewsets where a session starts.CameraInfo.zoomRangetells what the camera supports. - New error codes
cameraBusy,microphoneBusy,cameraNotActiveandpermissionPermanentlyDenied. While developing, a raw session survives a hot restart, so opening it again reportscameraBusy/microphoneBusy; stop the app and run it again (the error message and the README say so). - The example app has a lens picker, a zoom selector with a fine-control wheel, and a Streams mode that shows the raw streams with several listeners.
Changed #
- A back or front camera is now oriented and mirrored according to the camera that is really used, not the requested facing.
2.0.0 #
Modernized for Android 15 and 16. Breaking changes, see "Migrating from 1.x" in the README.
Breaking #
- Requires Android 12 (
minSdk 31) and Flutter 3.29+. Older Android versions are no longer supported. - Requires Dart 3.7+. The previous constraint (
<3.0.0) prevented the package from resolving on any current Flutter. - The recording service is now declared by the plugin and lives at
com.lightsoftware.flutter_background_video_recorder.plugin.VideoRecorderService. Remove theservices.VideoRecorderServiceentry from your app manifest. startVideoRecordingreturnsStartRecordingResult, and resolves after the permission dialogs are answered.stopRecording(and its aliasstopVideoRecording) returnsRecordedMedia(uri, optionalpath,kind,hasLocation) instead of a file path.- States are the
RecorderStatusenum instead of integers. Errors areRecorderExceptions.getVideoRecordingStatusis nowgetRecordingStatus. - Removed the
showToastparameter and all native toasts. - New barrel library
package:flutter_background_video_recorder/flutter_background_video_recorder.dart.
Fixed #
- Audio was recorded at 8 kHz and about 12 kbps (the platform default when nothing is set). It is now 48 kHz, 128 kbps AAC.
- A
MediaRecordererror (full disk, encoder failure) used to leave the recorder stuck in "recording". Errors now end the recording cleanly and keep what was recorded; running out of storage and overheating are reported as such. - The recorder refuses to start with almost no free storage and caps the file size so the disk is not filled completely.
- The foreground service now declares both camera and microphone types. Before, only the microphone type was used, so the camera was cut off in the background on Android 14+.
POST_NOTIFICATIONSis declared and requested (Android 13+).- Videos are saved through
MediaStore(scoped storage) instead of raw paths in public storage. - The permission flow no longer races, crashes on partial results or swallows other plugins' permission results.
- Recorder state no longer travels over exported broadcasts that other apps could spoof or read.
MediaRecorderstarts only once the capture session is configured, usesTEMPLATE_RECORD, is stopped and released correctly, and a failed or empty recording is discarded.- The service no longer crashes when restarted by the system with a null intent, and recording no longer depends on the Activity being bound.
- Video resolution selection (operator precedence bug, arbitrary fallback) and orientation for rear/front cameras.
- Removed unused
SYSTEM_ALERT_WINDOWandREAD_EXTERNAL_STORAGEpermissions and a duplicateCAMERAdeclaration.
Added #
- Video settings:
getVideoCapabilities()lists the sizes (grouped by aspect ratio), frame rates and codecs a camera supports.VideoSettingschooses resolution, frame rate, codec (h264,hevc,auto) and bitrate. The default is 1080p at 60 fps with fallbacks; an unsupported choice is refused withunsupportedConfiguration. - Audio-only recordings with
startAudioRecording(): microphone permission and foreground type only, saved toRecordings/<folder>. - Location in the video's metadata with
VideoSettings(embedLocation: true). The plugin declares no location permission; the app does. - Preview: the
RecorderPreviewwidget shows a viewfinder before recording and the live picture during a recording started withVideoSettings(preview: true). Hiding it is removing the widget. Front camera preview is mirrored like a mirror. VideoCapabilities.defaultResolution/defaultFrameRate(what a recording uses when nothing is set) andVideoResolution.portraitAspectRatioLabel(9:16for16:9).- The example app is now a camera-style viewfinder: full-screen preview, record button with a live timer, Video / Audio modes, a settings sheet with aspect ratio (with its vertical equivalent), resolution, frame rate and codec, and a landscape layout.
recorderWarningsstream (thermalWarning,previewUnavailable).openAppSettings()to send the user to the system settings when permissions are permanently denied, and a dialog in the example that does so.- When the camera is lost mid-recording, the video recorded so far is saved, a "Recording stopped" notification is shown, and
RecorderException.savedMediapoints to the saved video. - A Stop action, content intent, own icon and channel description on the notification.
recorderErrorsstream for failures while recording (for example the camera was lost).- Tests for the Dart API and the native size, orientation and folder name logic.
Build #
- Videos are written through
MediaStoreonly; the Android 9 file-path code andWRITE_EXTERNAL_STORAGEare gone with theminSdk 31change. - Kotlin, AGP 8.9, Gradle 8.12, Java 17,
compileSdk36. The plugin namespace was corrected.
1.0.0+2 #
- Added support for Android 14
0.0.9+1 #
- Fixed an issue that caused the plugin to not start recording when permissions are granted
0.0.9 #
- Updated documentation and example
- Updated dart code to implement
showToastproperty
0.0.8 #
- You can now hide the toasts by setting the
showToastproperty to false when callingstartVideoRecording()
0.0.7 #
- Added support for front camera
0.0.6 #
- Updated documentation and README
0.0.5 #
- Fixed an issue which caused the plugin to crash when app is closed causing the recording to continue until force stopped.
0.0.4 #
- Fixed an issue that caused start recording to fail for the first time
0.0.3 #
- Removed permission to draw over other apps
- Added more documentation to code
0.0.2 #
- Updated README.md
0.0.1 #
- Initial release
