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
  • 68,014
  • 12
  • 152
  • 178
Hari Mohan
  • 204
  • 1
  • 4
  • 13

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
  • 80,161
  • 21
  • 166
  • 138
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
  • 25,445
  • 23
  • 94
  • 171
guru
  • 2,415
  • 1
  • 25
  • 36