1
I need to put a video inside a view, in this it has to run only inside that square not fullscreen. (like facebook)
I’ve researched about and only seen full screen tutorials. How to do this?
I got it with this code:
class BeginController: UIViewController {
 @IBOutlet weak var videoPreviewLayer: UIView!
 var player: AVPlayer!
 var avpController = AVPlayerViewController!()
 override func viewDidLoad() {
    super.viewDidLoad()
    let moviePath = NSBundle.mainBundle().pathForResource("Hello           Moto", ofType: "mp4")
    if let path = moviePath{
        let url = NSURL.fileURLWithPath(path)
        let item = AVPlayerItem(URL: url)
        self.player = AVPlayer(playerItem: item)
        self.avpController = AVPlayerViewController()
        self.avpController.player = self.player
        avpController.view.frame = videoPreviewLayer.frame
        self.addChildViewController(avpController)
        self.view.addSubview(avpController.view)
    }
    // Do any additional setup after loading the view.
}
Welcome to Sopt. What have you tried to do? Add to question.
– user28595
Thanks! I’ve tried using Avplayer Controller but everything I find on the Internet only shows how the video runs as soon as the view loads. I needed to find a way to get Avplayer into a subview and it would only run inside that view. If anyone has an idea!
– aline
Do you need the answer in Swift? Still need help?
– João Vitor