需要导入头文件#import <MediaPlayer/MediaPlayer.h>
效果图
代码示例
// 实例化
MPMoviePlayerViewController *playerController = [[MPMoviePlayerViewController alloc] initWithContentURL:url];
playerController.moviePlayer.scalingMode = MPMovieScalingModeAspectFit;
playerController.moviePlayer.controlStyle = MPMovieControlStyleFullscreen;
[self presentViewController:playerController animated:YES completion:nil];
// 通知监听
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(movieFinishedCallback:) name:MPMoviePlayerPlaybackDidFinishNotification object:playerController.moviePlayer];
// 通知
- (void) movieFinishedCallback:(NSNotification *)notification
{
NSLog(@"播放完成");
MPMoviePlayerController *moviePlayer = notification.object;
}
注意:
1、present界面出来时,从顶端出来,取消时,前一个视图也向顶端出来
2、通知对象必须使用MPMoviePlayerViewController的属性moviePlayer