Pergunta

Eu tenho uma configuração do MPMoviePlayer para reproduzir um filme de introdução no meu aplicativo. Isso funciona muito bem, o único problema é que ele dura 14 segundos, e eu quero dar aos meus usuários a chance de pular a introdução pressionando em qualquer lugar do filme.

Eu escondi os controles do filme, pois eles não são necessários.

Código:

NSString *introPath = [[NSBundle mainBundle] pathForResource:@"intro" ofType:@"mov"];
intro = [[MPMoviePlayerController alloc] initWithContentURL:[NSURL fileURLWithPath:introPath]];
[intro setMovieControlMode:MPMovieControlModeHidden];
[intro play]; 

Obrigada!

Foi útil?

Solução

EDIT: Minha solução inicial não funcionará, porque o filme é mostrado em uma segunda janela, em camadas na parte superior da janela principal do aplicativo (é muito raro ter mais de uma janela na hierarquia de visualização no iPhone). Esta solução, com base em Código de amostra do MoviePlayer da Apple, funciona:

. . .
    // assuming you have prepared your movie player, as in the question
    [self.intro play];

    NSArray* windows = [[UIApplication sharedApplication] windows];
    // There should be more than one window, because the movie plays in its own window
    if ([windows count] > 1)
    {
        // The movie's window is the one that is active
        UIWindow* moviePlayerWindow = [[UIApplication sharedApplication] keyWindow];
        // Now we create an invisible control with the same size as the window
        UIControl* overlay = [[[UIControl alloc] initWithFrame:moviePlayerWindow.frame]autorelease];

        // We want to get notified whenever the overlay control is touched
        [overlay addTarget:self action:@selector(movieWindowTouched:) forControlEvents:UIControlEventTouchDown];

        // Add the overlay to the window's subviews
        [moviePlayerWindow addSubview:overlay];
    }
. . .

// This is the method we registered to be called when the movie window is touched
-(void)movieWindowTouched:(UIControl*)sender
{
    [self.intro stop];
}

NB: Você deve salvar a referência ao player de filme em uma variável de instância e é mais conveniente declarar uma propriedade que podemos usar para acessá -la. É por isso que é usado self.intro em vez de apenas intro no exemplo. Se você não sabe como declarar uma variável de instância e uma propriedade, há muitas informações neste site e em outros lugares.

**** Resposta original abaixo

(Não funciona neste caso, mas em muitos cenários semelhantes, então vou deixá -lo como um exemplo de aviso e/ou inspiração.)

. . . Se nada mais funcionar, eu recomendaria a subclassificação do UIWindow e garantir que o seu aplicativo delegue instanciados que, em vez de uma UIWindow normal. Você pode interceptar toques nessa classe e enviar uma notificação ou cancelar o filme diretamente (se você armazenou um ponteiro para o MPMoviePlayer em um adar na sua subclasse de janela).

@interface MyWindow : UIWindow {
}
@end

@implementation MyWindow
// All touch events get passed through this method
-(UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event
{
   // The screen has been touched, send a notification or stop the movie
   return [super hitTest:point withEvent:event];
}
@end
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top