1

I would like to loop a mp4 file in UIWebView.

e.g. If you go to this link (http://techslides.com/demos/sample-videos/small.mp4) to open UIWebView, you won't be able to play it in loop. But I would like to watch this mp4 video for loop and loop again.

Please give me any tips to overcome!

Cheers,

user1574429
  • 251
  • 1
  • 4
  • 14

1 Answers1

0

You can simply use MPMoviePlayerController with setRepeatMode:MPMovieRepeatModeOne.

This should allow seamless looping of any video, and it's simple to implement.

NSURL *url = [NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"Your Cool Video File" ofType:@"mp4"]];
MPMoviePlayerViewController *playerController = [[MPMoviePlayerViewController alloc]initWithContentURL:url];

[self presentMoviePlayerViewControllerAnimated:playerController];
[playerController.moviePlayer prepareToPlay];

playerController.moviePlayer.movieSourceType = MPMovieSourceTypeFile;
playerController.moviePlayer.controlStyle = MPMovieControlStyleNone;
playerController.moviePlayer.scalingMode = MPMovieScalingModeAspectFill;
playerController.moviePlayer.repeatMode = MPMovieRepeatModeOne;

[playerController.moviePlayer play];

Important to remember to subscribe to the end playback notification like so:

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(moviePlayBackDidFinished:) name:MPMoviePlayerPlaybackDidFinishNotification object:self.moviePlayer];
  • Start playback manually in moviePlayBackDidFinished method
Woodstock
  • 22,184
  • 15
  • 80
  • 118
  • Wow, you are amazing. I will try with your codes.If working properly, will give you back later! Thank you very much for your comments anyway! – user1574429 Feb 15 '15 at 21:20