Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Setting User Agent for AVPlayer

Tags:

ios

swift

could you please help with setting User Agent for AVPlayer?

I have a following code:

    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()

It doesn't work. How I can set User Agent in a right way in Swift?

like image 596
Anton Avatar asked Sep 23 '16 23:09

Anton


1 Answers

it is really very simple in Swift 2.3

let headerFields: [String:String] = ["User-Agent":"myua"]
let asset: AVURLAsset = AVURLAsset(URL:url!, options: ["AVURLAssetHTTPHeaderFieldsKey": headerFields])
like image 89
Anton Avatar answered Oct 02 '22 12:10

Anton