2011-02-28 3 views
0

많은 비디오를 보여주는 응용 프로그램이 있습니다. 파일을로드하고 재생하려면, 나는 다음과 같은 코드를 사용합니다 NSNotification이 알리지 않음

- (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에 비디오가 올바르게 시작됩니다. 알림은 어떻게 받아야합니까?

답변

0

부분적으로 문제가 풀 렸습니다 : 문제는 NSNotification이 아니라 PrepareToPlay입니다.

관련 문제