audio_recorder_service 0.0.5
audio_recorder_service: ^0.0.5 copied to clipboard
A Flutter Background Service Audio recorder and Notification
Audio Recorder Service #
A Flutter package that provides functionality for recording audio with the ability to pause, resume, and stop the recording. It also includes background notifications to manage the recording state.
Features #
- Start, pause, resume, and stop audio recording.
- Background notifications during recording.
- Supports AAC audio encoding.
- Works across Android platforms.
- Handles recording permissions automatically.
Getting Started #
Usage #
- Initialize the Recorder
final audioRecorderService = AudioRecorderService(); await audioRecorderService.initializeNotifications(); - Start Recording
await audioRecorderService.startRecording(); - Pause Recording
await audioRecorderService.pauseRecording(); - Resume Recording
await audioRecorderService.resumeRecording(); - Stop Recording
await audioRecorderService.stopRecording();
Android Setup #
To enable background recording, you need to update AndroidManifest.xml and build.gradle.
- Modify
AndroidManifest.xmlLocation:android/app/src/main/AndroidManifest.xml
Add Permissions #
Inside <manifest>:
<uses-permission android:name="android.permission.RECORD_AUDIO"/> <uses-permission android:name="android.permission.FOREGROUND_SERVICE"/> <uses-permission android:name="android.permission.POST_NOTIFICATIONS"/> <uses-permission android:name="android.permission.WAKE_LOCK"/> <uses-permission android:name="android.permission.INTERNET"/>
Add Receivers #
Inside <application>:
<receiver android:exported="false" android:name="com.dexterous.flutterlocalnotifications.ScheduledNotificationReceiver" /> <receiver android:exported="false" android:name="com.dexterous.flutterlocalnotifications.ScheduledNotificationBootReceiver"> <intent-filter> <action android:name="android.intent.action.BOOT_COMPLETED"/> <action android:name="android.intent.action.MY_PACKAGE_REPLACED"/> </intent-filter> </receiver> <receiver android:exported="false" android:name="com.dexterous.flutterlocalnotifications.ActionBroadcastReceiver" />
Add Service #
Add this after <activity>:
<service android:name="com.ryanheise.audioservice.AudioService" android:foregroundServiceType="mediaPlayback" android:exported="true" tools:ignore="Instantiatable"> <intent-filter> <action android:name="android.media.browse.MediaBrowserService"/> </intent-filter> </service>
- Modify
android/app/build.gradleLocation:android/app/build.gradle
Ensure the following settings:
compileSdk = 34
minSdk = 23
defaultConfig { multiDexEnabled true // Add this line }
To use this package, add it to your pubspec.yaml:
dependencies:
audio_recorder_service:
path: ../audio_recorder_service