youtube嵌入式视频iphone

时间:2011-11-10 15:02:28

标签: iphone youtube

我正在尝试使用此网址中的技术在iPhone应用中播放YouTube视频http://iphoneincubator.com/blog/audio-video/how-to-play-youtube-videos-within-an-application

该技术工作正常,视频播放正常,但我希望视频在完成时切换回主视图。当我点击youtube播放器的“完成”按钮时,它会转回主视图,但当视频播完时,youtube播放器不会消失(你必须点击“完成”)

请帮忙!

2 个答案:

答案 0 :(得分: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];

答案 1 :(得分: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];