简体   繁体   中英

iOS 7 Notification center not called

i have use this code for doing playing some videos. and want to recieve event when finish the play. but not get the event using Notification center.

i have tried this code

    NSString * str=[[NSBundle mainBundle]pathForResource:@"iGreet" ofType:@"m4v"];

    NSURL * url=[NSURL fileURLWithPath:str];

    MPMoviePlayerController * movieController=[[MPMoviePlayerController alloc]initWithContentURL:url];
    movieController.controlStyle=MPMovieControlStyleFullscreen;
    [movieController.view setFrame:self.view.bounds];

    [movieController setMovieSourceType:MPMovieSourceTypeFile];
    movieController.shouldAutoplay=YES;

    [self.view addSubview:movieController.view];
    [movieController setFullscreen:YES animated:YES];
    [movieController play];


    [[NSNotificationCenter defaultCenter] addObserver:self
                                             selector:@selector(onStop:)
                                                 name:MPMoviePlayerPlaybackDidFinishNotification
                                               object:movieController];

}

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


}

Change to:

[[NSNotificationCenter defaultCenter] addObserver:self
                                             selector:@selector(onStop:)
                                                 name:MPMoviePlayerPlaybackDidFinishNotification
                                               object:movieController];

and

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


}

It works for me.

This is from the documentation for MPMoviePlayerController

This notification is not sent when a movie is displaying in fullscreen mode and the user taps Done. The Done button pauses playback and causes the movie player to exit fullscreen mode. To detect this scenario, register for other notifications such as MPMoviePlayerDidExitFullscreenNotification.

Perhaps that might help you

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM