imjonu
imjonu

Reputation: 515

Play video not in fullscreen, swift 3

I am facing a problem with embedding a video into my app. I am trying to play the video inside a box rather than in full screen mode. Because I need a Label at the top of the screen, The video should be in the middle and an another button at the bottom of the screen. The following link is the quick sketch of that I am trying to achieve. Image Please note that, I want to play the video in that box, not in the fullscreen. The code I have used is shown below, however this code makes the video to go into full screen. Any help on the topic will be very much appreciated, thank you.

override func viewDidAppear(_ animated: Bool) {

let fileURL = NSURL(fileURLWithPath: "videoOne")
playerView = AVPlayer(url: fileURL as URL)

   playerViewController.player = playerView
   self.present(playerViewController, animated: true){
   self.playerViewController.player?.play()
 }
}

Upvotes: 0

Views: 2292

Answers (1)

Danh Huynh
Danh Huynh

Reputation: 2327

I'm assuming your video box is called boxView and you should add playerViewController.view into boxView like this:

playerViewController.view.frame = boxView.bounds
boxView.addSubview(playerViewController.view)

Upvotes: 1

Related Questions