iOS-Xcode:视频复制在最后一帧中冻结

时间:2013-07-04 19:16:20

标签: mpmovieplayercontroller movie

我正在开发一个iOS应用程序,我想在用户按下按钮时播放视频。 我已经开发了这个,用户按下按钮并播放视频,但是当视频结束时,视频的视图仍然存在,并且在视频的最后一帧中被冻结。

我在谷歌搜索过,我发现了这个问题:

iOS 6, Xcode 4.5 video not exiting when done playing

我使用过那里写的代码,但我没有修复它。 这是我的代码:

-(IBAction)reproducirVideo:(id)sender
{
NSURL *url5 = [NSURL fileURLWithPath:[[NSBundle mainBundle]
                                      pathForResource:@"instrucciones"     ofType:@"mp4"]];
_moviePlayer =  [[MPMoviePlayerController alloc]
                  initWithContentURL:url5];

_moviePlayer.controlStyle = MPMovieControlStyleDefault;
_moviePlayer.shouldAutoplay = YES;
[self.view addSubview:_moviePlayer.view];
[_moviePlayer setFullscreen:YES animated:YES];
}

-(void) moviePlayBackDidFinish:(NSNotification *)aNotification{
[_moviePlayer.view removeFromSuperview];
_moviePlayer = nil;
}


- (void)moviePlayerWillExitFullscreen:(NSNotification*) aNotification {
[_moviePlayer stop];
[_moviePlayer.view removeFromSuperview];
_moviePlayer = nil;
}

1 个答案:

答案 0 :(得分:1)

很抱歉给您带来不便,但我已经阅读了这个问题,我刚刚解决了这个问题:

MPMoviePlayerController will not automatically dismiss movie after finish playing (ios 6)

这是正确的代码:

- (IBAction)reproducirVideo:(id)sender
{
NSURL *url = [NSURL fileURLWithPath:[[NSBundle mainBundle]
                                     pathForResource:@"instrucciones" ofType:@"mp4"]];
_moviePlayer =
[[MPMoviePlayerController alloc]
 initWithContentURL:url];

[[NSNotificationCenter defaultCenter] addObserver:self
                                         selector:@selector(moviePlayBackDidFinish:)
                                             name:MPMoviePlayerPlaybackDidFinishNotification
                                           object:_moviePlayer];

_moviePlayer.controlStyle = MPMovieControlStyleDefault;
_moviePlayer.shouldAutoplay = YES;
[self.view addSubview:_moviePlayer.view];
[_moviePlayer setFullscreen:YES animated:YES];
}

- (void) moviePlayBackDidFinish:(NSNotification*)notification {

MPMoviePlayerController *player = [notification object];

[[NSNotificationCenter defaultCenter] removeObserver:self
                                                name:MPMoviePlayerPlaybackDidFinishNotification
                                              object:player];

if ([player
     respondsToSelector:@selector(setFullscreen:animated:)])
{
    [player setFullscreen:NO animated:YES];
    [player.view removeFromSuperview];
}
}

感谢JASEN !!!你拯救了我的生命

祝你好运