Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AVPlayer is never ready to play

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

like image 462
Alex Yurkowski Avatar asked Jul 21 '16 19:07

Alex Yurkowski


People also ask

What is an avplayer and how to use it?

You can use an AVPlayer to play local and remote file-based media, such as QuickTime movies and MP3 audio files, as well as audiovisual media served using HTTP Live Streaming. Line 1 — AVAsset object is created using the video URL.

How to show playback status on screen in avplayer?

For example, we could use a loader to show the playback status on screen. AVPlayer’s timeControlStatus can be used to track the video playback status. timeControlStatus — A status that indicates whether playback is currently in progress, paused indefinitely, or suspended while waiting for appropriate network conditions.

What is avasset and avplayer?

AVPlayer — An AVPlayer is a controller object used to manage the playback and timing of a media asset. You can use an AVPlayer to play local and remote file-based media, such as QuickTime movies and MP3 audio files, as well as audiovisual media served using HTTP Live Streaming. Line 1 — AVAsset object is created using the video URL.

What is avplayerviewcontroller in iOS?

Besides AVPlayer, apple has also provided the support for a full screen controller for media playback. AVPlayerViewController — An object that displays the video content from a player object along with system-supplied playback controls. It is provided by AVKit framework. Line 1 — create an AVPlayerViewController instance.


2 Answers

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.

like image 159
Josh O'Connor Avatar answered Sep 22 '22 17:09

Josh O'Connor


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.

like image 20
Duck Avatar answered Sep 21 '22 17:09

Duck