gpt4 book ai didi

swift - 带有 AWS Cookie 的 AVPlayer 使用 AirPlay

转载 作者:行者123 更新时间:2023-12-04 11:36:38 27 4
gpt4 key购买 nike

我尝试播放 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)

最佳答案

You have to use AVAssetResourceLoaderDelegate and then make a requestusing AVAssetResourceLoadingRequest to be able to authenticate thechunk.


from OP's own comment

关于swift - 带有 AWS Cookie 的 AVPlayer 使用 AirPlay,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57486044/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com