0

I am trying to play movies from a view controller. I am using the code below to do that:

VideoPlayerViewController* moviePlayer = [self.storyboard instantiateViewControllerWithIdentifier:@"videoPlayerController"];
moviePlayer.view.frame = rect;
UIWindow *window = [[[UIApplication sharedApplication] windows] lastObject];
[window.rootViewController presentViewController:moviePlayer animated:NO completion:nil];
[moviePlayer playMoviesForItems:items];

Normally it works fine. But sometimes, movie starts but I cannot see the video, just I can hear the sounds.

What is the best way to play video on top of everything?

Burak
  • 5,706
  • 20
  • 70
  • 110

2 Answers2

1
NSString *path = [[NSBundle mainBundle] pathForResource:@"myVideo" ofType:@"mp4"];   

MPMoviePlayerController *myPlayer = [[MPMoviePlayerController alloc] init];
myPlayer.shouldAutoplay = YES;
myPlayer.repeatMode = MPMovieRepeatModeOne;
myPlayer.fullscreen = YES;
myPlayer.movieSourceType = MPMovieSourceTypeFile;
myPlayer.scalingMode = MPMovieScalingModeAspectFit;
myPlayer.contentURL =[NSURL fileURLWithPath:path];
[self.view addSubview:myPlayer.view];
[myPlayer play];

Another solution would be to segue to another ViewController and dissmiss it when the movie ends.

Segev
  • 19,035
  • 12
  • 80
  • 152
0

You can also try using AVPlayer. In that case, you can play the video in your current view itself without having a separate overlay for the video.

Here's an example of playing multiple AVPlayers. You can modify the code to play a single video.

Anil
  • 2,430
  • 3
  • 37
  • 55