【问题标题】:AVPlayer with AWS Cookie using AirPlayAVPlayer 与 AWS Cookie 使用 AirPlay
【发布时间】:2019-12-20 12:00:32
【问题描述】:

我尝试播放 CloudFront 提供的 HLS 流。

它在应用程序中运行良好。我只是在 AVURLAsset 中设置了 cookie,然后就顺利了。

当我在 AirPlay 提供的列表中选择一个设备(Apple TV)时,就会出现问题。流没有开始。

我得到了错误:

Error Domain=AVFoundationErrorDomain Code=-11800 "The operation could not be completed" UserInfo={NSLocalizedFailureReason=An unknown error occurred (-12926), NSLocalizedDescription=The operation could not be completed, NSUnderlyingError=0x28312ed90 {Error Domain=NSOSStatusErrorDomain Code=-12926 "(null)"}}

我正在使用此代码来设置 cookie:

let url = URL(string: "https://YOUR_VIDEO_URL.m3u8");
var cookies = [HTTPCookie]()
    if let cookie = json["cookie"] as? [String: String] {
    for key in cookie.keys {
        let cookieField = ["Set-Cookie": "\(key)=\(cookie[key] ?? "")"]
        let cookie = HTTPCookie.cookies(withResponseHeaderFields: cookieField, for: url)
        cookies.append(contentsOf: cookie)
    }
}

// Assign cookies to AVPlayer
let values = HTTPCookie.requestHeaderFields(with: cookies)
let cookieOptions = ["AVURLAssetHTTPHeaderFieldsKey": values]
let assets = AVURLAsset(url: url, options: cookieOptions)
let item = AVPlayerItem(asset: assets)
let player = AVPlayer(playerItem: item)

【问题讨论】:

  • 您找到解决方案了吗?
  • 是的,您必须使用 AVAssetResourceLoaderDelegate 然后使用 AVAssetResourceLoadingRequest 发出请求才能对块进行身份验证。
  • 当时你能在 Apple TV 上播放吗? AVAssetResourceLoading 对我不起作用。你有示例吗?

标签: swift avplayer amazon-cloudfront http-live-streaming airplay


【解决方案1】:

您必须使用 AVAssetResourceLoaderDelegate 然后发出请求 使用 AVAssetResourceLoadingRequest 能够验证 块。

from OP's own comment

【讨论】:

    【解决方案2】:

    当 AirPlay 设备没有连接到互联网时,也会出现同样的问题。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多