Objective-C Tips & Trick - Prioregroup.com
[Objective-C] Check valid MPMoviePlayerController video URL
       
back

- (void)validVideoURL:(NSString*)url valid:(void(^)())valid invalid:(void(^)())invalid
{
    // AFNetworking https://github.com/AFNetworking
    AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
    manager.responseSerializer = [AFHTTPResponseSerializer serializer];
    manager.responseSerializer.acceptableContentTypes = [NSSet setWithObjects:@"application/vnd.apple.mpegurl", @"video/mp2t",
                                                         @"video/mov", @"video/mpv", @"video/3gp", @"video/mp4", nil];
    NSMutableURLRequest *request = [manager.requestSerializer requestWithMethod:@"HEAD" URLString:url parameters:nil error:nil];
    AFHTTPRequestOperation *operation = [manager HTTPRequestOperationWithRequest:request success:^(AFHTTPRequestOperation *operation, id responseObject) {
        
        RAILog(@"%@", operation.response);
        
        if (valid)
            valid();
        
    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
        if (operation.response.statusCode == 405) { // method HEAD not support from server
            if (valid)
                valid();
        } else if (invalid) {
            invalid();
        }
    }];
    
    [operation start];
    
}






Copyright © 1996-2018 Centro Studi Informatica di Danilo Priore. All rights reserved. P.I.10149810581.
prioregroup.com