2014-09-28 147 views
8

我正在将应用程序移植到iOS 8.我有一些代码可以播放之前正在工作的视频,但现在它没有。MPMoviePlayerController布局约束问题

当我运行它,我得到以下错误:

(
"<NSLayoutConstraint:0x7faba2df5940 H:|-(34)-[MPKnockoutButton:0x7faba2e6d750](LTR) (Names: '|':_UIBackdropContentView:0x7faba2dc38c0)>", 

"<NSLayoutConstraint:0x7faba2d51780 H:[MPKnockoutButton:0x7faba2e6d750]-(34)-[MPDetailSlider:0x7faba2dc6440](LTR)>", 

"<NSLayoutConstraint:0x7faba2d5b7f0 H:[MPDetailSlider:0x7faba2dc6440]-(34)-[UIView:0x7faba2dc4060](LTR)>", 

"<NSLayoutConstraint:0x7faba2dc5da0 UIView:0x7faba2dc4060.right == _UIBackdropView:0x7faba2dbfdc0.right>", 

"<NSLayoutConstraint:0x7faba2dc58d0 H:|-(0)-[_UIBackdropView:0x7faba2dbfdc0] (Names: '|':MPVideoPlaybackOverlayView:0x7faba2dbf6a0)>", 

"<NSLayoutConstraint:0x7faba2dc5950 H:[_UIBackdropView:0x7faba2dbfdc0]-(0)-| (Names: '|':MPVideoPlaybackOverlayView:0x7faba2dbf6a0)>", 

"<NSLayoutConstraint:0x7faba2df9b10 H:[MPVideoPlaybackOverlayView:0x7faba2dbf6a0(0)]>", 

"<NSAutoresizingMaskLayoutConstraint:0x7faba2dfbfa0 h=-&- v=-&- _UIBackdropContentView:0x7faba2dc38c0.midX == _UIBackdropView:0x7faba2dbfdc0.midX>", 

"<NSAutoresizingMaskLayoutConstraint:0x7faba2dfbff0 h=-&- v=-&- _UIBackdropContentView:0x7faba2dc38c0.width == _UIBackdropView:0x7faba2dbfdc0.width>" 
) 

下面的代码:

movieController = [[MPMoviePlayerController alloc] 
       initWithContentURL:[NSURL URLWithString:playlistUrl]]; 

movieController.movieSourceType = MPMovieSourceTypeStreaming; 
[movieController.view setFrame:[self.playerView bounds]]; 

[self.playerView addSubview:movieController.view]; 
[movieController play]; 

有什么想法?

回答

7

这似乎是固定在iOS 8.1中。升级后错误消失。

不过,我也得稍微修改我的代码:

movieController = [[MPMoviePlayerController alloc] 
        initWithContentURL:[NSURL URLWithString:playlistUrl]]; 

movieController.movieSourceType = MPMovieSourceTypeStreaming; 

[movieController.view setTranslatesAutoresizingMaskIntoConstraints:NO]; 
[playerView addSubview:movieController.view]; 

id views = @{ @"player": movieController.view }; 

[playerView addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:|[player]|" 
                     options:0 
                     metrics:nil 
                     views:views]]; 

[playerView addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:|[player]|" 
                     options:0 
                     metrics:nil 
                     views:views]]; 
[movieController play]; 
+0

谢谢,西蒙,这节省了我很多时间! – 2015-02-14 21:27:41

1

我刚刚遇到过这个问题。

我注意到即使没有屏幕上的MKMoviePlayerController视图,以及之前我曾经访问它,约束警告也会出现。

这导致我删除了我的缩略图生成API requestThumbnailImagesAtTimes:timeOption:cancelAllThumbnailImageRequests的调用。

使用另一种检索缩略图的方法后,警告立即停止。

虽然我正在加载本地url,但不是流媒体 - 但我想象的是流式机制试图在某处加载缩略图并导致我们看到的问题。

我没有注意到任何记录的解决方案或对这个问题的答案,所以我希望我的轶事证据有帮助。

1

懒人

当我想用movieController.view.frame直接我只是叫

[movieController.view setTranslatesAutoresizingMaskIntoConstraints:YES]; 

[movieController prepareToPlay]; 
[self.view addSubview:movieController.view]; 

不带约束的混乱。