on xCode 4.6.1 it worked fine.
But I had this problem with xCode 5!
But this solution is very useful:
"The solution is that the player must have an instance variable or a view controller property, that is, we must use the MPMoviePlayerController instance
@property (non-atomic, strong) MPMoviePlayerController * myMovieController; "
Thanks to the author very much!
And this is my code:
UIGraphicsBeginImageContext(CGSizeMake(1,1)); NSString *path = [[NSBundle mainBundle] pathForResource:@"video" ofType:@"mp4"]; NSURL *videoURL = [NSURL fileURLWithPath:path]; self.moviePlayerView = [[MPMoviePlayerController alloc] initWithContentURL:videoURL]; [self.moviePlayerView prepareToPlay]; [self.moviePlayerView.view setFrame:CGRectMake(0, 0, 320, self.view.frame.size.height/2)]; self.moviePlayerView.view.backgroundColor = [UIColor clearColor]; [self.moviePlayerView setContentURL:videoURL]; self.moviePlayerView.movieSourceType = MPMovieSourceTypeFile; self.moviePlayerView.controlStyle = MPMovieControlStyleDefault; [self.view addSubview:self.moviePlayerView.view]; self.moviePlayerView.shouldAutoplay = NO; [self.moviePlayerView play]; UIGraphicsEndImageContext();
Artem levkovich
source share