Resolved Set View Controller to nil

Discussion in 'iOS Programming' started by newtoiphonesdk, Mar 22, 2012.

  1. newtoiphonesdk, Mar 22, 2012
    Last edited: Mar 25, 2012

    newtoiphonesdk macrumors 6502a

    Joined:
    Jul 30, 2010
    #1
    I have a Table View that when clicked, pushes a different view controller and streams audio through that controller. I am trying to add a Now Playing button that will only show when the detail view playing the audio is not set to nil. It is working fine, but I am not sure how to get the controller to return to nil after the movie has finished playing. Any suggestions?
     
  2. jnoxx macrumors 65816

    jnoxx

    Joined:
    Dec 29, 2010
    Location:
    Aartselaar // Antwerp // Belgium
    #2
    There is a Delegate message, here is some example code

    Code:
    
    - (void) playmovie {	
        NSURL *url = [NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"APP intro" ofType:@"mp4"]];  
        moviePlayerController = [[MPMoviePlayerController alloc] initWithContentURL:url];  
        
        // Register to receive a notification when the movie has finished playing.  
        [[NSNotificationCenter defaultCenter] addObserver:self  
                                                 selector:@selector(moviePlayBackDidFinish:)  
                                                     name:MPMoviePlayerPlaybackDidFinishNotification  
                                                   object:moviePlayerController];  
        [[NSNotificationCenter defaultCenter] addObserver:self 
                                                 selector:@selector(movieDonePreload:) 
                                                     name:MPMoviePlayerLoadStateDidChangeNotification 
                                                   object:moviePlayerController];
        
        if ([moviePlayerController respondsToSelector:@selector(setFullscreen:animated:)]) {  
            // Use the new 3.2 style API  
            moviePlayerController.controlStyle = MPMovieControlStyleNone;   
            [moviePlayerController.view setFrame:CGRectMake(0, 0, 1024, 748)];
            [self.view insertSubview:moviePlayerController.view belowSubview:masqueView];
            [moviePlayerController play];
        } 
        
    }
    
    - (void) moviePlayBackDidFinish:(NSNotification*)notification { 
        MPMoviePlayerController *moviePlayer = [notification object];  
        [[NSNotificationCenter defaultCenter] removeObserver:self  
                                                        name:MPMoviePlayerPlaybackDidFinishNotification  
                                                      object:moviePlayer];  
        
        // If the moviePlayer.view was added to the view, it needs to be removed  
        if ([moviePlayer respondsToSelector:@selector(setFullscreen:animated:)]) {  
            [UIView animateWithDuration:0.4 animations:^{
                moviePlayer.view.alpha = 0.0;
            }];
            [self performSelector:@selector(removeAfterTime:) withObject:moviePlayer.view afterDelay:0.4]; 
        }  
        
    }  
    
    Not sure if you need alot of explenation, let me know when you have more questions :)

    (instead of my performselector, you can do a "popviewcontroller" on your navigationcontroller)
     
  3. newtoiphonesdk thread starter macrumors 6502a

    Joined:
    Jul 30, 2010

Share This Page