Skip to content

Conversation

@REU8ER
Copy link

@REU8ER REU8ER commented Dec 28, 2025

Description

This PR fixes an issue where audio from external apps (YouTube Music, Spotify, Apple Music, etc.) would not automatically resume after stopping, canceling, or pausing a recording.

Problem

Android

  • Used AUDIOFOCUS_GAIN (permanent focus) instead of AUDIOFOCUS_GAIN_TRANSIENT (temporary focus)
  • The cancel() method did not call restoreAudioManagerSettings() to release audio focus
  • Result: External apps did not resume playback automatically

iOS

  • Audio session was activated on start() but never deactivated on stop(), pause(), or cancel()
  • Result: External apps did not resume playback automatically

Solution

Android Changes

  1. Changed from AUDIOFOCUS_GAIN to AUDIOFOCUS_GAIN_TRANSIENT in requestAudioFocus()
    • This signals to Android that the audio focus is temporary
    • Other apps will automatically resume when focus is released
  2. Added restoreAudioManagerSettings() call in cancel() method
    • Ensures audio focus is properly released on cancel

iOS Changes

  1. Added deactivateAudioSession() helper function
  2. Call deactivateAudioSession() in stop() and pause() methods of both delegates
    • Properly deactivates the audio session with .notifyOthersOnDeactivation
    • Other apps automatically resume playback

Testing

Tested on:

  • Android 12+ (multiple devices)
  • iOS 15+ (iPhone)

Steps to reproduce/verify:

  1. Start playing music in an external app (YouTube Music, Spotify, etc.)
  2. Start recording → music pauses ✅
  3. Call stop(), cancel(), or pause() → music resumes automatically ✅

Modified Files

Android

  • record_android/android/src/main/kotlin/com/llfbandit/record/record/recorder/AudioRecorder.kt
  • record_android/pubspec.yaml (1.4.5 → 1.4.6)
  • record_android/CHANGELOG.md

iOS

  • record_ios/ios/record_ios/Sources/record_ios/delegate/RecorderFileDelegate.swift
  • record_ios/ios/record_ios/Sources/record_ios/delegate/RecorderStreamDelegate.swift
  • record_ios/ios/record_ios/Sources/record_ios/extension/RecorderSessionExtension.swift
  • record_ios/pubspec.yaml (1.1.5 → 1.1.7)
  • record_ios/CHANGELOG.md

Other

  • record_platform_interface/pubspec.yaml (1.4.0 → 1.4.1)
  • record_macos/pubspec.yaml (1.1.2 → 1.1.3)
  • record/pubspec.yaml (dependencies updated)

Breaking Changes

None. This is a bug fix that improves existing behavior without changing the API.

Checklist

  • Code follows the project's style guidelines
  • Self-review of code completed
  • CHANGELOGs updated
  • Version numbers updated following semantic versioning
  • Tested on Android 12+
  • Tested on iOS 15+

References

…GAIN_TRANSIENT

- Add restoreAudioManagerSettings() call in cancel() method to properly release audio focus
- Change from AUDIOFOCUS_GAIN to AUDIOFOCUS_GAIN_TRANSIENT for temporary audio focus
- This allows other audio apps to automatically resume playback after recording stops

Fixes: Audio from external apps (YouTube Music, Spotify, etc.) not resuming after cancel/pause
- Add deactivateAudioSession() helper function
- Call deactivateAudioSession() in stop() and pause() methods of both delegates
- This properly releases the audio session and notifies other apps to resume

Fixes: Audio from external apps (Apple Music, Spotify, etc.) not resuming after stop/pause/cancel
- record_platform_interface: 1.4.0 -> 1.4.1
- record_android: 1.4.5 -> 1.4.6
- record_ios: 1.1.5 -> 1.1.7
- record_macos: 1.1.2 -> 1.1.3
- Update dependencies in all packages to use compatible versions
Update main package version to reflect audio focus/session fixes on Android and iOS platforms.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant