views:

31

answers:

1

As you know,when i play movie with MPmoviePlayerController ,the moviePlayer should show an activityIndicatorView in the center of the moviePlayer'view. Now,i have put a custom activityIndicatorView in my program,i just want to hide or remove the activityIndicatorView of MPMoviePlayController,can i do that ?

+1  A: 

yes we can!

I guess what you want to do is show the activity idicator while your movie is being loaded, not while it is being played? I just assume that and keep going...

in SDK 3.2 and above, the whole MPMoviePlayerController (and MPMoviePlayerViewController) are a lot better than on previous versions. If you still using MPMoviePlayerController you might consider switching to MPMoviePlayerViewController (which is basically a UIView Subclass that encapsules a MPMoviePlayerController Object).

anyway, to show and hide your UIActivityindicator view, i would recommend you to hook up onto notifications that are being sent from your MPMoviePlayerController when load- or playstatus change.

a few of these are:

MPMoviePlayerPlaybackStateDidChangeNotification
MPMoviePlayerLoadStateDidChangeNotification 

so you hook up to those events doing this:

[[NSNotificationCenter defaultCenter] addObserver: self 
                                             selector: @selector(loadStateChanged:) 
                                                 name: MPMoviePlayerLoadStateDidChangeNotification 
                                               object: moviePlayerViewController.moviePlayer];

and this

        [[NSNotificationCenter defaultCenter] addObserver: self 
                                             selector: @selector(playBackStateChanged:) 
                                                 name: MPMoviePlayerPlaybackStateDidChangeNotification 
                                               object: moviePlayerViewController.moviePlayer];

and within your handlers (playBackStateChanged and loadStateChanged)

you can do something like this:

-(void)playBackStateChanged:(id)sender

{ MPMoviePlaybackState playbackState = [moviePlayerViewController.moviePlayer playbackState];

switch (playbackState) {

    case MPMoviePlaybackStateStopped :


        break;

    case MPMoviePlaybackStatePlaying :
        [yourActivityIndicatorView stopAnimating];
        break;

    case MPMoviePlaybackStateInterrupted :
        [yourActivityIndicatorView startAnimating];
        break;
}

}

make sure the "hidesWhenStopped" (or similar) property of your IndicatorView is set to yes (if you do that, you don't have to care about hiding and unhiding the control.

the rest is simple, just add your activityIndicatorView ontop of your MPMovieViewController's view.

hope i could help
cheers
sam

samsam
I have do that ,what i want just let the activeIndicator of the moviePlayerViewController never show,because i have already add an activeIndicator by myself
ben
Ah i think i understand you now. the solution would be to HIDE your player until the Movieplayer's Loadstate is equal to MPMovieLoadStatePlayable , then unhide the player again. in the meantime you can display your custom loader.
samsam