Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MPMoviePlayerController layout constraint issues

I am porting an application to iOS 8. I had some code to play a video that was working before but now it doesn't.

When I run it, I get the following errors:

(
"<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>"
)

Here's the code:

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

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

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

Any thoughts?

like image 576
Simon Avatar asked Sep 28 '14 17:09

Simon


3 Answers

This appears to be fixed in iOS 8.1. The error disappeared after I upgraded.

However, I did have to modify my code slightly:

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];
like image 94
Simon Avatar answered Sep 24 '22 13:09

Simon


I've just come across this issue myself.

I noticed the constraint warnings would appear even without the MKMoviePlayerController view on screen and before before I ever accessed it.

This lead me to remove my calls to the thumbnail generation APIs requestThumbnailImagesAtTimes:timeOption: and cancelAllThumbnailImageRequests.

After using an alternate method of retrieving thumbnails the warnings stopped immediately.

I'm loading local urls though, not streaming - but I imagine the streaming mechanism is attempting to load a thumbnail somewhere and causing the issues we're seeing.

I haven't noticed any documented solutions or answers to this issue so I hope my anecdotal evidence helps.

like image 43
Jessedc Avatar answered Sep 23 '22 13:09

Jessedc


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.

like image 22
SoftDesigner Avatar answered Sep 22 '22 13:09

SoftDesigner