使用MPMoviePlayerViewController
以全屏模式播放视频时遇到问题(在正常模式下完美无效)。
CODE:
if (PlayV) {
self.previewView.hidden=NO;
self.videoController =[[MPMoviePlayerController alloc] initWithContentURL:self.videoURL];
[self.videoController.view setFrame:self.previewView .frame];
self.videoController.view.center=self.playBtn.center;
[self.previewView addSubview:self.videoController.view];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(videoPlayBackDidFinish:) name:MPMoviePlayerPlaybackDidFinishNotification object:self.videoController];
self.videoController.scalingMode = MPMovieScalingModeAspectFit;
self.videoController.controlStyle = MPMovieControlStyleNone;
[self.videoController play];
}
答案 0 :(得分:1)
我得到了解决方案 - 希望它也会帮助其他人。
在playBtnAction
方法中添加以下代码:
- (IBAction)playBtnAction:(id)sender {
[self.videoController setFullscreen:YES animated:YES];
}
然后在videoPlayBackDidFinish
中添加此行代码。
MPMoviePlayerController *player=[notification object];
if ([player respondsToSelector:@selector(setFullscreen:animated:)]) {
[player.view removeFromSuperview];
}
此代码将检查视频是否处于全屏模式并将其恢复为正常模式。
答案 1 :(得分:0)
moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:[NSURL fileURLWithPath:imagepath]]; //moviePlayer declared in .h and set URL
moviePlayer.view.frame = CGRectMake(364, 89, 660, 668); //set custom frame
moviePlayer.controlStyle = MPMovieControlStyleDefault;
moviePlayer.shouldAutoplay = YES;
[self.view addSubview:moviePlayer.view]; //add to view
[moviePlayer setFullscreen:NO animated:YES];
这可能会对你有帮助。