2012-12-07 42 views
0

我提出一個控制器來播放視頻:不能解僱模態視圖控制器與iOS5的

[self presentModalViewController:movieController animated:YES]; 

,並添加一個觀察者時結束palying:

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(movieFinishedPlayback:) 
name:MPMoviePlayerPlaybackDidFinishNotification object:nil]; 
    } 

    -(void) movieFinishedPlayback:(NSNotification*)notification{ 
     NSLog(@"........movieFinishedPlayback....... \n "); 
     [self dismissModalViewControllerAnimated:YES]; 
     [[NSNotificationCenter defaultCenter] removeObserver:self name:MPMoviePlayerPlaybackDidFinishNotification object:nil]; 
    } 

這是我VideoDetailViewController:

#import "VideoDetailViewController.h" 
#import "PSStackedView.h" 
#import "YunMaoIpadAppDelegate.h" 

#define IpadAppDelegate ((YunMaoIpadAppDelegate *)[[UIApplication sharedApplication] delegate]) 
#define IphoneAppDelegate ((YunMaoIosAppDelegate *)[[UIApplication sharedApplication] delegate]) 

@interface VideoDetailViewController() 

@end 

@implementation VideoDetailViewController 

@synthesize video, moviePlayer, collectionsArray; 

-(id)initWithVideo:(Video *)theVideo 
{ 
    self = [super initWithNibName:@"VideoDetailViewController" bundle:nil]; 
    if (self) { 
     self.video = theVideo; 
    } 
    return self; 
} 
- (void)viewWillDisappear:(BOOL)animated 
{ 
    [moviePlayer pause]; 
    //[self.navigationController setNavigationBarHidden:false animated:animated]; 
    [super viewWillDisappear:animated]; 
} 

- (void)viewDidDisappear:(BOOL)animated; 
{ 
    [[UIApplication sharedApplication] setStatusBarHidden:YES withAnimation:UIStatusBarAnimationNone]; 

    [super viewDidDisappear:animated]; 
} 

- (void) viewWillAppear:(BOOL)animated 
{ 
    [super viewWillAppear:animated]; 
    self.view.backgroundColor = [UIColor blackColor]; 
} 

- (void) viewDidAppear:(BOOL)animated 
{ 
    //[moviePlayer play]; 
    //[DejalBezelActivityView removeViewAnimated:YES]; 
    [super viewDidAppear:animated]; 
} 

- (void)viewDidLoad 
{ 
    [super viewDidLoad]; 

    [self performSelector:@selector(displayActivityView) withObject:self.moviePlayer.view afterDelay:0.1]; 

    moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:[NSURL URLWithString:video.link]]; 
    [moviePlayer prepareToPlay]; 

    //[moviePlayer setShouldAutoplay:NO]; 
    moviePlayer.controlStyle = MPMovieControlStyleFullscreen; 
    moviePlayer.scalingMode = MPMovieScalingModeAspectFit; 

    if([moviePlayer respondsToSelector:@selector(useApplicationAudioSession)]) 
    { 
     if(UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone) 
     { 
      NSLog(@"iPhone ios5.x"); 
      [moviePlayer.view setFrame: CGRectMake(0.0f, 0.0f, 480.0f, 320.0f)]; 
      //moviePlayer.view.transform = CGAffineTransformConcat(moviePlayer.view.transform, CGAffineTransformMakeRotation(M_PI_2)); 
     } 
     else{ 
      NSLog(@"iPad ios5.x"); 
      [moviePlayer.view setFrame: CGRectMake(0.0f, 0.0f, 1024.0f, 768.0f)]; 
      moviePlayer.view.transform = CGAffineTransformConcat(moviePlayer.view.transform, CGAffineTransformMakeRotation(M_PI_2)); 
      [moviePlayer.view setFrame:[IpadAppDelegate window].bounds]; 
     } 
    } 
    else 
    { 
     if(UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone) 
     { 
      moviePlayer.view.transform = CGAffineTransformConcat(moviePlayer.view.transform, CGAffineTransformMakeRotation(M_PI_2)); 

      NSLog(@"iPhone ios6.x"); 
      CGSize result = [[UIScreen mainScreen] bounds].size; 
      if(result.height == 480) 
      { 
       [moviePlayer.view setFrame: CGRectMake(0.0f, 0.0f, 320.0f, 480.0f)]; 
      } 
      if(result.height == 568) 
      { 
       //moviePlayer.controlStyle = MPMovieControlStyleDefault; 
       [moviePlayer.view setFrame:self.view.bounds]; 
      } 
     } 
     else{ 
      NSLog(@"ipad ios 6.x"); 
      [moviePlayer.view setFrame: CGRectMake(0.0f, 0.0f, 1024.0f, 768.0f)]; 
      //[moviePlayer.view setFrame:[IpadAppDelegate window].bounds]; 
     } 
    } 

    [self.view addSubview:moviePlayer.view]; 
    [moviePlayer play]; 
} 

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation 
{ 
    if (interfaceOrientation==UIInterfaceOrientationLandscapeLeft || interfaceOrientation==UIInterfaceOrientationLandscapeRight) 
     return YES; 
    return NO; 
} 

- (BOOL)shouldAutorotate{ 
    return NO; 
} 

/* 
- (NSUInteger)supportedInterfaceOrientations { 
    return UIInterfaceOrientationLandscapeRight; 
} 
*/ 

- (IBAction)displayActivityView 
{ 
    [DejalBezelActivityView activityViewForView:self.moviePlayer.view withLabel:@"節目正在下載中,請稍後..."].showNetworkActivityIndicator = NO; 
} 

- (void)removeActivityView; 
{ 
    [DejalBezelActivityView removeViewAnimated:YES]; 
    [[self class] cancelPreviousPerformRequestsWithTarget:self]; 
} 

- (void)didReceiveMemoryWarning 
{ 
    [super didReceiveMemoryWarning]; 
    // Dispose of any resources that can be recreated. 
} 

@end 
+0

注意,你所添加的'MPMoviePlayerPlaybackDidFinishNotification'觀察者但消除對'MPMoviePlayerDidExitFullscreenNotification'觀察員。這是預期的行動? –

+0

更新問題,仍然無法正常工作。 – why

+0

您遺漏的一條重要信息......您的日誌語句是否顯示在控制檯中?另外,模擬器或設備? – NJones

回答

1

這爲我工作。

[self dismissViewControllerAnimated:NO completion:^{ 
    [self.view removeFromSuperview]; 
}]; 

希望它有幫助!

+0

好的解決方案.. – why

0

駁回movieplayer做[moviePlayer stop];和蘇刪除movieplayer.view之前perview。之後嘗試解僱。這可能會解決這個問題。

相關問題