您的位置:首页 > 产品设计 > 产品经理

关于MPMoviePlayerController的一些知识

2016-03-14 09:54 806 查看
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);
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: