Reputation: 1794
I have an AVPlayer
that is loading a remote media URL
(HLS
stream) and sometimes the player is never ready to play, but no error is presented. Is there somewhere else an error can be or a way to check if it is still loading the AVPlayerItem
?
I have KVO
for rate, status, and playback likely to keep up which never get called when the video isn't loading. I added a button to check for an error on the player, the player item, and whether playback is likely to keep up. These report nil, nil, and false when the player seems stuck. It seems random when the player gets stuck(refuses to load vidoe at all), it doesn't happen on a specific video.
What other steps can I take to debug this issue? Are there other places to check for errors or status?
More info checked: Playback buffer is empty: true Playback buffer is full: false
Upvotes: 6
Views: 1592
Reputation: 4962
Our solution is before reusing the player, we deallocated the AVPlayer by using player.replaceCurrentItemWithPlayerItem(nil)
. Some reason replacing the current item sometimes caused issues. We also made sure our videos were loading in order, rather than all at once. That seemed to have solved our issue.
Upvotes: 2
Reputation: 35953
To be able to load URLs from remote servers from within your app you have to add this to your info.plist
<key>NSAppTransportSecurity</key>
<dict>
<key>NSExceptionDomains</key>
<dict>
<key>mydomain.com</key>
<dict>
<key>NSIncludesSubdomains</key>
<true/>
<key>NSExceptionAllowsInsecureHTTPLoads</key>
<true/>
<key>NSExceptionRequiresForwardSecrecy</key>
<true/>
<key>NSExceptionMinimumTLSVersion</key>
<string>TLSv1.2</string>
<key>NSThirdPartyExceptionAllowsInsecureHTTPLoads</key>
<false/>
<key>NSThirdPartyExceptionRequiresForwardSecrecy</key>
<true/>
<key>NSThirdPartyExceptionMinimumTLSVersion</key>
<string>TLSv1.2</string>
<key>NSRequiresCertificateTransparency</key>
<false/>
</dict>
</dict>
</dict>
Don't add the lines exactly as I typed. Configure them for your needs. Note that Apple's default configuration for iOS is to expect https
connections, not http
. You must configure it to allow http
.
Upvotes: 1