Voici comment lancer une vidéo depuis IOS6.
Inclure le framework suivant:
MediaPlayer.framework
Dans le .h:
#import <MediaPlayer/MediaPlayer.h>
@property (strong, nonatomic) MPMoviePlayerController * moviePlayerController;
Dans le .m:
@synthesize moviePlayerController;
- (void)viewDidLoad
{
[super viewDidLoad];
//PLAY MOVIE
NSString *filepath = [[NSBundle mainBundle] pathForResource:@"video" ofType:@"mov"];
NSURL *fileURL = [NSURL fileURLWithPath:filepath];
moviePlayerController = [[MPMoviePlayerController alloc] initWithContentURL:fileURL];
moviePlayerController.shouldAutoplay =YES ;
moviePlayerController.controlStyle = MPMovieControlStyleDefault ;
moviePlayerController.scalingMode = MPMovieScalingModeFill ;
[moviePlayerController.view setFrame:CGRectMake(34, 50, 700, 394)];
[self.view addSubview:moviePlayerController.view];
// WHEN THE VIDEO FINISH
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(moviePlaybackComplete:)
name:MPMoviePlayerPlaybackDidFinishNotification
object:moviePlayerController];
[moviePlayerController play ] ;
}
Il ne reste plus que de créer la fonction qui capture la fin de la vidéo:
- (void)moviePlaybackComplete:(NSNotification *)notification
{
moviePlayerController = [notification object];
[[NSNotificationCenter defaultCenter] removeObserver:self
name:MPMoviePlayerPlaybackDidFinishNotification
object:moviePlayerController];
[moviePlayerController.view removeFromSuperview];
NSLog(@"ENDEDDD");
}
Depuis IOS 5.0 il faut faire un property du player !