AVPlayer - play network video with separate audio URL without downloading the files first : <p>I'm currently trying to play a video using <code>AVPlayer</code> that has separate sources for video and audio, so I combine them into a single <code>AVPlayerItem</code> as below:</p>

<pre><code>let videoAsset = AVURLAsset(url: videoURL)
let audioAsset = AVURLAsset(url: audioURL)
let duration = videoAsset.duration
let composition = AVMutableComposition()

let videoTrack = composition.addMutableTrack(withMediaType: AVMediaType.video, preferredTrackID: kCMPersistentTrackID_Invalid)
try? videoTrack?.insertTimeRange(CMTimeRange(start: kCMTimeZero, duration: duration), of: videoAsset.tracks(withMediaType: .video)[0], at: kCMTimeZero)

let audioTrack = composition.addMutableTrack(withMediaType: .audio, preferredTrackID: kCMPersistentTrackID_Invalid)
try? audioTrack?.insertTimeRange(CMTimeRange(start: kCMTimeZero, duration: duration), of: audioAsset.tracks(withMediaType: .audio)[0], at: kCMTimeZero)

let playerItem = AVPlayerItem(asset: composition)
</code></pre>

<p>However the problem is that this code <strong>fetches the entire source</strong> of the video and audio over the network before it completes. Either calling 'videoAsset.duration' or <code>videoTrack.insertTimeRange</code> triggers this network request.</p>

<p>Is there a way to use <code>AVPlayer</code> to play these separate video and audio URLs together (MP4 video and AAC audio) without having to download the entire file first?</p>

<p>I've noticed that on my Mac, Quicktime Player also fetches the source file before it begins playback. However using something like VLC or IINA doesn't and playback can start immediately.</p>

<p>Thanks.</p>
