문제

I have a simple view that creates a MPMoviePlayerViewController when the user presses a button, using the presentMoviePlayerViewControllerAnimated: method. The new view controller slides in and shows the movie player, so far so good.

However, when the button is pushed, the current view controller slides out the bottom, showing a ugly (probably default) white view, that sticks around anywhere from half a second to a few seconds, until the movie view controller is shown. It seems like it's dependent on my network connection, as if the movie view controller is downloading parts of the movie before showing the player.

Am I doing something wrong, or how can I work around this? I'd really prefer to just show the movie view controller directly, maybe even without sliding out the previous view controller that holds the play button, but still animated like a modal view controller.

Thanks!

Christoph

도움이 되었습니까?

해결책 2

I ended up just setting the background of the view to black. Doesn't fix the delay, but makes it look much nicer:

  theMovieVC.view.backgroundColor = [UIColor blackColor];

다른 팁

The solution was to init the player view controller when the parent view is created, and then call prepareToPlay on the moviePlayer inside it. That removes the latency when the play button is pushed and (I guess) moves it to when the user gets to the parent view from which he can play the movie.

EDIT: This removes the delay, but for some reason, initializing the movie view controller also autoplays it when it's loaded, so that's not a good solution.

this is what i do for iOS > 3.2 :

- (void) play {
    mMoviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:mMovieURL];

    if ([mMoviePlayer respondsToSelector:@selector(loadState)]) 
    {
        [[NSNotificationCenter defaultCenter] addObserver:self 
                                                 selector:@selector(moviePreloadDidFinishIOS32:) 
                                                     name:MPMoviePlayerContentPreloadDidFinishNotification 
                                                   object:nil];


        [mMoviePlayer prepareToPlay];
        [mMoviePlayer play];
        mMoviePlayer.controlStyle = MPMovieControlStyleEmbedded;
        [mMoviePlayer setMovieControlMode:MPMovieControlModeDefault];
        [mMoviePlayer setBackgroundColor:[UIColor clearColor]];
    }
}

and

- (void) moviePreloadDidFinishIOS32:(NSNotification*)notification;
{
    // Remove observer
    [[NSNotificationCenter  defaultCenter] 
     removeObserver:self
     name:MPMoviePlayerContentPreloadDidFinishNotification
     object:nil];

    self.view = mMoviePlayer.view;
}

Thus in the viewdidload you can instantiate what you want (UIActivityIndicatorView for example). The view controller will only be replaced when the preload is finished.

I'm noticing the same issue in my app. Anyone have suggestions to avoid this issue?

In my case, I'm pushing the MPMoviePlayerViewController to the UI as a modal popup.

// build the movie player
[UIApplication sharedApplication].networkActivityIndicatorVisible = YES;
MPMoviePlayerViewController *movieViewController = [[[MPMoviePlayerViewController alloc] initWithContentURL:request.URL] autorelease];
[movieViewController.moviePlayer prepareToPlay];
movieViewController.view.backgroundColor = [UIColor blackColor];

// show the movie player view
[self.parentViewController presentModalViewController:movieViewController animated:YES];
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top