2011-11-10 23 views
6

Estoy intentando reproducir un vídeo de YouTube dentro de una aplicación para el iPhone usando la técnica en este URL http://iphoneincubator.com/blog/audio-video/how-to-play-youtube-videos-within-an-applicationyoutube embeber vídeos iphone

La técnica funciona muy bien y el vídeo se reproduce bien, excepto que yo quiero el video para volver a la vista principal cuando está terminado. cuando hago clic en el botón "done" del reproductor de youtube, vuelve a la vista principal pero cuando el video termina, el reproductor de youtube no desaparece (tienes que hacer clic en "done")

¡Ayuda!

Respuesta

0
NSURL *url = [[NSURL alloc]initWithString:@"url for video"]; 
     self.backgroundColor=[UIColor redColor]; 
     moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:url]; 
     [moviePlayer.view setFrame:CGRectMake(0,0,self.frame.size.width-10,self.frame.size.height-10)]; 
     moviePlayer.controlStyle = MPMovieControlStyleNone; 
     moviePlayer.shouldAutoplay=YES; 
     moviePlayer.repeatMode = NO; 
     [moviePlayer setFullscreen:YES animated:YES]; 
     [moviePlayer prepareToPlay]; 
     pause=NO; 
     [self.view addSubview:moviePlayer.view]; 
+0

moviePlayer.controlStyle = MPMovieControlStyleNone; cambiar como MPMovieControlStyle como predeterminado, – NANNAV

0

Puede utilizar la notificación para informar cuándo ha finalizado para que pueda eliminarlo de la vista y permitir la vista previa en la pantalla.

[[NSNotificationCenter defaultCenter] addObserver:self 
             selector:@selector(moviePlaybackComplete:) 
              name:MPMoviePlayerPlaybackDidFinishNotification 
              object:self.player.moviePlayer]; 

No se olvide de quitar la notificación en moviePlaybackComplete: por

MPMoviePlayerController *moviePlayerController = [notification object]; 
[[NSNotificationCenter defaultCenter] removeObserver:self 
               name:MPMoviePlayerPlaybackDidFinishNotification 
               object:moviePlayerController]; 
Cuestiones relacionadas