Swift 3:
import UIKit
import AVKit
import AVFoundation
class ViewController: UIViewController {
@IBOutlet weak var viewPlay: UIView!
var player : AVPlayer?
override func viewDidLoad() {
super.viewDidLoad()
let url : URL = URL(string: "http://static.videokart.ir/clip/100/480.mp4")!
player = AVPlayer(url: url)
let playerLayer = AVPlayerLayer(player: player)
playerLayer.frame = self.viewPlay.bounds
self.viewPlay.layer.addSublayer(playerLayer)
}
@IBAction func play(_ sender: Any) {
player?.play()
}
@IBAction func stop(_ sender: Any) {
player?.pause()
}
}