Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

newtoiphonesdk

macrumors 6502a
Original poster
Jul 30, 2010
567
2
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?
 
Last edited:
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)
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.