ivany4
ivany4

Reputation: 21

MPMoviePlayerController not playing video on iOS7

I have a basic MPMoviePlayerController code that plays videos. It works flawlessly on iOS8, however it freezes the app on iOS7.

Here's the code:

 - (void)playURL:(NSURL *)URL fromView:(UIView *)view
 {
     NSParameterAssert(URL);
     NSParameterAssert(view);
     NSParameterAssert(view.superview);

     self.moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:URL];
     [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(moviePlayBackDidFinish:) name:MPMoviePlayerPlaybackDidFinishNotification object:self.moviePlayer];
     [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(movieControllerDidCollapse:) name:MPMoviePlayerDidExitFullscreenNotification object:self.moviePlayer];
     self.moviePlayer.shouldAutoplay = YES;

     self.moviePlayer.view.frame = view.frame;
     [view.superview addSubview:self.moviePlayer.view];
     [self.moviePlayer setFullscreen:YES animated:YES];
 }

 - (void)moviePlayBackDidFinish:(NSNotification *)notification
 {
     [self.moviePlayer setFullscreen:NO animated:YES];
 }

 - (void)movieControllerDidCollapse:(NSNotification *)note
 {
     [[NSNotificationCenter defaultCenter] removeObserver:self name:MPMoviePlayerPlaybackDidFinishNotification object:self.moviePlayer];
     [[NSNotificationCenter defaultCenter] removeObserver:self name:MPMoviePlayerDidExitFullscreenNotification object:self.moviePlayer];

     [self.moviePlayer.view removeFromSuperview];
     self.moviePlayer = nil;
 }

I have the same code running in my other apps, and it works well, but in this particular app it gets iOS7 frozen. When launched, it starts spitting numerous CGContext errors in a loop, saying that the context is 0x0. I tried to create a dummy CGContext and got rid of errors, but in this case it spins up the CPU to 100%, presumably because it is trying to draw things in the context that has a wrong scope or smth.

I also tried to use MPMoviePlayerViewController instead of MPMoviePlayerController, but it does the same thing. Modal presentation animation does not even appear.

I also searched my project for some UIAppearance setters and method swizzlings, but found nothing that could potentially cause this behavior.

I ran Time Profiler on this app, and the problem has something to do with drawing Progress Sliders. I have no progress view subclasses or categories in my project. The Instruments profiling looks like this: Instruments output. (Sorry, can't include direct image due to reputation lack).

I also tried running a clean project with the whole set of my cocoapods and it works perfectly in a different project.

Upvotes: 1

Views: 161

Answers (1)

ivany4
ivany4

Reputation: 21

OK, there problem was with one of my categories. I defined a method [UIImage imageNamed:inBundle:] which apparently conflicted with one of the private APIs. But I got no warnings what so ever. Renaming the method solved the problem.

Upvotes: 1

Related Questions