MPMoviePlayerController可以设置视频的frame.即设置其view的frame.
监听MPMoviePlayerController的全屏按钮和退出全名按钮的方法就是添加通知.
[notificationCenter addObserver:self selector:@selector(willFullScreen:) name:MPMoviePlayerWillEnterFullscreenNotification object:self.moviePlayer];
[notificationCenter addObserver:self selector:@selector(willFullScreen:) name:MPMoviePlayerWillExitFullscreenNotification object:self.moviePlayer];
方法里可以设置全屏的方法:
- (void)willFullScreen:(NSNotification *)notification
{
if (self.view.bounds.size.width < self.view.bounds.size.height) {
[[UIDevice currentDevice] setValue:[NSNumber numberWithInteger:UIInterfaceOrientationLandscapeRight] forKey:@"orientation"];
} else {
[[UIDevice currentDevice] setValue:[NSNumber numberWithInteger:UIInterfaceOrientationPortrait] forKey:@"orientation"];
}
}
MPMoviePlayerController除了一般的视频播放和控制外还有一些强大的功能,例如截取视频缩略图。请求视频缩略图时只要调用- (void)requestThumbnailImagesAtTimes:(NSArray *)playbackTimes timeOption:(MPMovieTimeOption)option方法指定获得缩略图的时间点,然后监控MPMoviePlayerThumbnailImageRequestDidFinishNotification通知,每个时间点的缩略图请求完成就会调用通知,在通知调用方法中可以通过MPMoviePlayerThumbnailImageKey获得UIImage对象处理即可。
[notificationCenter addObserver:self selector:@selector(mediaPlayerThumbnailRequestFinished:) name:MPMoviePlayerThumbnailImageRequestDidFinishNotification object:self.moviePlayer];
通知所执行的方法为:
-(void)mediaPlayerThumbnailRequestFinished:(NSNotification *)notification{
NSLog(@"视频截图完成.");
UIImage *image=notification.userInfo[MPMoviePlayerThumbnailImageKey];
//保存图片到相册(首次调用会请求用户获得访问相册权限)
UIImageWriteToSavedPhotosAlbum(image, nil, nil, nil);
}