2011-11-10 67 views
6

我試圖利用該技術在此URL http://iphoneincubator.com/blog/audio-video/how-to-play-youtube-videos-within-an-application的YouTube視頻embbed iphone

的技術工作正常,視頻播放正常,但我想要的視頻切換回一個iPhone應用程序中播放YouTube視頻到完成時的主視圖。當我點擊YouTube播放器的「完成」按鈕時,它會回到主視圖,但是當視頻播放完畢後,YouTube播放器不會消失(您必須點擊「完成」)

請幫忙!

回答

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;更改爲默認的MPMovieControlStyle, – NANNAV

0

您可以使用通知來通知它何時完成,以便您可以從視圖中刪除它,並讓屏幕上的前一個視圖。

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

不要忘記在moviePlaybackComplete刪除通知:由

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