Skip to main content
Background Audio enables native, continuous microphone recording in your Median-powered app, even when the app is in the background or the device is locked. The plugin records continuously with persistent notifications on Android and system-level recording indicators on iOS, plus real-time state updates and optional on-device speech-to-text transcription. The plugin supports start, stop, pause, and resume controls with real-time event callbacks for state changes and optional transcript delivery. Implement it using async JavaScript on top of the Median JavaScript Bridge.

Why use background audio

  • Background and lock screen recording: Keep capturing audio when users leave the app or lock the device.
  • Native platform UX: Surface a persistent Android foreground service notification and iOS system recording indicators without custom native code.
  • Lifecycle controls: Start, stop, pause, and resume without releasing the background session when pausing.
  • Realtime updates: Listen for recording state changes and handle completion or errors in your UI.

Prerequisites

  • Enable the JavaScript Bridge in your Median app
  • Grant microphone permission before or during your recording flow (see checkPermission and requestPermission)
  • Learn the basics of async JavaScript (async / await) and the optional callbacks used below
Key terms The following terms will help you implement Background Audio effectively: AVAudioSession (iOS): The app activates the native audio session in background mode while recording. The system shows a recording indicator in the Dynamic Island (iPhone 14+) or status bar pill while the session is active. Foreground service (Android): The Android component that runs while recording, showing a persistent notification with app icon, name, status text, and actions. On-device speech-to-text (STT): The plugin can produce optional transcription during recording. Configure it with enableTranscription and sttLanguage. Availability can vary by locale. Listener events: Real-time callbacks for lifecycle changes (idle, recording, paused, stopped, error).
Important considerations
  • iOS shows a system-level recording indicator (orange dot with waveform animation while actively recording); it hides when recording stops.
  • Android shows status text such as “audio recording in progress” or “paused” and exposes Launch App and Stop Recording actions on the notification.
  • WAV works only on iOS; Android automatically uses M4A if you request WAV.
  • OS interruptions (for example, calls or Siri) can pause the session (SESSION_INTERRUPTED); handle error listener state and the error reference table.

Implementation guide

Plugin setup

Enable the Background Audio plugin in your Median App Studio configuration, then rebuild your app. Once you enable it, you can call median.backgroundAudio.* functions from the JavaScript Bridge at runtime.

JavaScript Bridge functions

The following methods are available on median.backgroundAudio. Most functions return a promise; getStatus additionally supports a callback form.

Check permissions

Returns whether the user has already granted microphone permission. This method returns a promise.
Return value:

Request permissions

Prompts the user for microphone permission. If the user grants it, you can start recording. This method returns a promise.
Return value:

Start recording

Starts a background-aware recording session. Optional configuration controls format, duration, and transcription. This method returns a promise.
Parameters: Return value:

Platform UX during recording

When startRecording succeeds, each platform surfaces native UI automatically. You do not need additional manifest or Info.plist changes beyond enabling the plugin and declaring standard microphone usage descriptions.
Android: Foreground service notification
Android displays a persistent notification with:
  • App icon and name
  • Status text: “audio recording in progress” or “paused”
  • Two action buttons:
    • Launch App: deep-links back into the app
    • Stop Recording: terminates the session and launches the app
iOS: Recording indicator and audio session
iOS activates AVAudioSession with background mode and displays a system-level recording indicator while the session is active:
  • Dynamic Island (iPhone 14+) or status bar pill
  • Red dot with waveform animation during active recording
  • iOS hides it automatically when recording stops

Pause recording

Pauses an active recording without releasing the background session. This method returns a promise.
Return value: Returns a status object reflecting the updated recording state.

Resume recording

Resumes a paused session. This method returns a promise.
Parameters: This function takes no parameters. Return value: Returns a status object reflecting the updated recording state.

Stop recording

Stops the session and retrieves the file URI, duration, and optional transcript. This method returns a promise.
Parameters: This function takes no parameters. Return value:

Get status

Returns the current recording state and elapsed time. Pass a callback function to use the callback form. Otherwise, this method returns a promise.
Parameters: Return value:
Example JSON:

Add a listener

Registers a listener for real-time recording lifecycle updates. Returns a listener identifier that you pass to removeListener.
Parameters: Return value: Returns a listener identifier (opaque value) that you pass to removeListener. Event states you may receive:

Remove a listener

Removes a previously added listener so it stops receiving further events.
Parameters: Return value: No return value.

Error handling

Best practices for error handling

ImportantUse the listener error state and the errorCode it provides together with this reference table when presenting in-app guidance. Combine it with getStatus checks before issuing pause, resume, or stop commands to avoid NOT_RECORDING and ALREADY_RECORDING race conditions.

Example implementation

The following example shows the basic recording flow.

Basic recording flow

Step 1: Check permissions

Before starting a recording session, check if the user has granted microphone permissions:

Step 2: Request permission (if needed)

If permissions haven’t been granted, prompt the user:

Step 3: Start recording

Start a background-aware recording session with optional configuration: Minimal configuration:
Full configuration:
HTML example:

Sequence diagram

High-level view: permission gate → start recording → success or failure.

Testing checklist

Use this checklist to ensure Background Audio is working correctly in your app:

Basic functionality

  • checkPermission and requestPermission behave as expected before startRecording
  • Minimal startRecording() and full configuration calls succeed when permitted
  • pause and resume update behavior without releasing the session
  • stopRecording returns fileUri, durationSeconds, and transcript when you enable transcription and the platform supports it
  • Plugin loads without JavaScript errors

Platform testing

  • Android shows the foreground notification with correct status text and Launch App / Stop Recording actions
  • iOS shows the recording indicator during active recording and hides it when stopped
  • WAV records on iOS as documented; Android falls back to M4A when you request WAV
  • Recording continues when you background the app and lock the device

Status and events

  • getStatus returns state and elapsedSeconds via promise and via callback form
  • addListener receives transitions across idle, recording, paused, stopped, and error
  • removeListener stops further callbacks for that id

Error scenarios

  • Your app surfaces the errors in the reference table as documented (PERMISSION_DENIED, ALREADY_RECORDING, NOT_RECORDING, STT_UNAVAILABLE, SESSION_INTERRUPTED, FILE_ERROR)
  • Incoming calls or Siri trigger SESSION_INTERRUPTED, and your listener handles it
  • Denying microphone permission returns PERMISSION_DENIED and surfaces a clear user-facing path to Settings

Troubleshooting

Handle microphone access after PERMISSION_DENIED

Guide the user to the system Settings app to enable the microphone. Confirm you call checkPermission and, if needed, requestPermission before startRecording.

Handle an active session (ALREADY_RECORDING)

Avoid duplicate starts. Use getStatus or your listener state to decide whether to start, resume, or stop instead of calling startRecording again.

Handle missing transcription (STT_UNAVAILABLE)

Speech-to-text may be unavailable for the requested locale. Fall back to the recorded file using fileUri from stopRecording, and consider setting sttLanguage explicitly to a supported locale.

Handle OS interruptions (SESSION_INTERRUPTED)

Interruptions such as phone calls or Siri can pause recording. Inform the user in your UI and let them resume when appropriate via resume.

Android notification actions behave unexpectedly

The notification includes Launch App (deep-links into the app) and Stop Recording (ends the session and launches the app). Test both actions against your app’s navigation stack.
Still having trouble?For issues related to platform-level microphone, background audio, or speech-to-text behavior outside Median, refer to the platform documentation for Apple AVAudioSession and Android foreground services.
Last modified on December 3, 2026