0

What I am trying to do here is connect to an IP Camera and display the stream/feed using the AVPlayView.

If I play a local video everything is working fine:

 let path = NSBundle.mainBundle().pathForResource("video-bg", ofType: "mp4")
 let url = NSURL.fileURLWithPath(path!)
 playerItem = AVPlayerItem(URL: url)
 player = AVPlayer(playerItem: playerItem!)
//Display Stream on AVPlayerView 
self.avPlayerView.player = player

But when I am trying to connect to a camera using the following code it does not work:

let url = NSURL.fileURLWithPath("http://96.10.1.168/")
playerItem = AVPlayerItem(URL: url)
player = AVPlayer(playerItem: playerItem!)
//Display the stream       
self.avPlayerView.player = player
  • This is a public IP Camera found from Google and it works on my browser.
  • info.plist is edited to allow connection:

    <key>NSAllowsArbitraryLoads</key>
    <true/>
    <key>NSExceptionDomains</key>
    <dict>
        <key>http://96.10.1.168/</key>
        <dict>
            <key>NSIncludesSubdomains</key>
            <true/>
            <key>NSTemporaryExceptionAllowsInsecureHTTPLoads</key>
            <true/>
            <key>NSTemporaryExceptionMinimumTLSVersion</key>
            <string>TLSv1.1</string>
        </dict>
    </dict>
    

It seems that I am approaching this wrong, so can somebody point me to the right direction and tell what is the correct approach?

cmario
  • 605
  • 1
  • 7
  • 22

1 Answers1

0

The page at http://96.10.1.168/ returns HTML, it doesn't return a video stream.

There's JavaScript in the page's HTML, and this JavaScript is what loads the video in your browser.

You can not use http://96.10.1.168/ directly with AVPlayer.

Eric Aya
  • 69,473
  • 35
  • 181
  • 253
  • 1
    So what do I do when I want to access the IP camera which I know it's ip address and I want to play it using AVPlayerView? thank you for you answer. – cmario May 27 '16 at 11:40
  • You can use AVPlayer only if you know the video stream's URL. Here, you don't know it, because the Web Camera doesn't generate a video stream at all, it's all done in JavaScript in the page: you just can't use AVPlayer. – Eric Aya May 27 '16 at 11:42