Search code examples
macoscocoaquicktime

How do I detect QTMovie stop playing?


I have done the following - once played a QTMovie (on Mountain Lion) and wanted to get notification when a movie ended. But the notification never got called! Can anybody tell me what have I done wrong?

- (void)playMovie:(QTMovie *)movie {
    [self.movieView.movie stop];

    if (movie) {
        self.movieView.movie = movie;
        [movie gotoBeginning];
        [movie play];

        [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(stopMovie:) name:QTMovieDidEndNotification object:self];
    }
}


- (void)stopMovie:(NSNotification *)notification {
    NSLog(@"stop movie!");
    [[NSNotificationCenter defaultCenter] removeObserver:self name:QTMovieDidEndNotification object:nil];
}

Solution

  • Try changing to the following (note the object parameter):

    [[NSNotificationCenter defaultCenter] addObserver:self
        selector:@selector(stopMovie:)
        name:QTMovieDidEndNotification
        object:movie];