Skip to content

Commit

Permalink
fix: bufferAccessQueue for scheduleNextBuffer?
Browse files Browse the repository at this point in the history
  • Loading branch information
pax-k committed Jul 15, 2024
1 parent a8556b6 commit 7775d3b
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions ios/AudioController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,6 @@ public class AudioController {
}

private func scheduleNextBuffer() {
// self.bufferAccessQueue.async {
guard let engine = self.audioEngine, engine.isRunning else {
DispatchQueue.main.asyncAfter(deadline: .now() + 0.05) { // Check every 50 milliseconds
self.scheduleNextBuffer()
Expand All @@ -346,19 +345,20 @@ public class AudioController {
// promise(nil)
// }
// }
if let (buffer, promise) = bufferQueue.first {
bufferQueue.removeFirst()

self.audioPlayerNode!.scheduleBuffer(buffer) {
promise(nil)
self.bufferAccessQueue.async {
if let (buffer, promise) = self.bufferQueue.first {
self.bufferQueue.removeFirst()

let bufferDuration = Double(buffer.frameLength) / buffer.format.sampleRate
DispatchQueue.main.asyncAfter(deadline: .now() + bufferDuration) {
self.scheduleNextBuffer()
self.audioPlayerNode!.scheduleBuffer(buffer) {
promise(nil)

let bufferDuration = Double(buffer.frameLength) / buffer.format.sampleRate
DispatchQueue.main.asyncAfter(deadline: .now() + bufferDuration) {
self.scheduleNextBuffer()
}
}
}
}
// }
}

// private func currentQueue() -> [(buffer: AVAudioPCMBuffer, promise: RCTPromiseResolveBlock)] {
Expand Down

0 comments on commit 7775d3b

Please sign in to comment.