Swift version:
import AVFoundation
func playVideo(url: URL) {
let player = AVPlayer(url: url)
let layer: AVPlayerLayer = AVPlayerLayer(player: player)
layer.backgroundColor = UIColor.white.cgColor
layer.frame = CGRect(x: 0, y: 0, width: 300, height: 300)
layer.videoGravity = .resizeAspectFill
self.view.layer.addSublayer(layer)
player.play()
}