好吧,我可以找到很多关于相同或类似问题和答案的问题......但是,没有什么可以帮助我。只有当我不使用属性“controlStyle”作为“MPMovieControlStyleFullscreen”时,“完成”按钮才有效。我试过这种方式..
MPMoviePlayerController *mpMoviePlayerController = [[MPMoviePlayerController alloc] initWithContentURL:[NSURL URLWithString:@"https://dl.dropbox.com/u/14218997/thxq.mp4"]];
mpMoviePlayerController.controlStyle = MPMovieControlStyleNone;
[mpMoviePlayerController setUseApplicationAudioSession:NO];
[mpMoviePlayerController setScalingMode:MPMovieScalingModeAspectFit];
[mpMoviePlayerController setFullscreen:YES animated:YES];
[mpMoviePlayerController.view setFrame:CGRectMake(0, 0, 1024, 768)];
[[globalSingleton paintingView] addSubview:mpMoviePlayerController.view];
[mpMoviePlayerController prepareToPlay];
[mpMoviePlayerController play];
mpMoviePlayerController.controlStyle = MPMovieControlStyleFullscreen;
或者这样..
MPMoviePlayerController *mp;
MPMoviePlayerViewController *mpVC = [[MPMoviePlayerViewController alloc] initWithContentURL:[NSURL URLWithString:@"https://dl.dropbox.com/u/14218997/thxq.mp4"]];
mp = [mpVC moviePlayer];
mp.controlStyle = MPMovieControlStyleFullscreen;
mp.fullscreen = NO;
mp.useApplicationAudioSession = NO;
mp.view.frame = CGRectMake(0, 0, 1024, 768);
[[globalSingleton paintingView] addSubview:mp.view];
([globalSingleton paintingView]仅用于表示主视图。我已经检查过它没有问题。)
请分享您对此问题的了解。 Thx提前!
答案 0 :(得分:3)
根据您的代码,我认为您的目的是让全屏电影播放器接管屏幕。在这种情况下,您可能最好使用MPMoviePlayerViewController,但您需要使用当前的视图控制器将其作为模态视图控制器呈现,如下所示:
MPMoviePlayerViewController *movieViewController = [[MPMoviePlayerViewController alloc] initWithContentURL:someVideoURL];
movieViewController.moviePlayer.scalingMode = MPMovieScalingModeAspectFit;
// Self is the UIViewController you are presenting the movie player from.
[self presentMoviePlayerViewControllerAnimated:movieViewController];
在这种情况下,“完成”按钮应该可以正常工作,并关闭模态MPMoviePlayerViewController
另一方面,如果您对在当前视图层次结构中添加动画的地方动画电影更感兴趣,以下是我为实现此目的所做的一个示例:
我还发现将MPMoviePlayerController
的controlStyle属性设置为MPMovieControlStyleFullscreen
具有相同的结果 - “完成”按钮未关闭MPMoviePlayerController
。当我将其更改为MPMovieControlStyleDefault
时,它按预期工作。但是,在我的情况下,我将MPMoviePlayerController
的视图作为缩略图大小的子视图添加到当前显示的UIViewController
视图中。我最初将MPMoviePlayerController
的controlStyle设置为MPMovieControlStyleNone
。我在缩略图大小的电影播放器视图上有一个自定义UIButton
,在按钮的操作方法中,我正在将MPMoviePlayerController
的controlStyle更改为MPMovieControlStyleDefault
,然后调用{ {1}}将电影播放器视图设置为全屏模式。然后,正确点击“完成”按钮可将玩家动画回原位到我setFullscreen:animated:
视图的缩略图大小的子视图中。这是一个例子:
我UIViewController
的初步实例化:
MPMoviePlayerController
注意:我还在我的moviePlayer视图的顶部添加了一个自定义UIButton(以调用全屏播放)并设置它的操作以调用以下方法:
// My moviePlayerController is a property
self.moviePlayer = [[MPMoviePlayerController alloc] initWithURL:videoURL];
moviePlayer.controlStyle = MPMovieControlStyleNone;
moviePlayer.scalingMode = MPMovieScalingModeAspectFit;
moviePlayer.shouldAutoplay = NO;
// Add the moviePlayer's view as a subview of a my UIViewController's view.
moviePlayer.view.frame = CGRectMake(20, 20, 160, 90);
[self.view addSubview:moviePlayer.view];
注意:我还观察并处理MPMoviePlayerWillExitFullscreenNotification,我将controlStyle设置回MPMovieControlStyleNone。