I have a webcam that I'm trying to connect to and display the video feed from.
I have an URL that works in Chrome:
http://admin:YWRtaW4=@192.168.1.127:8080/stream/video/mjpeg?resolution=vgaWhen I attempt to use this URL with AVPlayer the authentication fails. Here's my code:
let url = NSURL(string: "http://admin:YWRtaW4=@192.168.1.127:8080/stream/video/mjpeg?resolution=vga")
let asset = AVURLAsset(URL: url)
let item = AVPlayerItem(asset: asset)
player = AVPlayer(playerItem: item)
self.playerLayer.player = player
playerLayer.backgroundColor = NSColor.redColor().CGColor
player?.play()When playing with AVPlayer, the authentication fails. I can see this in WireShark:
HTTP/1.0 401 Unauthorized
Server: Streamd,60E327FEA06D
Date: Tue, 03 May 2016 11:37:40 UTC
Pragma: no-cache
Cache-Control: no-cache
Content-Length: 0
WWW-Authenticate: Digest realm="TP-Link IP-Camera",algorithm="MD5",qop="auth",nonce="e679022845da2fabdd6af37624ed18300003d8ff02ac8883",opaque="64943214654649846565646421"
Connection: keep-alive
GET /stream/video/mjpeg?resolution=vga HTTP/1.1
Host: 192.168.1.127:8080
Authorization: Digest username="admin", realm="TP-Link IP-Camera", nonce="e679022845da2fabdd6af37624ed18300003d8ff02ac8883", uri="/stream/video/mjpeg?resolution=vga", response="230eb8f8ba76ce5c689691f8d83f448f", opaque="64943214654649846565646421", algorithm="MD5", cnonce="adcd7d470e56e1d3958456661f7ddd9b", nc=00000002, qop="auth"
X-Playback-Session-Id: 30B37EAB-D7E7-42CF-A7D9-DC61CAAA2083
Range: bytes=0-1
Accept: */
User-Agent: AppleCoreMedia/1.0.0.15E65 (Macintosh; U; Intel Mac OS X 10_11_4; en_us)
Accept-Language: en-us
Accept-Encoding: identity
Connection: keep-aliveThe server sends a digest challenge, AVPlayer responds, but the response isn't accepted. The same sort of exchange happens when connecting from Chrome, but the authentication succeeds.This sequence repeats a number of times as AVPlayer keeps trying to connect.
Not sure where to go from here. Is there any way to take over this part of the authentication process when using AVURLAsset?