priore

Check valid MPMoviePlayerController video URL

Nov 10th, 2014
674
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. - (void)validVideoURL:(NSString*)url valid:(void(^)())valid invalid:(void(^)())invalid
  2. {
  3.     // AFNetworking https://github.com/AFNetworking
  4.     AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
  5.     manager.responseSerializer = [AFHTTPResponseSerializer serializer];
  6.     manager.responseSerializer.acceptableContentTypes = [NSSet setWithObjects:@"application/vnd.apple.mpegurl", @"video/mp2t",
  7.                                                          @"video/mov", @"video/mpv", @"video/3gp", @"video/mp4", nil];
  8.     NSMutableURLRequest *request = [manager.requestSerializer requestWithMethod:@"HEAD" URLString:url parameters:nil error:nil];
  9.     AFHTTPRequestOperation *operation = [manager HTTPRequestOperationWithRequest:request success:^(AFHTTPRequestOperation *operation, id responseObject) {
  10.        
  11.         RAILog(@"%@", operation.response);
  12.        
  13.         if (valid)
  14.             valid();
  15.        
  16.     } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
  17.         if (operation.response.statusCode == 405) { // method HEAD not support from server
  18.             if (valid)
  19.                 valid();
  20.         } else if (invalid) {
  21.             invalid();
  22.         }
  23.     }];
  24.    
  25.     [operation start];
  26.    
  27. }
RAW Paste Data