//From view did load...
[self playIntroductionVideo]; //Start playing video after view appears completely.
- (void)playIntroductionVideo {
NSString * nameOfVideoFile = @"myVideo.mp4";
moviePlayer = [[MPMoviePlayerController alloc] init];
moviePlayer = [NTZipExtractViewController setVideoFromPath:nameOfVideoFile]; //Returns video file from local
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(moviePlayBackDidFinish:) name:MPMoviePlayerPlaybackDidFinishNotification object:moviePlayer];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(movieNaturalSizeAvailableHack:)
name:MPMovieNaturalSizeAvailableNotification
object:moviePlayer];
moviePlayer.controlStyle = MPMovieControlStyleDefault;
[self.view addSubview:moviePlayer.view];
moviePlayer.fullscreen = NO;
moviePlayer.scalingMode = MPMovieScalingModeFill;
// float naturalHeight = moviePlayer.naturalSize.height; //---> Returns 0 !. But I here can See all the controllers of player. After setting frame. //---> [moviePlayer view].frame = CGRectMake(0, 0, self.view.frame.size.width , naturalHeight); where natural height is missing.!
}
-(void) movieNaturalSizeAvailableHack:(NSNotification *)notification{
float naturalHeight = moviePlayer.naturalSize.height; //----------> Here I can get the natural size. But the control style - Seek video is not appearing.
if(naturalHeight > self.view.frame.size.height) {
naturalHeight = self.view.frame.size.height;
}
[moviePlayer view].frame = CGRectMake(0, 0, self.view.frame.size.width , naturalHeight);
moviePlayer.view.center = self.view.center;
MPMoviePlayerController *player = [notification object];
[[NSNotificationCenter defaultCenter] removeObserver:self name:MPMovieNaturalSizeAvailableNotification object:player];
}
- (void)moviePlayBackDidFinish:(NSNotification*)notification {
MPMoviePlayerController *player = [notification object];
[[NSNotificationCenter defaultCenter] removeObserver:self name:MPMoviePlayerPlaybackDidFinishNotification object:player];
[moviePlayer.view removeFromSuperview];
}