2

我正在使用此代码在 iOS 6 上播放视频:

-(void)GrommeVideo4
{
NSURL *url5 = [NSURL fileURLWithPath:[[NSBundle mainBundle]
                                      pathForResource:@"Flickers" ofType:@"mp4"]];
grommePlayer4 =  [[MPMoviePlayerController alloc]
                  initWithContentURL:url5];

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

[[NSNotificationCenter defaultCenter] addObserver:self
                                         selector:@selector(moviePlayerWillExitFullscreen:)
                                             name:MPMoviePlayerWillExitFullscreenNotification
                                           object:nil];

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

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


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

而且我可以随时按“完成”退出视频,并且效果很好,但是当我将视频观看到最后时,它只是显示黑屏。关于为什么会发生这种情况的任何想法?

4

2 回答 2

2

试试这个,希望有帮助

-(void)GrommeVideo4
{
    NSURL *url5 = [NSURL fileURLWithPath:[[NSBundle mainBundle]
                                      pathForResource:@"Flickers" ofType:@"mp4"]];
    grommePlayer4 =  [[MPMoviePlayerController alloc]
                  initWithContentURL:url5];

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

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


- (void)moviePlayerWillExitFullscreen:(NSNotification*) aNotification {
    [grommePlayer4 stop];
    [grommePlayer4.view removeFromSuperview];
    grommePlayer4 = nil;
}
于 2012-11-08T09:19:04.493 回答
0

您是否尝试在moviePlayBackDidFinish 中也停止播放器?

于 2012-11-07T20:29:45.010 回答