首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >NSNotification不通知

NSNotification不通知
EN

Stack Overflow用户
提问于 2011-02-28 23:48:51
回答 1查看 571关注 0票数 0

我有一个应用程序,可以显示很多视频。要加载和播放该文件,我使用以下代码:

代码语言:javascript
复制
- (IBAction)playVideoooo {
[[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:YES];
moviePlayerController = [[MPMoviePlayerController alloc] initWithContentURL:
                         [NSURL URLWithString:@"/UnioneDiCentro2011_Live.isml/manifest(format=m3u8-aapl)"]];
switch ( [self interfaceOrientation] ) {
    case UIInterfaceOrientationPortrait:
    case UIInterfaceOrientationPortraitUpsideDown:
        [[moviePlayerController view] setFrame:CGRectMake(0, 0, P_WIDTH, P_HEIGHT)];
        break;
    case UIInterfaceOrientationLandscapeLeft:
    case UIInterfaceOrientationLandscapeRight:
        [[moviePlayerController view] setFrame:CGRectMake(0, 0, L_WIDTH, L_HEIGHT)];
        break;
}
[moviePlayerController prepareToPlay];
[[NSNotificationCenter defaultCenter] addObserver:self 
                                         selector:@selector(moviePlayerLoadStateChanged:) 
                                             name:MPMoviePlayerLoadStateDidChangeNotification 
                                           object:nil]; // Register that the load state changed (movie is ready)
[[NSNotificationCenter defaultCenter] addObserver:self 
                                         selector:@selector(moviePlayBackDidFinish:) 
                                             name:MPMoviePlayerPlaybackDidFinishNotification 
                                           object:nil];
[[self view] addSubview:[moviePlayerController view]];
}

- (void)moviePlayerLoadStateChanged:(NSNotification*)notification {
// Unless state is unknown, start playback
if ([moviePlayerController loadState] != MPMovieLoadStateUnknown) {
    [[NSNotificationCenter defaultCenter] removeObserver:self 
                                                    name:MPMoviePlayerLoadStateDidChangeNotification 
                                                  object:nil];
    [[UIApplication sharedApplication] setStatusBarOrientation:[self interfaceOrientation] 
                                                      animated:YES];
            [moviePlayerController play];
    [[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:NO];

}
}

- (void)moviePlayBackDidFinish:(NSNotification*)notification {    
[[UIApplication sharedApplication] setStatusBarHidden:NO];
[[NSNotificationCenter  defaultCenter] removeObserver:self 
                                                 name:MPMoviePlayerPlaybackDidFinishNotification 
                                               object:nil];
switch ( [self interfaceOrientation] ) {
    case UIInterfaceOrientationPortrait:
    case UIInterfaceOrientationPortraitUpsideDown:
        [[moviePlayerController view] setFrame:CGRectMake(0, 0, P_WIDTH, P_HEIGHT)];
        break;
    case UIInterfaceOrientationLandscapeLeft:
    case UIInterfaceOrientationLandscapeRight:
        [[moviePlayerController view] setFrame:CGRectMake(0, 0, L_WIDTH, L_HEIGHT)];
        break;
}       
if ( [moviePlayerController isFullscreen] ) {
    [moviePlayerController setFullscreen:NO];
}
}

实际上,系统似乎正常工作,但我必须按下链接到"playVideooooo“的按钮两次,才能让通知工作。如果我将moviePlayerController play;移动到IBActions中,视频将正确启动。我应该如何让通知工作?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2011-03-31 22:23:12

问题部分解决了:问题不在NSNotification,而在PrepareToPlay。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/5144171

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档