title: Stream video using AFNetworking and cache video for playback
body: <p>So I am trying to get my app to stream a video located on Amazon S3. So far, I can do that with the MediaPlayer Tutorial from Apple no problem: <a href="https://developer.apple.com/library/ios/#samplecode/MoviePlayer_iPhone/Introduction/Intro.html" rel="noreferrer">https://developer.apple.com/library/ios/#samplecode/MoviePlayer_iPhone/Introduction/Intro.html</a></p>
  
  <p>However, I am using RestKit in my app and therefore AFNetworking as well. I see that AFNetworking is using caching, so I was wondering if it was possible to do the same with videos? I don't know how to stream a video using AFNetworking. So that would be a good start. I can download a movie using AFNetworking... but can I stream with it or I should just use the streaming system given by #import </p>
  
  <pre><code>NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:@"https://s3.amazonaws.com/leclerc/videos/sop/IMG_0141.MOV"]];
  AFHTTPRequestOperation *operation = [[AFHTTPRequestOperation alloc] initWithRequest:request];
  
  NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
  NSString *path = [[paths objectAtIndex:0] stringByAppendingPathComponent:@"IMG_0141.MOV"];
  operation.outputStream = [NSOutputStream outputStreamToFileAtPath:path append:NO];
  
  [operation setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject) {
      NSLog(@"Successfully downloaded file to %@", path);
  } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
      NSLog(@"Error: %@", error);
  }];
  
  [operation start];
  </code></pre>
  
  <p>For example, if I watch a music clip on Vevo and then rewatch 5 minutes later, do I have to redownload it on my iPad?! This is all new to me, so sorry for my ignorance!</p>