Answer the question
In order to leave comments, you need to log in
How can I reduce the delay before audio starts playing?
public class Player: CAPPlugin {
var queuePlayer = AVQueuePlayer()
var started = false
@objc func play(_ call: CAPPluginCall) {
guard let audioUrl = call.getString("url") else { return }
print(audioUrl)
guard let url = URL.init(string: audioUrl) else { return }
let playerItem = AVPlayerItem.init(url: url)
if (!started) {
started = true
queuePlayer.play()
}
queuePlayer.insert(playerItem, after: nil)
do {
try AVAudioSession.sharedInstance().setPreferredIOBufferDuration(0.002)
try AVAudioSession.sharedInstance().setCategory(.playAndRecord, options: [.mixWithOthers])
print("Playback OK")
try AVAudioSession.sharedInstance().setActive(true)
print("Session is Active")
} catch {
print(error)
}
}
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question