iOS YTPlayerView HTTP Load Failed Error Code: -999
Sep 7, 2018 · 1 min read
I was building an iOS application with YouTube-Player-iOS-Helper cocoapod library, and I kept getting this error, HTTP load failed (error code: -999).
I searched around for a solution, but all I found was setting the flag, NSAllowsArbitraryLoads to true. Although it seemed to be the right answer, this alone did not solve my problem.
Then I found out from the official Google developers website the below:
- Reuse your existing, loaded
YTPlayerViewinstances when possible. When a video needs to be changed in a View, don't create a newUIViewinstance or a newYTPlayerViewinstance, and don't call eitherloadVideoId:orloadPlaylistId:. Instead, use the thecueVideoById:startSeconds:suggestedQuality:family of functions, which do not reload theUIWebView. There is a noticeable delay when loading the entire iframe player.
So I made a static YTPlayerView and loaded a video using loadVideoId:at first. All next videos were loaded using cueVideoById:startSeconds:suggestedQuality:. Doing so solved my problem.