0

In my app I record a movie, save it to the PhotosAlbum, and request then creation of a thumbnail using the code

self.player = [[MPMoviePlayerController alloc] initWithContentURL:videoURL_];
NSArray *times = @[@(1.1)];
[self.player requestThumbnailImagesAtTimes:times timeOption:MPMovieTimeOptionNearestKeyFrame];  

This works fine, but during the thumbnail creation, MPMoviePlayerController plays the sound of the movie, although the movie is not visible, which is annoying.
How can I turn the sound off just of this particular MPMoviePlayerController? The MPMoviePlayerController class has apparently no property to control this.

Reinhard Männer
  • 14,022
  • 5
  • 54
  • 116

2 Answers2

0

According to the answer in How to mute/unmute audio when playing video using MPMoviePlayerController? it is not possible to turn off the sound of a MPMoviePlayerController.
However I found in Creating Thumbnail for Video in iOS a much easier way to create thumbnails, which does not play sound and is synchronous so that handling of asynchronous callbacks is not required.
For convenience, I copy it here:

  1. Add the AVFoundation framework to you app.
  2. #import <AVFoundation/AVFoundation.h>
  3. Add the following code:

    UIImage *theImage = nil; AVURLAsset *asset = [[AVURLAsset alloc] initWithURL:contentURL options:nil]; AVAssetImageGenerator *generator = [[AVAssetImageGenerator alloc] initWithAsset:asset]; generator.appliesPreferredTrackTransform = YES; NSError *err = NULL; CMTime time = CMTimeMake(1, 60); CGImageRef imgRef = [generator copyCGImageAtTime:time actualTime:NULL error:&err]; theImage = [[UIImage alloc] initWithCGImage:imgRef]; CGImageRelease(imgRef);

Community
  • 1
  • 1
Reinhard Männer
  • 14,022
  • 5
  • 54
  • 116
0

Just add this line after creating your player:

self.player.shouldAutoplay = NO;
Mani
  • 51
  • 4
  • This was the missing piece! Although the solution that I found by myself works perfectly, your answer solves the problem more directly, thanks! – Reinhard Männer Jul 18 '14 at 11:01