can Audiokit audioplayer stream audio?

64 Views Asked by At

I am using Youtubekit to get an audiostream and i tried to use audiokit audiplayer to play it but I keep getting errors

Failed to load and play sound: Error Domain=com.apple.coreaudio.avfaudio Code=2003334207 "(null)" UserInfo={failed call=ExtAudioFileOpenURL((CFURLRef)fileURL, &_extAudioFile)}

code:


    override init() {
        
                mixer = Mixer()
                mixer.addInput(player)
                engine.output = mixer

                do {
                    try AudioKit.Settings.setSession(category: .playAndRecord, with: [.allowBluetoothA2DP, .allowAirPlay])
                    try engine.start()
                } catch {
                    print("AudioEngine Error: \(error)")
                }
}


    func prepareAKToPlay(url: URL) {
        // Load the URL for streaming
        player.isBuffered = false // Set to false for streaming
        player.stop() // Stop the player if it was already playing something

        do {
            try player.load(url: url, buffered: false) // Load the remote URL
            player.play() // Start playback
        } catch {
            print("Failed to load and play sound: \(error)")
        }
    }

I can actually stream the audio using an AVplayer with an AVplayeritem

self.playerItem = AVPlayerItem(url: audioURL)
self.audioPlayer = AVPlayer(playerItem: self.playerItem)

but I wanted to use audiokit to improve latency ( Karaoke app: record and play at the same time) the AKrecorder already works but streaming audio with Audiokit doesn't...

how to stream audio with audiokit? (remote url)

0

There are 0 best solutions below