Okay, my code plays a movie fullscreen with no controls for the user, (basically a cinematic). After the movie is done my NSNotification fires and loads a view.
However, when the user hits the home button during one of these movies, it pauses, but there is no way to get it to play again, since I took away the controls. I tried putting [playerController play] and [playerController shouldAutoplay] in my AppDelegate.m under applicationDidBecomeActive, but it's not defined there so it doesn't know what playerController is.
Can anyone help me properly pause and play this video if a user gets a text or hits the home button?
-(IBAction)playMovie:(id)sender {
NSString *movieUrl = [[NSBundle mainBundle] pathForResource:@"Initiate" ofType:@"m4v"]; playerController = [[MPMoviePlayerController alloc] initWithContentURL:[NSURL fileURLWithPath:movieUrl]];
[playerController.view setFrame: self.view.bounds];
[self.view addSubview:playerController.view];
playerController.controlStyle = MPMovieControlStyleNone;
[playerController shouldAutoplay];
[playerController play];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(playbackFinished:)
name:MPMoviePlayerPlaybackDidFinishNotification
object:playerController];
}
- (void)playbackFinished:(NSNotification*) notification {
playerController = [notification object];
[[NSNotificationCenter defaultCenter]
removeObserver:self
name:MPMoviePlayerPlaybackDidFinishNotification
object:playerController];
ViewController *viewController = [[ViewController alloc] initWithNibName:@"ViewController" bundle:nil];
viewController.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
[self presentModalViewController:viewController animated:YES];
EDIT:
Header
//ViewController.h
@interface ViewController : UIViewController {
MPMoviePlayerController *playerController;
}
Implementation
//ViewController.m
playerController = [[MPMoviePlayerController alloc] initWithContentURL:[NSURL fileURLWithPath:movieUrl]];
AppDelegate *sharedAppDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
sharedAppDelegate.pointer = playerController;
when implementing your player, send all necessary pointers to app delegate:
AppDelegate *sharedAppDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
sharedAppDelegate.yourPointer = yourPlayer;
use this methomd from appDelegate.m:
- (void)applicationWillResignActive:(UIApplication *)application
{
/*
Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
*/
}
- (void)applicationDidBecomeActive:(UIApplication *)application
{
/*
Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
*/
}