video not playing through MPMoviePlayer

36 Views Asked by At

I am very new to IOS app development , I am trying to play a video from gallery through MPMoviePlayer. I have list of all the video's urls in an array, but when trying to play the video MPMoviePlayer launches but does not play any video. Here is the code that I am using:

 NSURL *fileURL = [NSURL fileURLWithPath:[urlArr objectAtIndex:indexPath.row]];

playMovie = [[MPMoviePlayerController alloc] initWithContentURL:fileURL];

[self.view addSubview:playMovie.view];

 playMovie.fullscreen = YES;

 [playMovie play];
1

There are 1 best solutions below

1
Omer Malik On

Below is the code from apple documentation, I think you are not using [player prepareToPlay], which Prepares the player for playback by preloading its buffers. rest all looks fine.

MPMoviePlayerController *player =
[[MPMoviePlayerController alloc] initWithContentURL: myURL];
[player prepareToPlay];
[player.view setFrame: myView.bounds];  // player's frame must match    parent's
[myView addSubview: player.view];
// ...
[player play]