我有以下代码来播放视频
moviePlayer1 =[[MPMoviePlayerController alloc] initWithContentURL:firstMovieURL1];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(doneButtonClicked) name:MPMoviePlayerWillExitFullscreenNotification object:nil];
[[moviePlayer1 view] setFrame: [self.view bounds]]; // frame must match parent view
[self.view addSubview: [moviePlayer1 view]];
[moviePlayer1 play];
-(void)doneButtonClicked
{
NSLog(@"doneButtonClicked ...");
[moviePlayer1 stop];
[moviePlayer1.view removeFromSuperview];
}
如果我使用上面的代码我的屏幕看起来像这样。我必须点击小箭头图标然后再次点击屏幕以显示控件(向前/向后/完成按钮)
所以我做的是将这个controlStyle添加到我的代码中。现在,只要播放器启动,我就会看到所有按钮,但现在我的完成按钮没有关闭窗口而只是暂停电影。发生了什么事?
moviePlayer1.controlStyle=MPMovieControlStyleFullscreen;
[moviePlayer1 play];
答案 0 :(得分:0)
这是你如何做到的。如果苹果让这个逻辑在我们身上变得容易,那么上帝是禁止的。
[[moviePlayer1 view] setFrame: [self.view bounds]]; // frame must match parent view
[self.view addSubview: [moviePlayer1 view]];
moviePlayer1.controlStyle=MPMovieControlStyleFullscreen;
[moviePlayer1 prepareToPlay];
[moviePlayer1 play];
//use this instead
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(doneButtonClicked:) name:MPMoviePlayerPlaybackDidFinishNotification object:nil];
-(void)doneButtonClicked:(NSNotification*)notification
{
NSLog(@"doneButtonClicked ...");
NSNumber *reason = [notification.userInfo objectForKey:MPMoviePlayerPlaybackDidFinishReasonUserInfoKey];
if ([reason intValue] == MPMovieFinishReasonUserExited)
{
// done button clicked!
[moviePlayer1 stop];
[moviePlayer1.view removeFromSuperview];
}
}