-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Description
I encountered an issue with ASVideoNode where it does not handle HLS video streams properly. Instead of streaming the video in chunks (as expected with HLS), it attempts to load the entire video first, leading to significant delays before playback begins, especially on slower internet connections. The behavior is similar to loading an MP4 file, rather than a stream.
// Get the reverse proxy URL
let cachedVideoURL = HLSVideoCache.shared.reverseProxyURL(from: vURL) ?? vURL
// Create AVURLAsset
let asset = AVURLAsset(url: cachedVideoURL)
// Assign the asset to ASVideoPlayerNode
self.videoPlayerNode.videoNode.asset = asset
self.setupPlayer()
func setupPlayer() {
if let player = videoPlayerNode.videoNode.player {
if player.currentItem?.preferredForwardBufferDuration == 0.0 {
player.automaticallyWaitsToMinimizeStalling = true
if let currentItem = player.currentItem {
currentItem.preferredForwardBufferDuration = 2
currentItem.canUseNetworkResourcesForLiveStreamingWhilePaused = true
currentItem.cancelPendingSeeks()
currentItem.asset.cancelLoading()
}
player.playImmediately(atRate: 1.0)
player.play()
}
}
}
Expected Behavior:
The video should start playing immediately after loading the initial chunks, streaming the rest dynamically as needed (true HLS behavior).
Actual Behavior:
The video does not start playing until the entire content is loaded, resulting in long delays before playback begins.