Avplayer - NSAutoresizingMaskLayoutConstraint 错误

Posted

技术标签:

【中文标题】Avplayer - NSAutoresizingMaskLayoutConstraint 错误【英文标题】:Avplayer - NSAutoresizingMaskLayoutConstraint Error 【发布时间】:2015-11-09 03:47:23 【问题描述】:

Avplayer 工作正常。但我得到了这个错误。如果我禁用显示播放控件,则可以完美地工作而不会出错。但我不能这样做,因为我需要它。我包括控制台调试日志和其他代码。

谢谢。

2015-11-09 06:35:11.019 youapp[6798:2785361] 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. (Note: If you're seeing NSAutoresizingMaskLayoutConstraints that you don't understand, refer to the documentation for the UIView property translatesAutoresizingMaskIntoConstraints) 
(
    "<NSAutoresizingMaskLayoutConstraint:0x7f8164b96f20 h=-&- v=-&- _UIBackdropContentView:0x7f81648b0510.width == _UIBackdropView:0x7f81648af200.width>",
    "<NSLayoutConstraint:0x7f8164986a20 H:|-(0)-[UIView:0x7f8164985420]   (Names: '|':UIView:0x7f816256e810 )>",
    "<NSLayoutConstraint:0x7f8164986a70 H:[UIView:0x7f8164985420]-(0)-|   (Names: '|':UIView:0x7f816256e810 )>",
    "<NSLayoutConstraint:0x7f8164985ed0 H:|-(0)-[UIView:0x7f816256e810]   (Names: '|':AVPlayerView:0x7f8164976610 )>",
    "<NSLayoutConstraint:0x7f8164985f40 H:[UIView:0x7f816256e810]-(0)-|   (Names: '|':AVPlayerView:0x7f8164976610 )>",
    "<NSLayoutConstraint:0x7f8164b66d80 H:|-(0)-[UIView:0x7f81648b01e0]   (Names: '|':_UIBackdropContentView:0x7f81648b0510 )>",
    "<NSLayoutConstraint:0x7f8164b66dd0 H:[UIView:0x7f81648b01e0]-(0)-|   (Names: '|':_UIBackdropContentView:0x7f81648b0510 )>",
    "<NSLayoutConstraint:0x7f8164b66570 H:|-(0)-[_UIBackdropView:0x7f81648af200]   (Names: '|':UIView:0x7f81648a3900 )>",
    "<NSLayoutConstraint:0x7f8164b665c0 H:[_UIBackdropView:0x7f81648af200]-(0)-|   (Names: '|':UIView:0x7f81648a3900 )>",
    "<NSLayoutConstraint:0x7f8164b662b0 H:|-(0)-[UIView:0x7f81648a3900]   (Names: '|':AVAlphaUpdatingView:0x7f81648a3790 )>",
    "<NSLayoutConstraint:0x7f8164b66300 H:[UIView:0x7f81648a3900]-(0)-|   (Names: '|':AVAlphaUpdatingView:0x7f81648a3790 )>",
    "<NSLayoutConstraint:0x7f8164b69fc0 H:|-(14)-[AVButton:0x7f81648b0dd0](LTR)   (Names: '|':UIView:0x7f81648b01e0 )>",
    "<NSLayoutConstraint:0x7f8164b976d0 H:[AVButton:0x7f81648b0dd0]-(15)-[UILabel:0x7f8164a8aad0'0:00'](LTR)>",
    "<NSLayoutConstraint:0x7f8164b97910 H:[UILabel:0x7f8164a8aad0'0:00']-(12)-[AVScrubber:0x7f8164ac0b50](LTR)>",
    "<NSLayoutConstraint:0x7f8164b97960 AVScrubber:0x7f8164ac0b50.right == UILabel:0x7f8164ade4a0'--:--'.left - 12>",
    "<NSLayoutConstraint:0x7f8164b97e20 UILabel:0x7f8164ade4a0'--:--'.right == AVButton:0x7f8164adf1a0.left - 15>",
    "<NSLayoutConstraint:0x7f8164b97ec0 AVButton:0x7f8164adf1a0.right == AVButton:0x7f8164994ad0.left - 10>",
    "<NSLayoutConstraint:0x7f8164b97a00 AVButton:0x7f8164994ad0.right == AVButton:0x7f8164969690.left - 10>",
    "<NSLayoutConstraint:0x7f8164b98150 AVButton:0x7f8164969690.right == UIView:0x7f81648b01e0.right - 14>",
    "<NSLayoutConstraint:0x7f8164af4520 H:|-(0)-[AVAlphaUpdatingView:0x7f81648a3790]   (Names: '|':UIView:0x7f8164985420 )>",
    "<NSLayoutConstraint:0x7f8164af4570 H:[AVAlphaUpdatingView:0x7f81648a3790]-(0)-|   (Names: '|':UIView:0x7f8164985420 )>",
    "<NSLayoutConstraint:0x7f8164b86f20 'UIView-Encapsulated-Layout-Width' H:[AVPlayerView:0x7f8164976610(100)]>"
)

