2012-03-05 13 views
7

sto creando un oggetto MPMoviePlayerController e lo streaming di un video in modalità a schermo intero.MPMoviePlayerController non rimuove vista quando si fa clic fatto

Sto usando un UIViewController per visualizzare la vista film.

- (void)viewDidAppear:(BOOL)animated { 
    [super viewDidAppear:animated]; 
    //http://www.youtube.com/watch?feature=player_detailpage&v=ebeQaznNcmE 
    NSURL *url = [NSURL URLWithString:@"http://a1408.g.akamai.net/5/1408/1388/2005110405/1a1a1ad948be278cff2d96046ad90768d848b41947aa1986/sample_mpeg4.mp4"]; 
    MPMoviePlayerController *mPlayer = [[MPMoviePlayerController alloc]initWithContentURL:url]; 
    mPlayer.view.frame = gMainView.frame; 

    [[NSNotificationCenter defaultCenter] addObserver:self 
              selector:@selector(moviePlayBackDidFinish:) 
              name:MPMoviePlayerPlaybackDidFinishNotification 
              object:mPlayer]; 
    mPlayer.shouldAutoplay = YES; 
    mPlayer.controlStyle = MPMovieControlStyleFullscreen; 
    [gMainView addSubview:mPlayer.view]; 
    [mPlayer prepareToPlay]; 
    [mPlayer setFullscreen:YES animated:YES]; 
    [mPlayer play]; 
} 


- (void)moviePlayBackDidFinish:(NSNotification*)notification { 
    int reason = [[[notification userInfo] valueForKey:MPMoviePlayerPlaybackDidFinishReasonUserInfoKey] intValue]; 
    if (reason == MPMovieFinishReasonPlaybackEnded) { 
     //movie finished playing 
    } 
    else if (reason == MPMovieFinishReasonUserExited) { 
     //user hit the done button 
     MPMoviePlayerController *moviePlayer = [notification object]; 

     [[NSNotificationCenter defaultCenter] removeObserver:self  
                 name:MPMoviePlayerPlaybackDidFinishNotification 
                 object:moviePlayer]; 

     if ([moviePlayer respondsToSelector:@selector(setFullscreen:animated:)]) { 
      [moviePlayer.view removeFromSuperview]; 
     } 
     [moviePlayer release]; 
    } 
    else if (reason == MPMovieFinishReasonPlaybackError) { 
     //error 
    } 
} 

quando si fa clic fatto, il video visivo viene rimosso dallo schermo, ma i controlli non vengono rimossi dallo schermo e la vista non viene rimosso dallo schermo.

Il controllo fa venire a "// utente premere il pulsante fatto". Si fa eseguire il codice per rimuovere la vista da superview, ho controllato da tronchi aggiunta, ma i controlli non vengono rimossi dallo schermo e la vista non viene rimosso dallo schermo. Cosa sto sbagliando?

EDIT:

Se uso MPMoviePlayerViewController allora non ha nemmeno aspettare per me di premere Fine. Una volta completato il video, rimuove automaticamente la vista. Ma non lo voglio.

EDIT:

Se rimuovo "[MPlayer setFullscreen: SI animato: SI]" e poi quando si fa clic su Done, la vista viene completamente rimosso. Ma il video non viene visualizzato a schermo intero e la barra di stato diventa grigio, che è di nuovo ciò che non voglio.

+0

si prendono molti passi per descrivere quello che non vuoi, ma, almeno per me, questo non ancora veramente affermare ciò che realmente vuole raggiungere. – Till

+0

I controlli non vengono rimossi dallo schermo e la vista giocatore non viene rimossa dallo schermo. – Anand

+1

Prova questa soluzione: http://stackoverflow.com/questions/6142571/mpmovieplayer-done-button-issue/6142685#6142685 – Till

risposta

10

Il seguente codice ha funzionato per me, spero che ti aiuta troppo.

-(IBAction)playVedio:(id)sender{ 
mp = [[MPMoviePlayerViewController alloc] initWithContentURL:url]; 

    [[mp moviePlayer] prepareToPlay]; 
    [[mp moviePlayer] setUseApplicationAudioSession:NO]; 
    [[mp moviePlayer] setShouldAutoplay:YES]; 
    [[mp moviePlayer] setControlStyle:2]; 
    [[mp moviePlayer] setRepeatMode:MPMovieRepeatModeOne]; 
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(videoPlayBackDidFinish:) name:MPMoviePlayerPlaybackDidFinishNotification object:nil]; 
    [self presentMoviePlayerViewControllerAnimated:mp]; 

} 

-(void)videoPlayBackDidFinish:(NSNotification*)notification { 

    [[NSNotificationCenter defaultCenter] removeObserver:self name:MPMoviePlayerPlaybackDidFinishNotification object:nil]; 

    [mp.moviePlayer stop]; 
    mp = nil; 
    [mp release]; 
    [self dismissMoviePlayerViewControllerAnimated]; 
} 
+0

Perfavore, Sirji aggiunge anche qualcosa di più con il codice che altri possono facilmente capire la tua risposta che cosa hai fatto e qual è stato il problema con il codice in questione che cosa hai fatto per superarlo, comunque grazie per la soluzione:) – MKJParekh

+0

vl prendersi cura di quello che la prossima volta .. !! :) – Sirji

+4

Non si dovrebbe falsificare voti che palesemente. – Till

0
- (NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window 
{ 
    id presentedViewController = [window.rootViewController presentedViewController]; 
    NSString *className = presentedViewController ? NSStringFromClass([presentedViewController class]) : nil; 

    if (window && [className isEqualToString:@"AVFullScreenViewController"]) { 

     return UIInterfaceOrientationMaskAll; 

    } else { 

     UIInterfaceOrientation interfaceOrientation = [UIApplication sharedApplication].statusBarOrientation; 

     if(UIInterfaceOrientationIsPortrait(interfaceOrientation)) 

     { 

     } 

     else if(UIInterfaceOrientationIsLandscape(interfaceOrientation)) 

     { 


     } 

     return UIInterfaceOrientationMaskPortrait; 

     CGRect frame = [UIScreen mainScreen].applicationFrame; 
     CGSize size = frame.size; 
     NSLog(@"%@", [NSString stringWithFormat:@"Rotation: %s [w=%f, h=%f]", 
         UIInterfaceOrientationIsPortrait(interfaceOrientation) ? "Portrait" : "Landscape", 
         size.width, size.height]); 
    } 
} 
Problemi correlati