N
N
nuclear_kote2020-06-24 00:48:43
iOS
nuclear_kote, 2020-06-24 00:48:43

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)
           }
    }
    
}


16 seconds pass before the start of the first track. Can this be speeded up somehow?
Files by url weigh only 10kb, so there is hardly a network delay

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question