iOS 6, Xcode 4.5 video not exiting when done playing

北慕城南 提交于 2019-12-22 17:48:24

问题


I am using this code to play a video on 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;
}

And I can press "Done" to exit the video at any time, and it works fine, but when I watch the video through to the end, it just displays a black screen. Any ideas as to why this could occur?


回答1:


try this, hope it helps

-(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;
}



回答2:


Did you try to also stop the player in moviePlayBackDidFinish?



来源:https://stackoverflow.com/questions/13277295/ios-6-xcode-4-5-video-not-exiting-when-done-playing

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!