title: Downloaded video not playing iOS
body: <p>In my iOS application I send a GET request to a Java Servlet which successfully sends me a .mp4 video. I am using the NSURLSession API and I want to play the video in the completion block but the video never plays. I don't see what is wrong with my code:</p>
  
  <pre><code>@interface ViewVideoViewController ()
  
  @property (nonatomic) NSURLSession *session;
  @property (nonatomic, strong) MPMoviePlayerController *player;
  
  @end
  
  @implementation ViewVideoViewController
  
  - (void)viewDidLoad {
  [super viewDidLoad];
  
  NSString *requestedURL=[NSString stringWithFormat:@"http://urlservlet.com?filename=%@", self.filename];
  NSURL *url = [NSURL URLWithString:requestedURL];
  
  NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init];
  [request setCachePolicy:NSURLRequestReloadIgnoringLocalCacheData];
  [request setHTTPShouldHandleCookies:NO];
  [request setTimeoutInterval:30];
  [request setHTTPMethod:@"GET"];
  [request setURL:url];
  
  NSURLSessionConfiguration *config =
  [NSURLSessionConfiguration defaultSessionConfiguration];
  self.session = [NSURLSession sessionWithConfiguration:config
                                               delegate:nil
                                          delegateQueue:nil];
  NSURLSessionDownloadTask *downloadTask = [self.session downloadTaskWithRequest:request completionHandler:^(NSURL *location, NSURLResponse *response, NSError *error) {
      NSData *downloadedData = [NSData dataWithContentsOfURL:location
                                                     options:kNilOptions
                                                       error:nil];
  
  
      NSLog(@"Video size: %lu", (unsigned long)downloadedData.length);//the result is good so the video is here
      self.player = [[MPMoviePlayerController alloc] initWithContentURL:location];
      UIView *view = self.player.view;
      view.frame = CGRectMake(16, 84, 288, 128);
      [self.view addSubview:view];
      [self.player prepareToPlay];
      [self.player play];
  }];
  [downloadTask resume];
  
  }
  @end
  </code></pre>