AVPlayer queries redirecting URL twice

Hello,

consider this very simple example:

        guard
            let url = URL(string: "some_url")
        else {
            return
        }

        let player = AVPlayer(url: url)

        let controller = AVPlayerViewController()
        controller.player = player

        present(controller, animated: true) {
            player.play()
        }

When the video URL is using redirection and returns 302 when queried, AVPlayer's internal implementation is querying twice, which is proven by proxying.

I'm not sure if I can provide the actual links, thus the screenshot is blurred. It can be seen though, that the redirecting URL, which receives 302 as a response, it is queried twice, and only after the 2nd attempt the actual redirection is taking place.

This behavior is problematic to the backend services and we need to remediate it somehow.

Do you have any idea on how to address this problem, please?

Post not yet marked as solved Up vote post of kgrobelny Down vote post of kgrobelny
593 views

Replies

Consider using HTTP 301 instead of HTTP 302 if applicable. AVPlayer might handle permanent redirects differently and perform only one request in such cases.