How to stream fmp4 with AVFoundation

Hi,

I have an app that uses AVPlayer to stream and play videos (HLS) but I'm struggling to find a way to do the same with fmp4.

This is what I use to play my HLS stream. I tried just to replace the url with the fmp4 one but it does not work.

private func connect() {
        let stringUrl = "https://wolverine.raywenderlich.com/content/ios/tutorials/video_streaming/foxVillage.m3u8"
        let url = URL(string: stringUrl)!
        let asset = AVURLAsset(url: url)
        let item = AVPlayerItem(asset: asset)

        if #available(iOS 10.0, *) {
            item.preferredForwardBufferDuration = Double(50000) / 1000
        }
        if #available(iOS 13.0, *) {
            item.automaticallyPreservesTimeOffsetFromLive = true
        }

        self.player = AVPlayer(playerItem: item)
        let playerLayer = AVPlayerLayer(player: self.player)
        playerLayer.frame = self.playerView.bounds
        playerLayer.videoGravity = .resizeAspect
        self.playerView.layer.addSublayer(playerLayer)
        self.videoLayer = playerLayer
        self.videoLayer?.frame = self.playerView.bounds

        player?.play()
    }

I haven't got any luck looking for a possible solution and I'm out of ideas. I'll be really grateful if anyone of you could point me to a good direction.

Forgot to mention this: the fmp4 streams I'm trying to play does not have a manifest.

The workaround on Android was to use ProgressiveMediaSource on Exoplayer. That made the player ignore the fact that there is no manifest and play the stream.

Forgot to mention this: the url has no file extension

How to stream fmp4 with AVFoundation
 
 
Q