Why is it not possible to use the MPMoviePlayerController more than once?

前端 未结 3 1949
旧时难觅i
旧时难觅i 2020-12-31 10:07

In MonoTouch, we ran into this problem with the Movie Player sample in that it would only play the video once, but would not play it a second time.

I am asking thi

3条回答
  •  谎友^
    谎友^ (楼主)
    2020-12-31 10:40

    Can't see your code Nir and I don't have edit privileges so here it is again:

    The secret lays in the endPlay with setting the: moviePlayer.initialPlaybackTime = -1; before releasing it. Try it out : :)

    -(void)playMovie:(NSString *)urlString{ movieURL = [NSURL URLWithString:urlString];          
    moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:movieURL];    
    moviePlayer.initialPlaybackTime = 0; 
    //Register to receive a notification when the movie has finished playing. 
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(endPlay:) name:MPMoviePlayerPlaybackDidFinishNotification object:moviePlayer];
    
    moviePlayer.scalingMode = MPMovieScalingModeAspectFit; 
    moviePlayer.movieControlMode = MPMovieControlModeDefault;
    moviePlayer.backgroundColor = [UIColor blackColor];
    
    [moviePlayer play];
    
    }
    
    -(void)endPlay: (NSNotification*)notification{
     [[NSNotificationCenter defaultCenter] removeObserver:self name:MPMoviePlayerPlaybackDidFinishNotification object:moviePlayer]; 
    moviePlayer.initialPlaybackTime = -1; 
    [moviePlayer stop]; 
    [moviePlayer release]; 
    } 
    

提交回复
热议问题