About standards

I had seen some video about videos with Chris in youtube and tried the same on my Xcode, but something was wrong. Below is a code and photo(the second error message:Cannot call value of non-function type ‘UIViewController?’);

import UIKit
import AVFoundation
import AVKit

class ViewController: UIViewController {

let avPlayerViewController = AVPlayerViewController()
var avPlayer:AVPlayer?

override func viewDidLoad() {
    let movieUrl:NSURL? = NSURL(string: "http://techslides.com/demos/sample-videos/small.mp4")
    if let url = movieUrl {
        self.avPlayer = AVPlayer(URL: url)
        self.avPlayerViewController.player = self.avPlayer

override func didReceiveMemoryWarning() {

@IBAction func playButtonTaped(sender: UIButton) {
    self.presentingViewController(self.avPlayerViewController, animated: true) { () -> Void in self.avPlayerViewController.player?.play()}


You should use URL not NSURL

Where should I use URL instead of NSURL?

Hi Aidarbek,

If you are interested I have created a project to show the two methods of showing videos using AVPlayer OR AVPlayerViewController.

The code is based on this stackView thread:

One of the keys to getting this to work was adding an Info.plist entry
App Transport Security Settings to Allow Arbitrary Loads
Have a look at the Info.plist file to see what I mean.

There are two buttons on the Initial view when you run the App on your simulator.

  • The first makes use of the AVPlayerViewController which is presented modally (slides up from the bottom) .
  • The second button presents a separate ViewController and the code adds a sublayer in which to play the video.

If you tap the screen the presented view, the navigation bar will move out of view. Tap again and the navigation bar moves back into view.
Tap the “< Back” button to go back to the previous view.

Change the Simulator to Landscape for a better view of the video. Command + leftArrow (Command + rightArrow to change it back to Portrait).