iOS:收到"304 Not Modified"响应时,AVPlayerItem中存在错误 [英] iOS: bug in AVPlayerItem when receiving `304 Not Modified` response

查看:156
本文介绍了iOS:收到"304 Not Modified"响应时,AVPlayerItem中存在错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是一个非常奇怪的错误.

This is a very weird bug.

我有一个tableView,每个单元格都使用AVPlayer从远程服务器流式传输视频(想像Vine一样的时间轴).因此,当我滚动时,重复使用的单元将使用新视频重新配置其播放器.

I have a tableView with each cell using an AVPlayer to stream a video from a remote server (think a Vine-like timeline). So when I scroll, the cells that get reused reconfigure their player with the new video.

问题是:如果我快速前后滚动,使同一视频进出屏幕,则AVPlayer发送的请求最终将更改,以包括HTTP标头If-None-MatchIf-Modified-Since,剩下的时间都不在那里.它系统地使服务器返回304 Not Modified响应.

The problem is: if I scroll back and forth very fast, getting the same video in and out of the screen, the request sent by the AVPlayer eventually changes, to include the HTTP Headers If-None-Match and If-Modified-Since, which are not there the rest of the time. It systematically makes the server return a 304 Not Modified response.

这似乎不满意AVPlayer的playerItem,它将其状态更改为AVPlayerItemStatusFailed(有趣的是,AVPlayer的状态仍为AVPlayerStatusReadyToPlay).错误是带有OSStatus -12983的AVErrorUnknown(-11800)(没有记录在任何地方,并且在整个iOS SDK中都没有标头).

That doesn't seem to please the AVPlayer's playerItem, which changes its status to AVPlayerItemStatusFailed (interestingly, the AVPlayer's status is still AVPlayerStatusReadyToPlay). The error is AVErrorUnknown (-11800) with an OSStatus -12983 (which isn't documented anywhere and is in no header in the entire iOS SDK).

那是当它变得怪异的时候:接下来我做什么,AVPlayer及其playerItem都将被不可挽回地烧毁.即使我用其他资产重新配置它们,它们也只会返回此状态并显示黑框.仍然很奇怪:即使我初始化了另一个AVPlayer,AVPlayerItem AVAsset,它也将不再播放,我必须终止并重新启动该应用程序.

That's when it gets weird: whatever I do next, the AVPlayer and its playerItem are irrevocably burnt. Even if I reconfigure them with another asset, they'll just return this status and show a black frame. Weirder still: even if I initialize another AVPlayer, AVPlayerItem and AVAsset, it just won't play anymore, I have to kill and restart the app.

在这一点上,我还是一无所知.知道这里发生了什么吗?阻止播放器在其连接中包含这些标头会对其进行修复,但它不会公开其请求序列化器.

At this point, I'm pretty clueless. Any idea what's happening here? Preventing the player from including these headers in its connection would fix it, but it's not exposing its request serializer.

推荐答案

我遇到了同样的问题.所以我添加了If-None-Match: ${unique value}标头以防止返回304.它对我有用.

I met the same issue. so I add If-None-Match: ${unique value} header to prevent return 304. it work to me.

    var player = AVQueuePlayer()
    func play(url: String) {
        let headers = ["If-None-Match": "1"]
        let options = ["AVURLAssetHTTPHeaderFieldsKey": headers]
        let asset = AVURLAsset(url: URL(string: url)!, options: options)
        let playItem = AVPlayerItem(asset: asset)
        player.replaceCurrentItem(with: playItem)
        player.automaticallyWaitsToMinimizeStalling = false
        player.playImmediately(atRate: 1)
    }

这篇关于iOS:收到"304 Not Modified"响应时,AVPlayerItem中存在错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