Update AudioSessionManager.mm

Signed-off-by: rohithzmoi <166651631+rohithzmoi@users.noreply.github.com>
This commit is contained in:
rohithzmoi 2024-09-07 23:34:05 +05:30 committed by GitHub
parent e45a7b7d14
commit a335bb630c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 13 additions and 2 deletions

View File

@ -18,6 +18,11 @@
#import <AVFoundation/AVFoundation.h> #import <AVFoundation/AVFoundation.h>
#import <UIKit/UIKit.h> #import <UIKit/UIKit.h>
extern "C" void AudioEngine_stop_playback();
extern "C" void AudioEngine_start_playback();
static UIBackgroundTaskIdentifier bgTask = UIBackgroundTaskInvalid; static UIBackgroundTaskIdentifier bgTask = UIBackgroundTaskInvalid;
@ -81,12 +86,18 @@ extern "C" void setupAVAudioSession() {
reason == AVAudioSessionRouteChangeReasonNewDeviceAvailable || reason == AVAudioSessionRouteChangeReasonNewDeviceAvailable ||
reason == AVAudioSessionRouteChangeReasonOverride) { reason == AVAudioSessionRouteChangeReasonOverride) {
NSLog(@"Audio route change detected, attempting to reactivate..."); NSLog(@"Audio route change detected, attempting to reactivate...");
// Call C++ function to stop playback
AudioEngine_stop_playback();
NSError *activationError = nil; NSError *activationError = nil;
BOOL reactivationSuccess = [session setActive:YES error:&activationError]; BOOL reactivationSuccess = [session setActive:YES error:&activationError];
AudioEngine_start_playback();
if (!reactivationSuccess) { if (!reactivationSuccess) {
NSLog(@"Error re-activating AVAudioSession after route change: %@, code: %ld", activationError.localizedDescription, (long)activationError.code); NSLog(@"Error re-activating AVAudioSession after route change: %@, code: %ld", activationError.localizedDescription, (long)activationError.code);
} else { } else {
NSLog(@"Audio session successfully reactivated after route change"); NSLog(@"Audio session successfully reactivated after route change");
// Call C++ function to start playback
//AudioEngine_start_playback();
} }
} }
}]; }];