开发者

Testing MPMoviePlayerViewController in iPad simulator

开发者 https://www.devze.com 2022-12-30 02:54 出处:网络
I have a view that shows a MPMoviePlayerViewController modally. When testing it in the iPad simulator it works well on the first try. If I dismiss the video and then show the view again, the player on

I have a view that shows a MPMoviePlayerViewController modally. When testing it in the iPad simulator it works well on the first try. If I dismiss the video and then show the view again, the player only plays the audio, but not the vide开发者_StackOverflow社区o.

Is this a simulator quirk or am I doing something wrong? Here's my code:

- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    MPMoviePlayerViewController* v = [[MPMoviePlayerViewController alloc] initWithContentURL:url];
    [[NSNotificationCenter defaultCenter] addObserver:self selector: @selector(playbackDidFinish:) name:MPMoviePlayerPlaybackDidFinishNotification object:v.moviePlayer];
    [self presentMoviePlayerViewControllerAnimated:v];
    [v release];
}

-(void) playbackDidFinish:(NSNotification*)aNotification
{
    MPMoviePlayerController *player = [aNotification object];
    [[NSNotificationCenter defaultCenter] removeObserver:self
                                                name:MPMoviePlayerPlaybackDidFinishNotification
                                              object:player];
    [player stop];
    [self dismissMoviePlayerViewControllerAnimated];
}


Instead of putting the code to create one view controller in the viewWillAppear of another view controller, why not just create the MPMoviePlayerViewController directly? Usually view controllers are created or shown in direct response to some user action. Other than that there is nothing wrong with the code shown. I have never had any trouble playing movies in the simulator, but I created the MPMoviePlayerViewController in didSelectRow or in response to a button click.

0

精彩评论

暂无评论...
验证码 换一张
取 消