fix: Release audio focus/session on cancel/pause (Android & iOS) #571
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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
AUDIOFOCUS_GAIN(permanent focus) instead ofAUDIOFOCUS_GAIN_TRANSIENT(temporary focus)cancel()method did not callrestoreAudioManagerSettings()to release audio focusiOS
start()but never deactivated onstop(),pause(), orcancel()Solution
Android Changes
AUDIOFOCUS_GAINtoAUDIOFOCUS_GAIN_TRANSIENTinrequestAudioFocus()restoreAudioManagerSettings()call incancel()methodiOS Changes
deactivateAudioSession()helper functiondeactivateAudioSession()instop()andpause()methods of both delegates.notifyOthersOnDeactivationTesting
Tested on:
Steps to reproduce/verify:
stop(),cancel(), orpause()→ music resumes automatically ✅Modified Files
Android
record_android/android/src/main/kotlin/com/llfbandit/record/record/recorder/AudioRecorder.ktrecord_android/pubspec.yaml(1.4.5 → 1.4.6)record_android/CHANGELOG.mdiOS
record_ios/ios/record_ios/Sources/record_ios/delegate/RecorderFileDelegate.swiftrecord_ios/ios/record_ios/Sources/record_ios/delegate/RecorderStreamDelegate.swiftrecord_ios/ios/record_ios/Sources/record_ios/extension/RecorderSessionExtension.swiftrecord_ios/pubspec.yaml(1.1.5 → 1.1.7)record_ios/CHANGELOG.mdOther
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
References