2

I'm writing an app that needs to be able to play back all of the user's videos, including the Slo-Mo ones. My code works OK for normal videos, but the Slo-Mo videos are being played at normal speed (not slow motion). I've googled and searched SO but haven't been able to find any code examples to get this to work.

I get the asset url by doing the following:

PHVideoRequestOptions *options = [PHVideoRequestOptions new];
options.deliveryMode =  PHVideoRequestOptionsDeliveryModeHighQualityFormat;
options.version = PHVideoRequestOptionsVersionOriginal;
[[PHImageManager defaultManager] requestAVAssetForVideo:asset options:options resultHandler:^(AVAsset *asset, AVAudioMix *audioMix, NSDictionary *info) {
    if ([asset isKindOfClass:[AVURLAsset class]])
        completion(((AVURLAsset *)asset).URL);
}];

I then pass the URL into the MPMoviePlayerController:

_moviePlayer.view.frame = self.view.frame;
_moviePlayer.allowsAirPlay = true;
_moviePlayer.shouldAutoplay = true;
_moviePlayer.movieSourceType = MPMovieSourceType.File;
_moviePlayer.scalingMode = MPMovieScalingMode.AspectFit;
_moviePlayer.controlStyle = MPMovieControlStyle.Default;
_moviePlayer.view.autoresizingMask = [UIViewAutoresizing.FlexibleHeight, UIViewAutoresizing.FlexibleWidth];
_moviePlayer.contentURL = url!;
_moviePlayer.prepareToPlay();
_moviePlayer.play();

Any help would be greatly appreciated.

Thanks

Jacob

Eric Aya
  • 69,473
  • 35
  • 181
  • 253
Jacob Joz
  • 732
  • 1
  • 11
  • 29

1 Answers1

3

Try changing the currentPlaybackRate property which is declared in MPMediaPlayback Protocol. This is because Slo-Mo videos will play fully in high FPS instead of slowed down if you use PHVideoRequestOptionsVersionOriginal.

Please also note that MPMoviePlayerController is deprecated in iOS 9. Instead, you should use AVPlayerViewController.

AVPlayerViewController has an AVPlayer as its player. You can change AVPlayer's rate property to play video in slow motion. If you want to edit the asset itself, please take a look at this question: How to do Slow Motion video in IOS

Community
  • 1
  • 1
Aleksi Sjöberg
  • 1,454
  • 1
  • 12
  • 34
  • Thanks. I hadn't realised that MPMoviePlayerController is deprecated (I'm working on an app that's been around since iOS 5), so I will try and use the AVPlayerViewController instead. I'm hoping it's smart enough to handle Slo-Mo automatically without the need specify playback rate. – Jacob Joz Jan 20 '16 at 00:43
  • @JacobJoz I edited my answer to contain information about AVPlayerViewController as well. – Aleksi Sjöberg Jan 20 '16 at 06:41
  • I have implemented the AVPlayerViewController, and set the rate to 0.0001. However, it still doesn't play it as slowly as the standard Photos app. I've tried different values like 0.000001 and it doesn't make any difference, it's as though there is some floor as to how low the value can go before it's ignored. – Jacob Joz Jan 21 '16 at 05:21
  • @JacobJoz I see... No idea why it won't go below that certain speed even though the video is 240 fps... Well, the best idea I have is to create a mutable composition. Instructions can be found from the question I linked at the end of my answer. – Aleksi Sjöberg Jan 21 '16 at 06:50
  • not sure I want to go to all the trouble of investigating further. It's not really a vital part of my app. At least it now plays in "kind-of-slow-motion", and I think that's good enough for now. Thanks for your help. – Jacob Joz Jan 22 '16 at 00:12