3

I'm programatically adding a intro video for my app. Im getting the following warnings. any ideas what I'm doing wrong? Im very new to swift and iOS development.

2018-04-19 13:11:56.295952+0200 [1779:395252] [LayoutConstraints] Unable to simultaneously satisfy constraints. Probably at least one of the constraints in the following list is one you don't want. Try this: (1) look at each constraint and try to figure out which you don't expect; (2) find the code that added the unwanted constraint or constraints and fix it. ( "", "", " (active, names: '|':UIStackView:0x15dd29110 )>", "", " (active, names: '|':UIStackView:0x15dd29110 )>" )

Will attempt to recover by breaking constraint

Make a symbolic breakpoint at UIViewAlertForUnsatisfiableConstraints to catch this in the debugger. The methods in the UIConstraintBasedLayoutDebugging category on UIView listed in may also be helpful. 2018-04-19 13:11:56.296790+0200 [1779:395252] [LayoutConstraints] Unable to simultaneously satisfy constraints. Probably at least one of the constraints in the following list is one you don't want. Try this: (1) look at each constraint and try to figure out which you don't expect; (2) find the code that added the unwanted constraint or constraints and fix it. ( "", "", "", "UILayoutGuide:0x1d41bd180'UIViewLayoutMarginsGuide'
(active, names: '|':UIStackView:0x15dd29110 )>", " (active, names: '|':UIStackView:0x15dd29110 )>" )

Will attempt to recover by breaking constraint

Make a symbolic breakpoint at UIViewAlertForUnsatisfiableConstraints to catch this in the debugger. The methods in the UIConstraintBasedLayoutDebugging category on UIView listed in may also be helpful.

var movieController: AVPlayer?
let playerViewController = AVPlayerViewController()

override func viewDidLoad() {
    playVideo()
}

func playVideo() {
    let path = Bundle.main.path(forResource: appData.videoFile, ofType: appData.videoExtension)
    let url = URL(fileURLWithPath: path!)
    movieController = AVPlayer(url: url)
    NotificationCenter.default.addObserver(self, selector:#selector(movieFinished),name: NSNotification.Name.AVPlayerItemDidPlayToEndTime, object: movieController?.currentItem)
    playerViewController.player = self.movieController
    playerViewController.delegate = self
    playerViewController.view.frame = self.view.bounds
    playerViewController.showsPlaybackControls = false
    playerViewController.videoGravity = "AVLayerVideoGravityResizeAspectFill"
    playerViewController.view.translatesAutoresizingMaskIntoConstraints = false
    playerViewController.player?.play()
    self.view.addSubview(playerViewController.view)
}

@objc func movieFinished() {
    let value = UIInterfaceOrientation.portrait.rawValue
    UIDevice.current.setValue(value, forKey: "orientation")
    UIViewController.attemptRotationToDeviceOrientation()
    UIView.animate(withDuration: 1.5, delay: 0, options: .curveEaseIn, animations: {
        self.playerViewController.view.alpha = 0.0
    }, completion: { (finished: Bool) in
        self.playerViewController.view.removeFromSuperview()
    })
}
James Nicholson
  • 987
  • 10
  • 20
  • try adding this on `viewWillAppear` – Lu_ Apr 19 '18 at 11:41
  • @Lu_ thanks, but I still get the error even after adding override func viewWillAppear(_ animated: Bool) { super.viewWillAppear(animated) playVideo() } – James Nicholson Apr 19 '18 at 11:53
  • try also adding a view dedicated for video and not placing it `playerViewController.view` – Lu_ Apr 19 '18 at 11:55
  • Where is the stack view ? Add a symbolic break point for unsatisfiable constraints (refer to the error message). It will stop at the exact point where it is breaking. Always read the error carefully it has some hints as to what is wrong and how to identify the problem – user1046037 Apr 19 '18 at 13:12
  • @user1046037 it breaks when add the player to the subview LOL! Im pretty lost with this, will this error hinder the app in the appstore? – James Nicholson Apr 19 '18 at 13:40
  • Did you add the symbolic breakpoint ? Are you using any `UIStackView` ? – user1046037 Apr 19 '18 at 15:02
  • I end up solving this by adding a avPlayerLayer and avPlayerItem. il post the soloution – James Nicholson Apr 20 '18 at 12:23

1 Answers1

0

I end up solving this by using the AVPlayerLayer and AVPlayerItem.

var player:AVPlayer?
var playerItem:AVPlayerItem?
let playerLayer:AVPlayerLayer? = nil

override func loadView() {
    super.loadView()
    startWebiew()
}

func playVideo() {
    let path = Bundle.main.path(forResource: appData.videoFile, ofType: appData.videoExtension)
    let url = URL(fileURLWithPath: path!)
    let playerItem:AVPlayerItem = AVPlayerItem(url: url)
    player = AVPlayer(playerItem: playerItem)
    let playerLayer=AVPlayerLayer(player: player!)
    playerLayer.frame = view.bounds
    playerLayer.videoGravity = AVLayerVideoGravity.resizeAspectFill
    playerLayer.player?.play()
    view.layer.addSublayer(playerLayer)

}
James Nicholson
  • 987
  • 10
  • 20