MPMoviePlayerController布局约束问题

时间:2014-09-28 17:13:48

标签: ios8 autolayout

我正在将应用程序移植到iOS 8.我有一些代码可以播放之前正在运行的视频,但现在却没有。

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

(
"<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];

有什么想法吗?

3 个答案:

答案 0 :(得分: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];

答案 1 :(得分:1)

我自己刚刚遇到过这个问题。

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

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

使用替代方法检索缩略图后,警告立即停止。

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

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

答案 2 :(得分:1)

For lazy people.

When I want to use movieController.view.frame directly I just call

[movieController.view setTranslatesAutoresizingMaskIntoConstraints:YES];

before

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

to not mess with constraints.