Skip to content

Commit

Permalink
fix: enhanced pause logic
Browse files Browse the repository at this point in the history
  • Loading branch information
demchuk-alex committed Oct 23, 2024
1 parent b53a90a commit 247bbac
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
10 changes: 8 additions & 2 deletions ios/AudioSessionManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -252,14 +252,20 @@ class AudioSessionManager {
} else {
Logger.debug("Queue is empty")
}
resolver(nil)
}

func pauseAudio() {
func pauseAudio(promise: Promise) {
if let node = audioPlayerNode, self.audioEngine.isRunning, node.isPlaying {
node.pause()
node.stop()
self.audioEngine.stop()
self.destroyPlayerNode()
self.audioEngine = AVAudioEngine()
} else {
print("Cannot pause: Engine is not running or node is unavailable.")
}
promise.resolve(nil)
}

private func restartAudioSessionForPlayback() throws {
Expand Down Expand Up @@ -344,7 +350,7 @@ class AudioSessionManager {
Logger.debug("Debug: Configuring audio session with sample rate: \(settings.sampleRate) Hz")

// Create an audio format with the desired sample rate
//let desiredFormat = AVAudioFormat(commonFormat: commonFormat, sampleRate: newSettings.sampleRate, channels: UInt32(newSettings.numberOfChannels), interleaved: true)
let desiredFormat = AVAudioFormat(commonFormat: commonFormat, sampleRate: newSettings.sampleRate, channels: UInt32(newSettings.numberOfChannels), interleaved: true)

// Check if the input node supports the desired format
let inputNode = audioEngine.inputNode
Expand Down
3 changes: 1 addition & 2 deletions ios/ExpoPlayAudioStreamModule.swift
Original file line number Diff line number Diff line change
Expand Up @@ -142,8 +142,7 @@ public class ExpoPlayAudioStreamModule: Module, AudioStreamManagerDelegate {
}

AsyncFunction("pauseAudio") { (promise: Promise) in
audioSessionManager.pauseAudio()
promise.resolve(nil)
audioSessionManager.pauseAudio(promise: promise)
}


Expand Down

0 comments on commit 247bbac

Please sign in to comment.