В следующем коде я воспроизводю видео через Интернет из файла фильма, расположенного на веб-сервере.Не забудьте добавить каркас MediaPlayer и включить «MediaPlayer / MediaPlayer.h» в файл ViewController.h.
При нажатии кнопки используйте следующий код:
-(IBAction) playVideo:(id)sender
{
NSURL *url=[[NSURL alloc] initWithString:@"http://www.ebookfrenzy.com/ios_book/movie/movie.mov"];
MPMoviePlayerController *moviePlayer=[[MPMoviePlayerController alloc] initWithContentURL:url];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(moviePlayBackDidFinish:) name:MPMoviePlayerPlaybackDidFinishNotification object:moviePlayer];
moviePlayer.controlStyle=MPMovieControlStyleDefault;
moviePlayer.shouldAutoplay=YES;
[self.view addSubview:moviePlayer.view];
[moviePlayer setFullscreen:YES animated:YES];
}
Метод уведомления:
- (void) moviePlayBackDidFinish:(NSNotification*)notification
{
MPMoviePlayerController *player = [notification object];
[[NSNotificationCenter defaultCenter] removeObserver:self
name:MPMoviePlayerPlaybackDidFinishNotification object:player];
if ([player respondsToSelector:@selector(setFullscreen:animated:)])
{
[player.view removeFromSuperview];
}
}