Posted By

magickaito on 06/02/11


Tagged


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

Tintenklecks


Play a video full screen in objective c


 / Published in: Objective C
 

  1. include MediaPlayer framework in the project
  2. in the view controller header file,
import <MediaPlayer/MediaPlayer.h>
  1. declare the player instance in the controller header file: MPMoviePlayerViewController *playerViewController;
  1. - (void) playVideo:(NSString *)fileName
  2. {
  3. NSString *url = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:fileName];
  4.  
  5. playerViewController = [[MPMoviePlayerViewController alloc] initWithContentURL:[NSURL fileURLWithPath:url]];
  6.  
  7. [[NSNotificationCenter defaultCenter]
  8. addObserver:self
  9. selector:@selector(movieFinishedCallback:)
  10. name:MPMoviePlayerPlaybackDidFinishNotification
  11. object:[playerViewController moviePlayer]];
  12.  
  13. [self.view addSubview:playerViewController.view];
  14.  
  15. //play movie
  16.  
  17. MPMoviePlayerController *player = [playerViewController moviePlayer];
  18. [player play];
  19. }
  20.  
  21. // The call back
  22. - (void) movieFinishedCallback:(NSNotification*) aNotification {
  23. MPMoviePlayerController *player = [aNotification object];
  24. [[NSNotificationCenter defaultCenter]
  25. removeObserver:self
  26. name:MPMoviePlayerPlaybackDidFinishNotification
  27. object:player];
  28.  
  29. //player.initialPlaybackTime = -1;
  30. //[player pause];
  31. [player stop];
  32.  
  33. [player.view removeFromSuperview];
  34.  
  35. [player release];
  36. // call autorelease the analyzer says call too many times
  37. // call release the analyzer says incorrect decrement
  38. }

Report this snippet  

You need to login to post a comment.