Comment masquer le contrôle avant MPMoviePlayerController film est joué?
Assumer iOS 3.2 ou une version ultérieure. Quelle est la bonne séquence de commande pour jouer un coup avec les contrôles d'abord caché. Lorsque le film est en cours de lecture, l'utilisateur a la possibilité de tag sur l'écran pour afficher les commandes.
Merci!
Mon (contrôle non masqué) code:
- (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];
}
}
Vous devez vous connecter pour publier un commentaire.
[Mise à jour] tel Que proposé par @ReinYem, une bien meilleure solution est de s'appuyer sur une MPMoviePlayerLoadStateDidChangeNotification au lieu d'une minuterie.
En fait, la solution suivante ne doit pas être considéré comme plus:
Ensemble
controlStyle
propriétéMPMovieControlStyleNone
d'abord, et puis le mettre àMPMovieControlStyleFullscreen
une seconde plus tard, à l'aide d'un[performSelector:withObject:afterDelay:1]
.Il fonctionne bien, les contrôles n'apparaissent pas jusqu'à ce que l'utilisateur appuie sur la vidéo.
MPMovieControlStyleFullscreen
immédiatement après l'appel de jeu, il permet d'obtenir le même résultat. Alors peut-être il n'y a aucune raison pour spécifier un arbitraire de 1 seconde de retard?Utilisation d'un rappel à la place d'un timer :
Avec fonction de rappel :
Est la nouvelle façon de faire. 🙂