Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Create property for MPMoviePlayerController, because you retain view after adding it as subview, but not retain controller.</p> <pre><code>@property (strong, nonatomic) MPMoviePlayerController *player; ... @synthesize player = _player; ... - (IBAction)playVideo:(id)sender { NSURL *videoUrl = [[DataStore singletonInstance] getVideoUrl:self withUuid:self.eventDetailVC.event.uuid]; if ([videoUrl checkResourceIsReachableAndReturnError:nil] == NO) { NSLog(@"Video doesn't not exist."); return; } self.player = [[MPMoviePlayerController alloc] initWithContentURL:videoUrl]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(moviePlayBackDidFinish:) name:MPMoviePlayerPlaybackDidFinishNotification object:nil]; [previewView addSubview:_player.view]; _player.view.frame = previewView.bounds; _player.controlStyle = MPMovieControlStyleDefault; [_player play]; } - (void)moviePlayBackDidFinish:(NSNotification*)notification { NSLog(@"moviePlayBackDidFinish: called"); [[NSNotificationCenter defaultCenter] removeObserver:self name:MPMoviePlayerPlaybackDidFinishNotification object:nil]; // Checking for errors NSDictionary *notiUserInfo = [notification userInfo]; if (notiUserInfo != nil) { NSError *errorInfo = [notiUserInfo objectForKey:@"error"]; if ([[errorInfo domain] isEqualToString:@"MediaPlayerErrorDomain"]) { UIAlertView *notice = [[UIAlertView alloc] initWithTitle:@"Error" message:[errorInfo localizedDescription] delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil]; [notice show]; return; } } // Remove from view [_player.view removeFromSuperview]; [_player stop]; self.player = nil; } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload