[使用AirPlay的带有AWS Cookie的AVPlayer

问题描述 投票:3回答:1

我正在尝试播放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)
swift avplayer amazon-cloudfront http-live-streaming airplay
1个回答
0
投票
© www.soinside.com 2019 - 2024. All rights reserved.