views:

73

answers:

1

Hi. i have a small movieplayer in a rectangle (20,20,300,200) in an ipadview. there is a UIpagedcontrol. while a movie plays i change the UIPage, but movieFinishedCallback notification cant be called. i think movieFinishedCallback notification is called when the movie completly finished. i want to stop movie and prepare the next movie when the UIPage changed. which notification should i register?

i play video with this code:

//loading video codes
        NSURL *url = [NSURL URLWithString:self.currentVideoPath];
        MPMoviePlayerController *player = [[MPMoviePlayerController alloc] initWithContentURL:url];

        [[NSNotificationCenter defaultCenter] addObserver:self 
                                                 selector:@selector(movieFinishedCallback:)
                                                     name:MPMoviePlayerPlaybackDidFinishNotification object:player];
        player.view.frame = CGRectMake(20, 20, 320, 200);
    self.moviePlayer=player;
        [self.view addSubview:self.moviePlayer.view];
        [moviePlayer play];

        -(void) movieFinishedCallback:(NSNotification*) aNotification {
            //MPMoviePlayerController *player = [aNotification object];
            [[NSNotificationCenter defaultCenter] removeObserver:self name:MPMoviePlayerPlaybackDidFinishNotification object:self.moviePlayer];

            self.moviePlayer.initialPlaybackTime=-1.0;
            [self.moviePlayer stop];
            [self.moviePlayer release];    
            self.moviePlayer = nil;
        }

in .h file;

    MPMoviePlayerController *moviePlayer;
    //...
    @property (nonatomic, retain)   MPMoviePlayerController *moviePlayer;
A: 

when user changes page call [player stop];
which internally calls MPMoviePlayerPlaybackDidFinishNotification then you can set up next movie loading.

jeeva
i edited my code. i put [player stop] method in valuechanged method of UIPagecontrol, then i watched the NSLog but it doestn enter the movieFinishedCallback even
tester
ok but you have a option to stop current movie and start new movie go ahead with this...
jeeva