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

UI Example

Audio Recorder UI
Audio Recorder UI 2

Usage

  1. Initialize the Recorder final audioRecorderService = AudioRecorderService(); await audioRecorderService.initializeNotifications();
  2. Start Recording await audioRecorderService.startRecording();
  3. Pause Recording await audioRecorderService.pauseRecording();
  4. Resume Recording await audioRecorderService.resumeRecording();
  5. Stop Recording await audioRecorderService.stopRecording();

Android Setup

To enable background recording, you need to update AndroidManifest.xml and build.gradle.

  1. Modify AndroidManifest.xml Location: 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>`
  1. Modify android/app/build.gradle Location: 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