AVPlayer is never ready to play
Asked Answered
A

2

6

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

Aesthetically answered 21/7, 2016 at 19:38 Comment(8)
Do you actually ask the player to play?Devisor
Yep, I added an extra button to ensure this is happening with no luck still. The same player works in other cases, which is strange. We are changing the player item to reuse to player, and the observers are added to the new item, but logging the states with a button shows the KVO is working correctly, the item just never hits likely to keep up.Aesthetically
Can you post code? Does this happen only when you swap player items and attempt to reuse the player?Repentance
We are reusing the player, but I don't believe it only occurs when we swap player items. We used to not reuse the player, and we believe we still saw it back then. I'll keep a look out, but I don't believe it has to do with player reuse. I'll see if we can get some code on this as well.Aesthetically
Add your code in question that how you managing this!Cuddy
You should add some code, I would check your KVO implementation, try to use it vanilla, and see if the issue still happens.Bowleg
have you added entitlements to your project to allow the application to load something from a remote URL?Communalism
Download AVPlayerDemoPlayer Sample code provided by Apple and check your playback using it. It should not happen unless you have broken stream or poor network.Fondafondant
B
2

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.

Botello answered 26/8, 2016 at 23:5 Comment(0)
C
1

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>

see the docs

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.

Communalism answered 25/8, 2016 at 5:23 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.