8

In my project I have created a ViewController and created a class as "AVPlayerViewController" in order to show videos.

The code works and I am able to see the videos however, I get some constraints warnings in the console.

My project is working without AutoLayout and I use AutoResizing. I have tried the code:

self.view.translatesAutoresizingMaskIntoConstraints = false

but the warnings are not going away and the controls of the video player move to the top of the screen .

There warnings are:

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. (Note: If you're seeing NSAutoresizingMaskLayoutConstraints that you don't understand, refer to the documentation for the UIView property translatesAutoresizingMaskIntoConstraints) 
(
    "<NSAutoresizingMaskLayoutConstraint:0x1475c4540 h=-&- v=-&- _UIBackdropContentView:0x147443880.width == _UIBackdropView:0x147436a30.width>",
    "<NSLayoutConstraint:0x1475b38f0 H:|-(0)-[_UIBackdropView:0x147436a30]   (Names: '|':UIView:0x1474368d0 )>",
    "<NSLayoutConstraint:0x1475b3980 H:[_UIBackdropView:0x147436a30]-(0)-|   (Names: '|':UIView:0x1474368d0 )>",
    "<NSLayoutConstraint:0x1475b3650 H:|-(0)-[UIView:0x1474368d0]   (Names: '|':AVAlphaUpdatingView:0x14744db30 )>",
    "<NSLayoutConstraint:0x1475b36d0 H:[UIView:0x1474368d0]-(0)-|   (Names: '|':AVAlphaUpdatingView:0x14744db30 )>",
    "<NSLayoutConstraint:0x1475c7670 H:|-(15)-[UIView:0x1474435c0](LTR)   (Names: '|':_UIBackdropContentView:0x147443880 )>",
    "<NSLayoutConstraint:0x1475c54d0 UIView:0x147443b40.right == _UIBackdropContentView:0x147443880.right>",
    "<NSLayoutConstraint:0x1475c7a40 UIView:0x1474435c0.right == UIView:0x147443b40.left - 10>",
    "<NSLayoutConstraint:0x1475c4da0 'UIView-Encapsulated-Layout-Width' H:[AVAlphaUpdatingView:0x14744db30(0)]>"
)

Will attempt to recover by breaking constraint 
<NSLayoutConstraint:0x1475b3980 H:[_UIBackdropView:0x147436a30]-(0)-|   (Names: '|':UIView:0x1474368d0 )>

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

Any Idea what to do?

rmaddy
  • 314,917
  • 42
  • 532
  • 579
SNos
  • 3,430
  • 5
  • 42
  • 92

3 Answers3

5

As per this answer Unable to simultaneously satisfy constraints Warnings with AVPlayerViewController embedded in storyboard the solution seems to be to set showsPlayBackControls off on the PlayerController and then add it to the view.

Once you have an AVPlayer item, you can show the player controls again (assuming you need them).

I suspect that a valid AVPlayer item is needed in order for the player control constraints to be properly satisfied.

I had this exact same issue and managed to fix it by making this change. Good luck!

Community
  • 1
  • 1
Tim Bull
  • 2,375
  • 21
  • 25
0

Strangely enough, what you do is create a second view under your main view, and then add your player view as a subview to that.

This very problem took me an entire day to solve a month ago, and that's how it got solved. You must remove any code that auto resizes constraints, though.

James Bush
  • 1,485
  • 14
  • 19
  • @Jamesh I have tried with same adding a suvView and add playerView inside it but the error seems to be same. I am using xcode 8.2 and ios 10 any help will be appreciated. – The iCoder Jun 23 '17 at 06:06
  • You have to prove that’s what you’re doing by posting sample code. – James Bush Jun 23 '17 at 15:03
0

If you are programmatically creating the view for your view controller, add the AVPlayerViewController as a child view controller and its view as a subview in loadView() method instead of viewDidLoad(). No need to hide playback controls.

PastryPup
  • 166
  • 1
  • 8