0

I have used this coding in viewDidLoad Method:-

NSURL *fileURL = [NSURL URLWithString:@"https://www.youtube.com/watch?v=R4-YdC5N6Lo"];
moviePlayerController = [[MPMoviePlayerController alloc] initWithContentURL:fileURL];
[moviePlayerController.view setFrame:CGRectMake(10, 100, self.view.frame.size.width-20, 260)];
[self.view addSubview:moviePlayerController.view];
moviePlayerController.fullscreen = YES;
[moviePlayerController play];

When I run the app, then a black screen show but not play video. I want to play video from url. Can anybody help me.

Nirav D
  • 71,513
  • 12
  • 161
  • 183
Hari Mohan
  • 214
  • 1
  • 4
  • 16

2 Answers2

3

MPMoviePlayerController not playing youtube video directly, it play only video file path Url in ios, so try HCYoutubeParser.

for additional information see the Stackoverflow answer

Community
  • 1
  • 1
Anbu.Karthik
  • 82,064
  • 23
  • 174
  • 143
1

MPMoviePlayerController is deprecated in iOS10 you can now use AVKit

NSURL *videoURL = [NSURL URLWithString:@"https://clips.vorwaerts-gmbh.de/big_buck_bunny.mp4"];
AVPlayer *player = [AVPlayer playerWithURL:videoURL];
playerViewController = [AVPlayerViewController new];
playerViewController.player = player;
[self.view addSubview:playerViewController.view];
[self presentViewController:playerViewController animated:YES completion:nil];
Praveenkumar
  • 24,084
  • 23
  • 95
  • 173
guru
  • 2,727
  • 3
  • 27
  • 39