Youtube crop iphone video

I am trying to play a YouTube video in an iPhone application using the technique in this URL http://iphoneincubator.com/blog/audio-video/how-to-play-youtube-videos-within-an-application

The technique works fine, and the video plays perfectly, except that I want the video to switch back to the main screen when it is finished. when I press the "done" button on the YouTube player, it returns to the main view, but when the video is completed, the YouTube player does not disappear (you must click "done")

Please, help!

+6
source share
2 answers
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
source

You can use a notification to let you know when it's finished, so you can remove it from the view and allow the previous view on the screen.

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

Remember to delete the notification in moviePlaybackComplete:

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

Source: https://habr.com/ru/post/901222/


All Articles