你可以帮忙设置AVPlayer的用户代理吗?
我有以下代码:
let url = NSURL(string:"http://devimages.apple.com/iphone/samples/bipbop/bipbopall.m3u8")
var headers: [String:String] = ["User-Agent": "myagent"]
let asset: AVURLAsset = AVURLAsset.URLAssetWithURL(url!, options: ["AVURLAssetHTTPHeaderFieldsKey": headers])
let playerItem = AVPlayerItem(asset)
player.replaceCurrentItemWithPlayerItem(playerItem)
player.play()
它不起作用。如何在Swift中以正确的方式设置用户代理?
答案 0 :(得分:2)
在Swift 2.3中非常简单
let headerFields: [String:String] = ["User-Agent":"myua"]
let asset: AVURLAsset = AVURLAsset(URL:url!, options: ["AVURLAssetHTTPHeaderFieldsKey": headerFields])