Will attempt to recover by breaking constraint 
<NSLayoutConstraint:0x7f8164b976d0 H:[AVButton:0x7f81648b0dd0]-(15)-[UILabel:0x7f8164a8aad0'0:00'](LTR)>

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.
2015-11-09 06:37:08.097 [warn][tid:com.facebook.React.javascript] 'devtools socket closed'

#import "VideoPlayerView.h"
#import "RCTRootView.h"

@interface VideoPlayerView ()

@property (nonatomic, retain) AVPlayerViewController *avPlayerViewcontroller;
@property (nonatomic, retain) UIView *view;

@end

@implementation VideoPlayerView

  UIView *_reactView;



- (instancetype)init

  if ((self = [super init])) 
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(deviceOrientationChange:) name:@"UIDeviceOrientationDidChangeNotification" object:nil];
  
  return self;



- (void)dealloc

  [[NSNotificationCenter defaultCenter] removeObserver:self];



- (void)setUrl:(NSString *)url 
  AVPlayerViewController *playerViewController = [[AVPlayerViewController alloc] init];

  playerViewController.player = [AVPlayer playerWithURL:[NSURL URLWithString: url]];

  self.avPlayerViewcontroller = playerViewController;
  [self.avPlayerViewcontroller setShowsPlaybackControls:YES];

  self.avPlayerViewcontroller.videoGravity = AVLayerVideoGravityResizeAspect;

  [self addSubview:playerViewController.view];
  self.autoresizesSubviews = TRUE;

  [self.avPlayerViewcontroller.player play];


- (void)layoutSubviews

  [super layoutSubviews];

  self.avPlayerViewcontroller.view.frame = self.bounds;



- (void)viewDidDisappear:(BOOL)animated 
  NSLog(@"test");



- (void)deviceOrientationChange:(NSNotification *)notification


  UIDeviceOrientation orientation = [[UIDevice currentDevice] orientation];

  switch (orientation) 
    case UIDeviceOrientationPortrait:
    case UIDeviceOrientationPortraitUpsideDown:
      self.avPlayerViewcontroller.videoGravity = AVLayerVideoGravityResizeAspect;
      break;
    case UIDeviceOrientationLandscapeLeft:
    case UIDeviceOrientationLandscapeRight:

      self.avPlayerViewcontroller.videoGravity = AVLayerVideoGravityResizeAspectFill;
      break;
    default:
      self.avPlayerViewcontroller.videoGravity = AVLayerVideoGravityResizeAspect;
      break;
  



@end

【问题讨论】:

【参考方案1】:

不要在每次布局子视图时都设置视图控制器的视图;之前,当然,但之后没有意义。

【讨论】:

以上是关于Avplayer - NSAutoresizingMaskLayoutConstraint 错误的主要内容,如果未能解决你的问题,请参考以下文章

查找与 AVPlayerItem 关联的 AVPlayer

AVPlayer 问题,同时直播 (iOS)

如何为 AVPlayer 制作搜索栏

持续时间不是来自AVPlayer currentItem

使用 AVPlayer 进行 Airplay?

AVPlayer