Skip to content

Commit

Permalink
fix: exposed resetAudioSession method
Browse files Browse the repository at this point in the history
  • Loading branch information
demchuk-alex committed Oct 7, 2024
1 parent a8da97a commit 152acbb
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 2 deletions.
2 changes: 1 addition & 1 deletion ios/AudioController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)")
Expand Down
5 changes: 5 additions & 0 deletions ios/ExpoPlayAudioStreamModule.swift
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@ public class ExpoPlayAudioStreamModule: Module {
audioController.stop(promise: promise)
}

AsyncFunction("resetAudioSession") { promise in
audioController.deactivateAudioSession()
promise.resolve(nil)
}

OnCreate {}
}
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
9 changes: 9 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,13 @@ export class ExpoPlayAudioStream {
throw new Error(`Failed to stop audio: ${error}`);
}
}

static async resetAudioSession(): Promise<void> {
try {
return await ExpoPlayAudioStreamModule.resetAudioSession();
} catch (error) {
console.error(error);
throw new Error(`Failed to reset audio session: ${error}`);
}
}
}

0 comments on commit 152acbb

Please sign in to comment.