按下完成后如何从MPMoviePlayerController中删除动画

时间:2014-12-01 10:00:40

标签: ios objective-c iphone mpmovieplayercontroller

当用户按下完成按钮时,我想删除MPMoviePLayerController中发生的过渡动画。我曾经在电影完成时使用moviePlayBackDidFinish:通知来停止它,但它不起作用,就像动画一样。这个代码我用过。

NSURL *fileURL=[NSURL URLWithString:mediaurl1];

moviePlayerController = [[MPMoviePlayerController alloc] initWithContentURL:fileURL];
[moviePlayerController.view setFrame:CGRectMake(0, 150, 320, 270)];

[[NSNotificationCenter defaultCenter] addObserver:self
                                         selector:@selector(doneButtonClick:)
                                             name:MPMoviePlayerWillExitFullscreenNotification
                                           object:moviePlayerController];

[[NSNotificationCenter defaultCenter] addObserver:self
                                         selector:@selector(donefinished:)
                                             name:MPMoviePlayerPlaybackDidFinishNotification
                                           object:moviePlayerController];

[self presentMoviePlayerViewControllerAnimated:moviePlayerController];

[mediaView addSubview:moviePlayerController.view];
[moviePlayerController setFullscreen:YES animated:NO];
moviePlayerController.useApplicationAudioSession = YES;
[moviePlayerController play];

这是关闭动画效果的通知方法。

-(void)doneButtonClick:(NSNotification*)aNotification{



    [mediaView removeFromSuperview ];
    [moviePlayerController setFullscreen:NO animated:NO];
    [self dismissViewControllerAnimated:NO completion:NO];
   // [moviePlayerController setFullscreen:NO animated:NO];


}
-(void)donefinished:(NSNotification*)aNotification{


    [mediaView removeFromSuperview ];
    [moviePlayerController setFullscreen:NO animated:NO];
    [self dismissViewControllerAnimated:NO completion:NO];
    // [moviePlayerController setFullscreen:NO animated:NO];


}

1 个答案:

答案 0 :(得分:1)

Use it.
-(void)donefinished:(NSNotification*)aNotification
{
    [moviePlayerController stop];
    [moviePlayerController.view removeFromSuperview];
    moviePlayerController = nil;
}