Jak ukryć kontrolę przed odtwarzaniem filmu MPMoviePlayerController?

Załóżmy iOS 3.2 lub nowszy. Jaka jest prawidłowa Sekwencja poleceń, aby zagrać ruch z kontrolkami początkowo ukrytymi. Gdy film jest odtwarzany, użytkownik ma opcję oznaczania na ekranie i pokazywania kontrolek.

Dzięki!

Mój (nie ukryty) kod:

- (void)playMovie
{
    NSURL *url = [NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"Test" ofType:@"m4v"]];  
    MPMoviePlayerController *moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:url];  

    // Register to receive a notification when the movie has finished playing.  
    [[NSNotificationCenter defaultCenter] addObserver:self  
                                             selector:@selector(movieDone:)  
                                                 name:MPMoviePlayerPlaybackDidFinishNotification  
                                               object:moviePlayer];  

    [[NSNotificationCenter defaultCenter] addObserver:self  
                                             selector:@selector(movieState:)  
                                                 name:MPMoviePlayerNowPlayingMovieDidChangeNotification  
                                               object:moviePlayer];  

    [[NSNotificationCenter defaultCenter] addObserver:self 
                                             selector:@selector(movieReady:) 
                                                 name:MPMoviePlayerLoadStateDidChangeNotification 
                                               object:nil];

    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(willEnterFullScreen:) name:MPMoviePlayerWillEnterFullscreenNotification object:moviePlayer];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(willExitFullScreen:) name:MPMoviePlayerWillExitFullscreenNotification object:moviePlayer];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(didFinishPlayback:) name:MPMoviePlayerPlaybackDidFinishNotification object:moviePlayer];


    if ([moviePlayer respondsToSelector:@selector(setFullscreen:animated:)]) {  
        moviePlayer.controlStyle = MPMovieControlStyleDefault; // MPMovieControlStyleNone MPMovieControlStyleEmbedded MPMovieControlStyleFullscreen MPMovieControlStyleDefault
        moviePlayer.scalingMode = MPMovieScalingModeAspectFill; // MPMovieScalingModeAspectFit MPMovieScalingModeAspectFill
    }   
}

- (void) movieReady:(NSNotification*)notification 
{
    MPMoviePlayerController *moviePlayer = [notification object];  

    if ([moviePlayer loadState] != MPMovieLoadStateUnknown) {
        // Remove observer
        [[NSNotificationCenter defaultCenter] removeObserver:self  
                                                        name:MPMoviePlayerLoadStateDidChangeNotification  
                                                      object:nil];

        // When tapping movie, status bar will appear, it shows up
        // in portrait mode by default. Set orientation to landscape
        [[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationLandscapeLeft animated:NO];
        [[UIApplication sharedApplication] setStatusBarHidden:YES withAnimation:UIStatusBarAnimationNone];

        // Add movie player as subview
        [[self view] addSubview:[moviePlayer view]];   

        // Play the movie
        [moviePlayer play];
        [moviePlayer setFullscreen:YES animated:YES];       
    }
}
Author: ohho, 2010-10-18

3 answers

[Update] zgodnie z propozycją @ ReinYem, znacznie lepszym rozwiązaniem jest poleganie na MPMoviePlayerLoadStateDidChangeNotification zamiast na timerze.

W rzeczywistości następujące rozwiązanie nie powinno być już brane pod uwagę:

Ustaw właściwość controlStyle Na MPMovieControlStyleNone początkowo, a następnie ustaw ją na MPMovieControlStyleFullscreen sekundę później za pomocą [performSelector:withObject:afterDelay:1]. Działa dobrze, kontrolki nie pojawiają się, dopóki użytkownik nie dotknie wideo.

 35
Author: Phil,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2014-08-08 06:20:23

Użyj wywołania zwrotnego zamiast timera :

    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(hidecontrol) 
                                                 name:MPMoviePlayerLoadStateDidChangeNotification 
                                               object:playerView.moviePlayer];

Z funkcją call back:

- (void) hidecontrol {
[[NSNotificationCenter defaultCenter] removeObserver:self     name:MPMoviePlayerNowPlayingMovieDidChangeNotification object:playerView.moviePlayer];
[playerView.moviePlayer setControlStyle:MPMovieControlStyleFullscreen];

}
 34
Author: ReinYem,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2011-10-25 13:22:13
player.moviePlayer.controlStyle = MPMovieControlStyleNone;
To najnowszy sposób na to. :)
 10
Author: LAMBORGHINI,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2013-06-20 20:33:05