A simple Android app to record and play back audio with focus management, device selection, and smooth user experience.
-
Permission Required:
android.permission.RECORD_AUDIO
-
Recording Features:
-
Uses mono channel for efficient recording.
-
Supports popular audio formats.
-
Displays the current active microphone during recording:
-
For Android 12+: uses
AudioManager.getActiveRecordingConfigurations(). -
For Android <12: checks the first element from the active recording list.
-
-
Pause and resume recording at any time.
-
Handles Audio Focus during recording:
-
Short interruptions (e.g., notification sounds, system sounds) → pause recording.
-
Long interruptions (e.g., music app starts, incoming phone call) → stop recording.
-
When focus is regained (e.g., call ends) → resume recording.
-
-
-
Playback Features:
-
Requests audio focus when playing back:
-
Short interruptions → pause playback.
-
Long interruptions → stop playback.
-
Focus regained → resume playback.
-
-
Allows output device selection during playback (for Android 12+):
-
Uses
setCommunicationDevice()to switch between speaker, wired headset, Bluetooth, etc. -
Note: For Bluetooth A2DP devices, media route needs to be set separately.
-
-
On Android <12:
-
Output device change is only supported before playback starts (using
AudioAttributes.Builder.setUsage()). -
(Changing during playback is not implemented yet, but sample code has been tested.)
-
-
-
Kotlin
-
AudioRecord for recording audio
-
MediaPlayer for playback
-
AudioManager for managing active recordings and audio focus
-
MVVM architecture (ViewModel, Repository)
-
Hilt for Dependency Injection
-
Flow/StateFlow for reactive state handling
-
Audio focus is carefully managed to ensure good user experience across interruptions.
-
Device switching is smooth on Android 12+, partially limited on Android <12.
-
The app aims to give maximum control over recording/playback while handling different Android versions gracefully.