我正在使用自定义电影播放器以MPMoviePlayer为基础播放视频,而当调用 setFullscreen:YES 时播放器将进入全屏状态,当 setFullscreen:NO 被调用。
我试过了:
这是我目前使用的代码。我见过的所有答案都没有为我解决问题,所以任何帮助都会非常感激。
- (IBAction)fullScreenPressed:(id)sender {
if ([self mediaIsVideo]){
if ([self.videoController.moviePlayer isFullscreen]){
[self.videoController.moviePlayer setFullscreen:NO animated:YES];
UIImage *full = [UIImage imageNamed:@"fullscreen-vector-icon.png"];
[self.videoFullscreenButton setImage:full forState:UIControlStateNormal];
}else{
//video is in fullscreen, add notification observer
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(exitFullscreen) name:MPMoviePlayerPlaybackDidFinishNotification object:nil];
[self.videoController.moviePlayer setFullscreen:YES animated:YES];
UIImage *undoFull = [UIImage imageNamed:@"fullscreen-exit-vector-icon.png"];
[self.videoFullscreenButton setImage:undoFull forState:UIControlStateNormal];
}
}
-(void)exitFullscreen{
if ([self mediaIsVideo]){
NSLog(@"notification selector called");
[self.videoController.moviePlayer setFullscreen:NO animated:YES];
[[UIApplication sharedApplication] setStatusBarHidden:NO];
[[NSNotificationCenter defaultCenter] removeObserver:self name:MPMoviePlayerPlaybackDidFinishNotification object:nil];
}
}