From 152acbbcd6b3173b985e92f11a48fac2dcb88471 Mon Sep 17 00:00:00 2001 From: Alexander Demchuk Date: Mon, 7 Oct 2024 13:48:00 +0200 Subject: [PATCH] fix: exposed resetAudioSession method --- ios/AudioController.swift | 2 +- ios/ExpoPlayAudioStreamModule.swift | 5 +++++ package.json | 2 +- src/index.ts | 9 +++++++++ 4 files changed, 16 insertions(+), 2 deletions(-) diff --git a/ios/AudioController.swift b/ios/AudioController.swift index 09a509e..c943315 100644 --- a/ios/AudioController.swift +++ b/ios/AudioController.swift @@ -220,10 +220,10 @@ public class AudioController { public func stop(promise: Promise) { self.safeStop() // Stop the audio player node do { - // try self.deactivateAudioSession() // Deactivate the session if !self.bufferQueue.isEmpty { self.bufferQueue.removeAll() } + try self.deactivateAudioSession() // Deactivate the session promise.resolve(nil) } catch { promise.reject("PLAYBACK_STOP", "Failed to deactivate audio session: \(error.localizedDescription)") diff --git a/ios/ExpoPlayAudioStreamModule.swift b/ios/ExpoPlayAudioStreamModule.swift index e3a438c..85881a2 100644 --- a/ios/ExpoPlayAudioStreamModule.swift +++ b/ios/ExpoPlayAudioStreamModule.swift @@ -36,6 +36,11 @@ public class ExpoPlayAudioStreamModule: Module { audioController.stop(promise: promise) } + AsyncFunction("resetAudioSession") { promise in + audioController.deactivateAudioSession() + promise.resolve(nil) + } + OnCreate {} } } diff --git a/package.json b/package.json index 20ee67f..3fa0618 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@mykin-ai/expo-audio-stream", - "version": "0.1.26", + "version": "0.1.27", "description": "Expo Play Audio Stream module", "main": "build/index.js", "types": "build/index.d.ts", diff --git a/src/index.ts b/src/index.ts index de478e2..5bdd465 100644 --- a/src/index.ts +++ b/src/index.ts @@ -49,4 +49,13 @@ export class ExpoPlayAudioStream { throw new Error(`Failed to stop audio: ${error}`); } } + + static async resetAudioSession(): Promise { + try { + return await ExpoPlayAudioStreamModule.resetAudioSession(); + } catch (error) { + console.error(error); + throw new Error(`Failed to reset audio session: ${error}`); + } + } }