Linked Questions

Popular Questions

I'm trying to play an m3u8 stream in VideoPlayer, but it only plays one frame of the stream before freezing. The built-in play button is unresponsive. I get these messages which might be related:

[api] -[CIImage initWithCVPixelBuffer:options:] failed because the buffer is nil.
Metal API Validation Enabled
[MADService] Client XPC connection invalidated

I thought the problem could be the video player view re-rendering, but I tried isolating the player and no change.

import SwiftUI
import AVFoundation
import AVKit

struct VideoPlayerView: View {
    @State private var player: AVPlayer = AVPlayer()
    @State var url: URL?
    var body: some View {
        return
            VideoPlayer(player: player)
                .onAppear {
                    playVideo()
                }
    }
    
    func playVideo() {
        if let newUrl = url {
            let newPlayerItem = AVPlayerItem(url: newUrl)
            player.replaceCurrentItem(with: newPlayerItem)
        } else {
            player.replaceCurrentItem(with: nil)
        }
    }
}

The function playVideo is correctly called once. Can you walk me through how I can diagnose this problem?

edit I tried playing the URL in VLC on MacOS and it works correctly there.

Related Questions