Monday, June 04, 2012

Play a video in full screen

1. Include MediaPlayer framework in the project
2. Import header file in the view controller
3. Declare the player instance in the controller header file:
MPMoviePlayerViewController *playerViewController;

Sample Code : 
----------------
- (void) playVideo:(NSString *)fileName
{
    NSString *url = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:fileName];
    playerViewController = [[MPMoviePlayerViewController alloc] initWithContentURL:[NSURL fileURLWithPath:url]];
    [[NSNotificationCenter defaultCenter] addObserver:self
                                             selector:@selector(movieFinishedCallback:)
                                                 name:MPMoviePlayerPlaybackDidFinishNotification
                                               object:[playerViewController moviePlayer]];
    [self.view addSubview:playerViewController.view];
   
    //play movie
    MPMoviePlayerController *player = [playerViewController moviePlayer];
    [player play];        
}

// The call back
- (void) movieFinishedCallback:(NSNotification*) aNotification
{
    MPMoviePlayerController *player = [aNotification object];
    [[NSNotificationCenter defaultCenter] removeObserver:self
                                                    name:MPMoviePlayerPlaybackDidFinishNotification
                                                  object:player];
    player.initialPlaybackTime = -1;
    [player stop];
    [player.view removeFromSuperview];   
    [player release];   
}

No comments:

Swift Operators - Basic Part 3 (Range operators in swift)

Range Operators: Closed Range operators  Half-Open Range Operators One-Sided Ranges Closed Range Operators:  a...b It defines...