AVPlayer with playback controls of avplayerviewcontroller

To update this post with Swift 5 you can try this code:

let videoURL = URL(string: "https://your_video_in_internet.mp4")
let player = AVPlayer(url: videoUrl)
let playerViewController: AVPlayerViewController!
playerViewController = AVPlayerViewController()
playerViewController.view.frame = YOUR_FRAME_OR_EMBED_IN_STORYBOARD
playerViewController.player = player
playerViewController.showsPlaybackControls = true
playerViewController.videoGravity = .resizeAspectFill
YOUR_FRAME_OR_EMBED_IN_STORYBOARD.addSubview(playerViewController.view)
playerViewController.player!.play()  

No. The usual solution (explicitly advised by Apple) is to use the AVPlayerViewController as an embedded view controller - i.e., make your view controller a custom parent view controller and the AVPlayerViewController its child, and now you can place its view (the movie and the controls) inside your view as a subview in good order. Example (self is your view controller):

let url = // whatever
let player = AVPlayer(URL:url)
let avPlayerViewController = AVPlayerViewController()
avPlayerViewController.player = player
avPlayerViewController.view.frame = // whatever
self.addChild(avPlayerViewController)
self.view.addSubview(avPlayerViewController.view)
avPlayerViewController.didMove(toParent: self)