简体   繁体   English

iOS 7通知中心未调用

[英]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 这来自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. 要检测这种情况,请注册其他通知,例如MPMoviePlayerDidExitFullscreenNotification。

Perhaps that might help you 也许这可能对您有帮助

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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